๋ณธ๋ฌธ ๋ฐ”๋กœ๊ฐ€๊ธฐ
ORACLE/ADMIN

[Oracle] Transportable Tablespace ๊ฐ€์žฅ ๋น ๋ฅธ ๋ฐ์ดํ„ฐ ์ด๋™ ๋ฐฉ๋ฒ•

by ๐ŸŒปโ™š 2020. 7. 18.

Transportable Tablespace

Transportable Tablespace๋Š” ์˜ค๋ผํด์—์„œ ์˜ค๋ผํด ๋ฐ์ดํ„ฐ๋ฒ ์ด์Šค๋กœ ๋ฐ์ดํ„ฐ๋ฅผ ์ด๋™ํ• ๋•Œ ๊ฐ€์žฅ ๋น ๋ฅธ๋ฐฉ๋ฒ•์ด๋ผ๊ณ  ํ•ฉ๋‹ˆ๋‹ค. ๋ฐ์ดํ„ฐํŽŒํ”„๋‚˜ Export, Import ์œ ํ‹ธ๋ฆฌํ‹ฐ๋ฅผ ์‚ฌ์šฉํ• ๋•Œ๋Š” ๊ทธ๋ƒฅ insert์ž‘์—…์„ ํ•˜๋Š” ๊ฒƒ๊ณผ ๋น„์Šทํ•˜๋‹ค๊ณ  ํ•œ๋‹ค๋ฉด Transport Tablespace๋Š” Datapump๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ ๋ฉ”ํƒ€๋ฐ์ดํ„ฐ ์ฆ‰ ๊ตฌ์กฐ๋งŒ ์ถ”์ถœํ•˜๊ณ  ๋ฐ์ดํ„ฐํŒŒ์ผ ์ž์ฒด๋ฅผ ์ด๋™์‹œ์ผœ migration ์ž‘์—…์„ ํ•ฉ๋‹ˆ๋‹ค. 

 

Transport Tablespace๋ฅผ ์ด์šฉํ•˜์—ฌ ๋ฐ์ดํ„ฐ๋ฅผ ์ด๋™ํ• ๋•Œ๋Š” ์šด์˜์ฒด์ œ์— ๋Œ€ํ•œ ์ œํ•œ์ด ์žˆ์Šต๋‹ˆ๋‹ค. ๋ฐ์ดํ„ฐํŒŒ์ผ ์ž์ฒด๋ฅผ ์ด๋™์‹œํ‚ค๋‹ค๋ณด๋‹ˆ ํŒŒ์ผ์„ ์ €์žฅํ•˜๋Š” ๋ฐฉ์‹์ด OS์— ๋”ฐ๋ผ ์ƒ์ดํ•˜์—ฌ Platform์˜ Endian ์ •๋ณด๋งŒ ๊ฐ™๋‹ค๋ฉด ์ด๋™์ด ๊ฐ€๋Šฅํ–ˆ์Šต๋‹ˆ๋‹ค. ํ•˜์ง€๋งŒ ์ด์ œ๋Š” Endian์˜ ์ •๋ณด๊ฐ€ ๋‹ค๋ฅด๋”๋ผ๋„ RMAN์„ ํ†ตํ•ด์„œ Convertingํ•˜์—ฌ ๋ฐ์ดํ„ฐํŒŒ์ผ์˜ ํ˜•์‹์„ ๋ณ€๊ฒฝํ•  ์ˆ˜ ์žˆ์–ด ๋ชจ๋“  OS์—์„œ ํ˜ธํ™˜์ด ๊ฐ€๋Šฅํ•ฉ๋‹ˆ๋‹ค.

 

SYS@newdb> select platform_name, endian_format from v$transportable_platform;

Endian์— ๋Œ€ํ•œ ์ •๋ณด๋Š” v$transportable_platform ๋ทฐ๋ฅผ ํ†ตํ•ด์„œ ํ™•์ธํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

 

 

