DB upgrade 때문에
[oracle@ora19c ~]$ sys
SQL*Plus: Release 19.0.0.0.0 - Production on 수 9월 10 10:03:44 2025
Version 19.3.0.0.0
Copyright (c) 1982, 2019, Oracle. All rights reserved.
다음에 접속됨:
Oracle Database 19c Enterprise Edition Release 19.0.0.0.0 - Production
Version 19.3.0.0.0
SYS @ ORA19 > @i
STATUS
------------
OPEN
SYS @ ORA19 > exit
Oracle Database 19c Enterprise Edition Release 19.0.0.0.0 - Production
Version 19.3.0.0.0에서 분리되었습니다.
[oracle@ora19c ~]$ sysdw
SQL*Plus: Release 19.0.0.0.0 - Production on 수 9월 10 10:04:16 2025
Version 19.3.0.0.0
Copyright (c) 1982, 2019, Oracle. All rights reserved.
다음에 접속됨:
Oracle Database 19c Enterprise Edition Release 19.0.0.0.0 - Production
Version 19.3.0.0.0
SYS @ ora19dw > @i
STATUS
------------
OPEN
SYS @ ora19dw >
[oracle@ora19c ~]$ lsnrctl status
LSNRCTL for Linux: Version 19.0.0.0.0 - Production on 10-9월 -2025 10:05:11
Copyright (c) 1991, 2019, Oracle. All rights reserved.
(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=192.168.13.81)(PORT=21533)))에 연결되었습니다
리스너의 상태
------------------------
별칭 LISTENER
버전 TNSLSNR for Linux: Version 19.0.0.0.0 - Production
시작 날짜 10-9월 -2025 08:18:01
업타임 0 일 1 시간. 47 분. 10 초
트레이스 수준 off
보안 ON: Local OS Authentication
SNMP OFF리스너 매개변수 파일 /u01/app/oracle/product/19.3.0/dbhome_1/network/admin/listener.ora
리스너 로그 파일 /u01/app/oracle/diag/tnslsnr/ora19c/listener/alert/log.xml
끝점 요약 청취 중...
(DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=192.168.13.81)(PORT=21533)))
(DESCRIPTION=(ADDRESS=(PROTOCOL=ipc)(KEY=EXTPROC21533)))
(DESCRIPTION=(ADDRESS=(PROTOCOL=tcps)(HOST=ora19c)(PORT=5501))(Security=(my_wallet_directory=/u01/app/oracle/admin/ora19dw/xdb_wallet))(Presentation=HTTP)(Session=RAW))
서비스 요약...
"ORA19" 서비스는 1개의 인스턴스를 가집니다.
"ORA19" 인스턴스(READY 상태)는 이 서비스에 대해 1 처리기를 가집니다.
"ORA19XDB" 서비스는 1개의 인스턴스를 가집니다.
"ORA19" 인스턴스(READY 상태)는 이 서비스에 대해 1 처리기를 가집니다.
"ora19dw" 서비스는 1개의 인스턴스를 가집니다.
"ora19dw" 인스턴스(READY 상태)는 이 서비스에 대해 2 처리기를 가집니다.
명령이 성공적으로 수행되었습니다
[oracle@ora19c ~]$
-- 1. 먼저 dw 쪽에 scott 유져를 drop 합니다.
SYS @ ora19dw > drop user scott cascade;
사용자가 삭제되었습니다.
-- 2. scott 유져를 다시 생성합니다.
SYS @ ora19dw > create user scott
identified by tiger;
사용자가 생성되었습니다.
SYS @ ora19dw > grant dba to scott;
권한이 부여되었습니다.
-- 3. 오랜지로 dw 쪽에 scott 으로 접속해서 소유한 테이블 목록을 봅니다.
select table_name
from user_tables;
-- 4. db 링크를 scott 유져에서 생성합니다.
create public database link asis_link
connect to scott
identified by tiger
using '192.168.13.69:21533/ORA19';
select table_name
from user_tables@asis_link;
select *
from emp@asis_link;
select *
from dept@asis_link;
create table emp_dw
as
select *
from emp@asis_link;
create table dept_dw
as
select *
from dept@asis_link;
select table_name from user_tables;
drop table emp_dw;
drop table dept_dw;
💡 위와 같이 만들게 되면 인덱스와 제약을 따로 구성해줘야함
select instance_name from v$instance;
@demo
select * from emp;
select * from dept;
create index emp_sal on emp(sal);
create index emp_job on emp(job);
create index dept_loc on dept(loc);
alter table emp
add constraint emp_empno_pk primary key(empno);
alter table dept
add constraint dept_deptno_pk primary key(deptno);
- ora19쪽에서 테이블 생성 스크립트와 인덱스 생성 스크립트, 제약 스크립트를 추출
- ora19dw 쪽에 테이블 생성
- ora19에서 ora19dw 데이터 이행
- (★중요★) ora19dw 쪽에 인덱스 생성
- ora19dw 쪽에 제약 생성
EMP 테이블
CREATE TABLE SCOTT.EMP
(
EMPNO NUMBER(4) NOT NULL,
ENAME VARCHAR2(10),
JOB VARCHAR2(9),
MGR NUMBER(4),
HIREDATE DATE,
SAL NUMBER(7,2),
COMM NUMBER(7,2),
DEPTNO NUMBER(2)
)
TABLESPACE USERS
STORAGE
(
INITIAL 64K
NEXT 1M
)
NOCOMPRESS;
CREATE UNIQUE INDEX SCOTT.EMP_EMPNO_PK
ON SCOTT.EMP (EMPNO)
TABLESPACE USERS
STORAGE
(
INITIAL 64K
NEXT 1M
);
CREATE INDEX SCOTT.EMP_JOB
ON SCOTT.EMP (JOB)
TABLESPACE USERS
STORAGE
(
INITIAL 64K
NEXT 1M
);
CREATE INDEX SCOTT.EMP_SAL
ON SCOTT.EMP (SAL)
TABLESPACE USERS
STORAGE
(
INITIAL 64K
NEXT 1M
);
ALTER TABLE SCOTT.EMP
ADD CONSTRAINT EMP_EMPNO_PK PRIMARY KEY (EMPNO);
DEPT 테이블
CREATE TABLE SCOTT.DEPT
(
DEPTNO NUMBER(10),
DNAME VARCHAR2(14),
LOC VARCHAR2(13)
)
TABLESPACE USERS
STORAGE
(
INITIAL 64K
NEXT 1M
)
NOCOMPRESS;
CREATE UNIQUE INDEX SCOTT.DEPT_DEPTNO_PK
ON SCOTT.DEPT (DEPTNO)
TABLESPACE USERS
STORAGE
(
INITIAL 64K
NEXT 1M
);
CREATE INDEX SCOTT.DEPT_LOC
ON SCOTT.DEPT (LOC)
TABLESPACE USERS
STORAGE
(
INITIAL 64K
NEXT 1M
);
ALTER TABLE SCOTT.DEPT
ADD CONSTRAINT DEPT_DEPTNO_PK PRIMARY KEY (DEPTNO);
Tools - Script Generation Tool 클릭
CREATE TABLE SCOTT.DEPT
(
DEPTNO NUMBER(10) NOT NULL,
DNAME VARCHAR2(14),
LOC VARCHAR2(13)
)
TABLESPACE USERS
STORAGE
(
INITIAL 64K
NEXT 1M
)
NOCOMPRESS;
CREATE TABLE SCOTT.EMP
(
EMPNO NUMBER(4) NOT NULL,
ENAME VARCHAR2(10),
JOB VARCHAR2(9),
MGR NUMBER(4),
HIREDATE DATE,
SAL NUMBER(7,2),
COMM NUMBER(7,2),
DEPTNO NUMBER(2)
)
TABLESPACE USERS
STORAGE
(
INITIAL 64K
NEXT 1M
)
NOCOMPRESS;
CREATE UNIQUE INDEX SCOTT.DEPT_DEPTNO_PK
ON SCOTT.DEPT (DEPTNO)
TABLESPACE USERS
STORAGE
(
INITIAL 64K
NEXT 1M
);
CREATE INDEX SCOTT.DEPT_LOC
ON SCOTT.DEPT (LOC)
TABLESPACE USERS
STORAGE
(
INITIAL 64K
NEXT 1M
);
CREATE UNIQUE INDEX SCOTT.EMP_EMPNO_PK
ON SCOTT.EMP (EMPNO)
TABLESPACE USERS
STORAGE
(
INITIAL 64K
NEXT 1M
);
CREATE INDEX SCOTT.EMP_ENAME
ON SCOTT.EMP (JOB)
TABLESPACE USERS
STORAGE
(
INITIAL 64K
NEXT 1M
);
CREATE INDEX SCOTT.EMP_SAL
ON SCOTT.EMP (SAL)
TABLESPACE USERS
STORAGE
(
INITIAL 64K
NEXT 1M
);
ALTER TABLE SCOTT.EMP
MODIFY EMPNO NOT NULL;
ALTER TABLE SCOTT.DEPT
ADD CONSTRAINT DEPT_DEPTNO_PK PRIMARY KEY (DEPTNO);
ALTER TABLE SCOTT.EMP
ADD CONSTRAINT EMP_EMPNO_PK PRIMARY KEY (EMPNO);
CREATE TABLE SCOTT.DEPT
(
DEPTNO NUMBER(10) NOT NULL,
DNAME VARCHAR2(14),
LOC VARCHAR2(13)
)
TABLESPACE USERS
STORAGE
(
INITIAL 64K
NEXT 1M
)
NOCOMPRESS;
CREATE TABLE SCOTT.EMP
(
EMPNO NUMBER(4) NOT NULL,
ENAME VARCHAR2(10),
JOB VARCHAR2(9),
MGR NUMBER(4),
HIREDATE DATE,
SAL NUMBER(7,2),
COMM NUMBER(7,2),
DEPTNO NUMBER(2)
)
TABLESPACE USERS
STORAGE
(
INITIAL 64K
NEXT 1M
)
NOCOMPRESS;
select table_name from user_tables;
truncate table emp;
truncate table dept;
select name, value from v$parameter where name like '%cpu%';
alter session enable parallel dml;
insert /*+ parallel(new_emp,4) */ into emp new_emp
select /*+ parallel(old_emp,4) */ *
from emp@asis_link old_emp;
commit;
insert /*+ parallel(new_dept,4) */ into dept new_dept
select /*+ parallel(old_dept,4) */ *
from dept@asis_link old_dept;
commit;
인덱스 생성 시 nologging 옵션과 parallel 옵션을 써서 생성해야 빠르게 생성할 수 있음
CREATE UNIQUE INDEX SCOTT.DEPT_DEPTNO_PK
ON SCOTT.DEPT (DEPTNO)
TABLESPACE USERS
STORAGE
(
INITIAL 64K
NEXT 1M
) nologging
parallel 4;
CREATE INDEX SCOTT.DEPT_LOC
ON SCOTT.DEPT (LOC)
TABLESPACE USERS
STORAGE
(
INITIAL 64K
NEXT 1M
) nologging
parallel 4;
CREATE UNIQUE INDEX SCOTT.EMP_EMPNO_PK
ON SCOTT.EMP (EMPNO)
TABLESPACE USERS
STORAGE
(
INITIAL 64K
NEXT 1M
) nologging
parallel 4;
CREATE INDEX SCOTT.EMP_ENAME
ON SCOTT.EMP (JOB)
TABLESPACE USERS
STORAGE
(
INITIAL 64K
NEXT 1M
) nologging
parallel 4;
CREATE INDEX SCOTT.EMP_SAL
ON SCOTT.EMP (SAL)
TABLESPACE USERS
STORAGE
(
INITIAL 64K
NEXT 1M
) nologging
parallel 4;
echo on
set timing on
set time on
spool on
spool create_index_20250910.txt
CREATE UNIQUE INDEX SCOTT.DEPT_DEPTNO_PK
ON SCOTT.DEPT (DEPTNO)
TABLESPACE USERS
STORAGE
(
INITIAL 64K
NEXT 1M
) nologging
parallel 4;
CREATE INDEX SCOTT.DEPT_LOC
ON SCOTT.DEPT (LOC)
TABLESPACE USERS
STORAGE
(
INITIAL 64K
NEXT 1M
) nologging
parallel 4;
CREATE UNIQUE INDEX SCOTT.EMP_EMPNO_PK
ON SCOTT.EMP (EMPNO)
TABLESPACE USERS
STORAGE
(
INITIAL 64K
NEXT 1M
) nologging
parallel 4;
CREATE INDEX SCOTT.EMP_ENAME
ON SCOTT.EMP (JOB)
TABLESPACE USERS
STORAGE
(
INITIAL 64K
NEXT 1M
) nologging
parallel 4;
CREATE INDEX SCOTT.EMP_SAL
ON SCOTT.EMP (SAL)
TABLESPACE USERS
STORAGE
(
INITIAL 64K
NEXT 1M
) nologging
parallel 4;
set time off
set timing off
spool off
인덱스 생성이 다 되었으면 nologging을 logging으로 변경하고 parallel을 다시 1 로 변경
select 'alter index ' || index_name || ' logging parallel 1;'
from user_indexes
where degree >1;
alter index DEPT_DEPTNO_PK logging parallel 1;
alter index DEPT_LOC logging parallel 1;
alter index EMP_EMPNO_PK logging parallel 1;
alter index EMP_ENAME logging parallel 1;
alter index EMP_SAL logging parallel 1;
마지막으로 제약을 생성합니다.
ALTER TABLE SCOTT.EMP
MODIFY EMPNO NOT NULL;
ALTER TABLE SCOTT.DEPT
ADD CONSTRAINT DEPT_DEPTNO_PK PRIMARY KEY (DEPTNO);
ALTER TABLE SCOTT.EMP
ADD CONSTRAINT EMP_EMPNO_PK PRIMARY KEY (EMPNO);
-- 1.테이블 건수가 서로 일치하는지 확인
select a.table_name, a.num_rows as as_is, b.num_rows as to_be
from user_tables b, user_tables@asis_link a
where b.table_name=a.table_name;
-- 2. 인덱스의 건수가 서로 일치하는지 확인
select 'as-is 인덱스 갯수', count(*)
from user_indexes@asis_link
union all
select 'to-be 인덱스 갯수', count(*)
from user_indexes;
--3. 제약의 갯수가 서로 일치하는지 확인
select 'as-is 제약 갯수', count(*)
from user_constraints@asis_link
union all
select 'to-be 제약 갯수', count(*)
from user_constraints;
drop table job_bonus;
create table job_bonus
( job varchar2(9),
bonus number(7,2) );
insert into job_bonus values('ANALYST', 5500 );
insert into job_bonus `values('CLERK', 2300 );
insert into job_bonus values('MANAGER', 4500 );
insert into job_bonus values('PRESIDENT', 2400 );
insert into job_bonus values('SALESMAN', 3400 );
commit;
create index job_bonus_idx on job_bonus(bonus);
alter table job_bonus
add constraint job_bonus_pk primary key(job);