SYS@newdb> select platform_name from v$database;

ํ˜„์žฌ Database์˜ Platform์„ ํ™•์ธํ•˜๊ณ  Endian ์ •๋ณด๋ฅผ ํ™•์ธํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

 

 

Trasportable Tablespace ์‹ค์Šต

์‹ค์Šตํ™˜๊ฒฝ

OS : Red Hat Enterprise Linux Server release 6.10
DB : Oracle 11.2.0.1
SID : orcl, newdb (1๊ฐœ ์„œ๋ฒ„ 2๊ฐœ ๋ฐ์ดํ„ฐ๋ฒ ์ด์Šค)
host : 601d2fce71dc

 

 

์‹ค์Šต๋ชฉํ‘œ

- Transportable Tablespace๋ฅผ ์ด์šฉํ•ด์„œ orcl์—์„œ ์ƒ์„ฑํ•œ tts tablespace ๋ฐ์ดํ„ฐ๋ฅผ newdb๋กœ ์ด๋™
- orcl์˜ hr ์Šคํ‚ค๋งˆ์™€ newdb์—์„œ allen ์Šคํ‚ค๋งˆ๋ฅผ ์ƒ์„ฑํ•ด์„œ ์ด๋™

 

 

 

Export ์‚ฌ์ „ ์ž‘์—…

[oracle@601d2fce71dc ~]$ mkdir /opt/oracle/tbs

ํŽธ์˜๋ฅผ ์œ„ํ•ด ์ƒ์„ฑํ•  ํ…Œ์ด๋ธ”์ŠคํŽ˜์ด์Šค์˜ ๊ฒฝ๋กœ๋ฅผ ๋ฏธ๋ฆฌ ๋งŒ๋“ค์–ด๋‘ก๋‹ˆ๋‹ค.

 

[oracle@601d2fce71dc ~]$ sqlplus / as sysdba
SYS@orcl> create tablespace tts01 datafile '/opt/oracle/tbs/tts01.dbf' size 50m;

Tablespace created.

SYS@orcl> create tablespace tts02 datafile '/opt/oracle/tbs/tts02.dbf' size 50m;

Tablespace created.

๋‘๊ฐœ์˜ ํ…Œ์ด๋ธ”์ŠคํŽ˜์ด์Šค๋ฅผ ์‚ฌ์šฉํ•ด์„œ ์‹ค์Šต์„ ์ง„ํ–‰ํ•˜๊ฒ ์Šต๋‹ˆ๋‹ค.

 

 

SYS@orcl> create table hr.emp_test tablespace tts01 as select * from hr.employees;

Table created.

SYS@orcl> create table hr.dept_test tablespace tts02 as select * from hr.departments;

Table created.

์ƒ์„ฑํ•œ ํ…Œ์ด๋ธ”์ŠคํŽ˜์ด์Šค์— ๊ฐ๊ฐ ๋ฐ์ดํ„ฐ๊ฐ€ ๋“ค์–ด์žˆ๋Š” ํ…Œ์ด๋ธ”์„ ํ•˜๋‚˜์”ฉ ์ƒ์„ฑํ•ด์คฌ์Šต๋‹ˆ๋‹ค.

 

 

SYS@orcl> alter table hr.dept_test add constraint dept_test_pk primary key(department_id);

Table altered.

SYS@orcl> alter table hr.emp_test add constraint emp_test_dept_fk foreign key(department_id) references hr.dept_test(department_id);

Table altered.

์ƒ์„ฑํ•œ ํ…Œ์ด๋ธ”์— primary key์™€ foreign key๋ฅผ ์ƒ์„ฑํ•ด์ค๋‹ˆ๋‹ค.

 

 

 

 dbms_tts.transport_set_check ํ”„๋กœ์‹œ์ € ํ™•์ธ

SYS@orcl> desc dbms_tts

dbms_tts ํŒจํ‚ค์ง€์˜ transport_set_check ํ”„๋กœ์‹œ์ €๋ฅผ ์ด์šฉํ•ด์„œ tts01๊ณผ tts02 ํ…Œ์ด๋ธ”์ŠคํŽ˜์ด์Šค๊ฐ€ Transportable tablespace๋ฅผ ์ด์šฉํ•ด์„œ export๊ฐ€ ๊ฐ€๋Šฅํ•œ์ง€ ํ™•์ธํ•˜๋Š” ์ž‘์—…์„ ์ง„ํ–‰ํ• ๊ฒ๋‹ˆ๋‹ค.

 

 

 

SYS@orcl> 
begin
dbms_tts.transport_set_check
(ts_list=>'tts01,tts02',
incl_constraints=>true);
end;
/

PL/SQL procedure successfully completed.
SYS@orcl> select * from transport_set_violations;

dbms_tts.transport_set_check ํ”„๋กœ์‹œ์ €๋ฅผ ์ด์šฉํ•ด์„œ ์ด๋™ํ•˜๋ ค๋Š” ํ…Œ์ด๋ธ”์ŠคํŽ˜์ด์Šค๋ฅผ transportableํ•˜๊ฒŒ ๊ฐ€๋Šฅํ•œ์ง€ ํ™•์ธ์ž‘์—…์„ ํ–ˆ์Šต๋‹ˆ๋‹ค. ๊ฒฐ๊ณผ๋Š” transport_set_violations ๋ทฐ๋ฅผ ์ด์šฉํ•ด์„œ ํ™•์ธํ•  ์ˆ˜์žˆ์Šต๋‹ˆ๋‹ค.

 

ํ•ด๋‹น ์‹ค์Šต์—์„œ ํ™•์ธ ๊ฒฐ๊ณผ index์— ๋Œ€ํ•œ violation์ด ๋ฐœ์ƒํ•ฉ๋‹ˆ๋‹ค. hr.dept_test ํ…Œ์ด๋ธ”์—์„œ primary key๋ฅผ ๋งŒ๋“ค๋ฉด์„œ ์ธ๋ฑ์Šค๊ฐ€ ์ƒ์„ฑ๋˜์—ˆ์Šต๋‹ˆ๋‹ค. ํ•˜์ง€๋งŒ ํ•ด๋‹น ์ธ๋ฑ์Šค๋Š” default tablespace์ธ examples ํ…Œ์ด๋ธ”์— ์ƒ์„ฑ๋˜์–ด ๋งŒ์•ฝ ์ด์ƒํƒœ๋กœ ํ…Œ์ด๋ธ”์ŠคํŽ˜์ด์Šค๋ฅผ ์ด๋™ํ•˜๊ฒŒ๋˜๋ฉด ์ธ๋ฑ์Šค์˜ ๋ˆ„๋ฝ์œผ๋กœ ๋ฌธ์ œ๊ฐ€ ๋ฐœ์ƒํ•ฉ๋‹ˆ๋‹ค. ์ด๋™ ๊ฐ€๋Šฅํ•˜๋„๋ก index์˜  rebuild ์ž‘์—…์„ ์ง„ํ–‰ํ•ด์•ผํ•ฉ๋‹ˆ๋‹ค.

 

SYS@orcl> alter index hr.dept_test_pk rebuild tablespace tts02;

Index altered.

์ธ๋ฑ์Šค์˜ rebuild๋ฅผ ์ง„ํ–‰ํ–ˆ์Šต๋‹ˆ๋‹ค. ๋‹ค์‹œ ํ”„๋กœ์‹œ์ €๋กœ ๋ฐ์ดํ„ฐ ์ด๋™์ด ๊ฐ€๋Šฅํ•œ์ง€ ํ™•์ธํ•˜๊ฒ ์Šต๋‹ˆ๋‹ค.

 

 

SYS@orcl> 
begin
dbms_tts.transport_set_check
(ts_list=>'tts01,tts02',
incl_constraints=>true);
end;
/

PL/SQL procedure successfully completed.
SYS@orcl> select * from transport_set_violations;

no rows selected

transport_set_violations ๋ทฐ๋ฅผ ํ™•์ธํ–ˆ์„๋•Œ ๋ณด์—ฌ์ง€๋Š” ๋ฐ์ดํ„ฐ๊ฐ€ ์—†๋‹ค๋ฉด ๋ฌธ์ œ๊ฐ€ ์—†๋‹ค๋Š” ๋œป์ž…๋‹ˆ๋‹ค. Transportable tablespace๋ฅผ ์‚ฌ์šฉํ•˜๋ฉด ๊ผญ ์‚ฌ์ „์— dbms_tts ํŒจํ‚ค์ง€๋ฅผ ์ด์šฉํ•ด์„œ ๋ฌธ์ œ๊ฐ€ ์žˆ๋Š”์ง€ ํ™•์ธ์ž‘์—… ๋ฐ ํ•ด๊ฒฐ ํ›„ ์ง„ํ–‰ํ•ด์ค˜์•ผํ•ฉ๋‹ˆ๋‹ค.

 

 

Datapump Transportable Tablespace Export

SYS@orcl> alter tablespace tts01 read only;

Tablespace altered.

SYS@orcl> alter tablespace tts02 read only;

Tablespace altered.
SYS@orcl> select tablespace_name, status from dba_tablespaces;

Transportable Tablespace๋ฅผ export ์ž‘์—…์„ ํ• ๋•Œ ๊ผญ Read only ์ƒํƒœ๋กœ ๋ณ€๊ฒฝ ํ›„ ์ž‘์—…์„ ์ง„ํ–‰ํ•ฉ๋‹ˆ๋‹ค. Transportable Tablespace๋Š” ๋ฐ์ดํ„ฐํŒŒ์ผ ์ž์ฒด๋ฅผ ์ด๋™์‹œ์ผœ์„œ ์ž‘์—…ํ•˜๊ธฐ ๋•Œ๋ฌธ์— export ํ•˜๋Š” ๊ณผ์ •์—์„œ dml ์ž‘์—…์œผ๋กœ ํ…Œ์ด๋ธ”์˜ ๊ตฌ์กฐ๊ฐ€ ๋ณ€๊ฒฝ๋˜์—ˆ์„๋•Œ import์‹œ ๋ฐ์ดํ„ฐํŒŒ์ผ์—์„œ์˜ ์ •๋ณด๊ฐ€ exportํ•œ ๊ตฌ์กฐ์™€ ์ƒ์ดํ•˜์—ฌ ๋ฌธ์ œ๊ฐ€ ๋ฐœ์ƒํ•ฉ๋‹ˆ๋‹ค.

 

 

[oracle@601d2fce71dc ~]$ mkdir /opt/oracle/dbpump
SYS@orcl> create directory pump_dir as '/opt/oracle/dbpump';

Directory created.

Datapump์—์„œ ์ง€์ •ํ•  Directory ์˜ค๋ธŒ์ ํŠธ๋ฅผ ๋งŒ๋“ค์–ด์ค๋‹ˆ๋‹ค. export๋˜๋Š” ํ…Œ์ด๋ธ”์˜ ๊ตฌ์กฐ๋ฅผ ํ•ด๋‹น ๋””๋ ‰ํ† ๋ฆฌ๋กœ ๋‚ด๋ฆด๊ฒƒ์ž…๋‹ˆ๋‹ค.

 

 

[oracle@601d2fce71dc ~]$ expdp system/oracle dumpfile=tts.dmp directory=pump_dir transport_tablespaces=tts01,tts02

datapump๋ฅผ ์‚ฌ์šฉํ•˜๋Š” ๋ฐฉ๋ฒ•๊ณผ ๊ฐ™์ด ์‚ฌ์šฉํ•˜๋Š”๋ฐ transport_tablespace ์˜ต์…˜์„ ๊ฐ™์ด ์‚ฌ์šฉํ•˜์—ฌ export ์ž‘์—…์„ ์ง„ํ–‰ํ•ฉ๋‹ˆ๋‹ค.

 

 

[oracle@601d2fce71dc ~]$ mkdir /opt/oracle/newdb_tbs
[oracle@601d2fce71dc ~]$ cp /opt/oracle/tbs/tts0* /opt/oracle/newdb_tbs/

newdb sid์—์„œ ๋ฐ”๋ผ๋ณผ ๋ฐ์ดํ„ฐํŒŒ์ผ์˜ ๊ฒฝ๋กœ ์œ„์น˜๋ฅผ ๋งŒ๋“ค์–ด์ค๋‹ˆ๋‹ค. ์ดํ›„ orcl์—์„œ ๋งŒ๋“ค์–ด ๋†“์€ tablespace์˜ ๋ฐ์ดํ„ฐํŒŒ์ผ๋“ค์„ ๋ชจ๋‘ ์ด๋™์‹œ์ผœ์ค๋‹ˆ๋‹ค.

 

 

Datapump Transportable Tablespace import

[oracle@601d2fce71dc ~]$ . oraenv
ORACLE_SID = [orcl] ? newdb
The Oracle base for ORACLE_HOME=/opt/oracle/app/product/11.2.0/dbhome_1 is /opt/oracle/app

newdb ๋ฐ์ดํ„ฐ๋ฒ ์ด์Šค์— ๋งž์ถฐ ํ™˜๊ฒฝ๋ณ€์ˆ˜๋ฅผ ๋ณ€๊ฒฝํ•˜๋Š” ์ž‘์—…์„ ์ง„ํ–‰ํ•ฉ๋‹ˆ๋‹ค.

 

 

SYS@newdb> create directory pump_dir as '/opt/oracle/dbpump';

Directory created.

import ์ž‘์—…์„ ์œ„ํ•ด orcl์—์„œ exportํ•œ ํŒŒ์ผ์˜ ๋””๋ ‰ํ† ๋ฆฌ์™€ ๋™์ผํ•œ ๋””๋ ‰ํ† ๋ฆฌ ์˜ค๋ธŒ์ ํŠธ๋ฅผ ์ƒ์„ฑํ•ด์ค๋‹ˆ๋‹ค.

 

 

SYS@newdb> create user allen identified by allen account unlock;

User created.

SYS@newdb> grant connect, resource to allen;

Grant succeeded.

๋ฐ์ดํ„ฐ๋ฅผ importํ•  ์Šคํ‚ค๋งˆ๋ฅผ ์ƒ์„ฑํ•ฉ๋‹ˆ๋‹ค.

 

 

[oracle@601d2fce71dc ~]$ impdp system/oracle dumpfile=tts.dmp directory=pump_dir remap_schema=hr:allen transport_datafiles=/opt/oracle/newdb_tbs/tts01.dbf,/opt/oracle/newdb_tbs/tts02.dbf

์ด์ƒ์—†์ด ๋ฐ์ดํ„ฐ๋ฅผ import ํ–ˆ์Šต๋‹ˆ๋‹ค.

 

 

ํ™•์ธ

SYS@newdb> select tablespace_name, file_name from dba_data_files;

์ด๋™ํ•˜๋ ค๋Š” ํ…Œ์ด๋ธ”์ŠคํŽ˜์ด์Šค ๋ชจ๋‘ import ๋˜์—ˆ์Šต๋‹ˆ๋‹ค.

 

 

SYS@newdb> conn allen/allen
Connected.
ALLEN@newdb> select table_name from tabs;

์ƒ์„ฑํ•œ ํ…Œ์ด๋ธ”๋“ค๋„ ๋ชจ๋‘ import๋œ๊ฒƒ์„ ํ™•์ธํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

 

๋Œ“๊ธ€