Oracle TTS(Transportable tablespace) allows us to copy datafiles between databases. TTS was introducted in Oracle 8i.
datafile '/u01/app/oracle/oradata/orcl/tts_test01.dbf'
size 2m
autoextend on
next 2m
maxsize unlimited;
identified by oracle
default tablespace tts_test;

Create table tbl_test(
sn number,
name varchar2(200)
);
begin
for i in 1..50000000
loop
insert into tbl_test values(i,'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa');
commit;
end loop;
end;
/
as '/home/oracle';
ALTER TABLESPACE tts_test READ ONLY;
expdp dumpfile=tts_test_$(date +%Y_%m_%d).dmp logfile=exp_tts_test_$(date +%Y_%m_%d).log directory=dump_dir transport_tablespaces=tts_test
identified by oracle;
grant connect, resource to tts_user;
select /*+ Parallel */ * from tbl_test;
insert /*+ APPEND */ into tbl_test
select /*+ Parallel */ * from tbl_test;
insert /*+ APPEND */ into tbl_test
select /*+ Parallel */ * from tbl_test;
SELECT sequence#, first_time, next_time, applied
FROM v$archived_log
ORDER BY sequence#;
ALTER DATABASE RECOVER MANAGED STANDBY DATABASE DISCONNECT FROM SESSION;
Lets create a tablespace, schema, create table and insert some data on the table.
-- Create tablespace to test transportable tablespace
Create tablespace tts_testdatafile '/u01/app/oracle/oradata/orcl/tts_test01.dbf'
size 2m
autoextend on
next 2m
maxsize unlimited;
-- Create user schema
Create user tts_useridentified by oracle
default tablespace tts_test;
-- Grant required privileges
Grant connect, resource to tts_user;
-- Connect as user tts_user and create table
Conn tts_user/oracleCreate table tbl_test(
sn number,
name varchar2(200)
);
-- Insert huge data using PL/SQL below
declarebegin
for i in 1..50000000
loop
insert into tbl_test values(i,'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa');
commit;
end loop;
end;
/
Verify the number of rows on the table.
Select count(*) from tbl_test;
Connect as user sys, create directory and grant read, write privileges on directory to public.
-- Connect as user sys
Conn / as sysdba-- Create directory
Create directory dump_diras '/home/oracle';
-- Grant read, write privileges on directory to public.
Grant read,write on directory dump_dir to public;
Alter tablespace to read only state.
ALTER TABLESPACE tts_test READ ONLY;
Export tablespace with transport_tablespaces option.
expdp dumpfile=tts_test_$(date +%Y_%m_%d).dmp logfile=exp_tts_test_$(date +%Y_%m_%d).log directory=dump_dir transport_tablespaces=tts_testCopy datafile to oracle home.
In destination database with DataGuard configured. Execute impdp on Primary Database.
Copy datafiles to default datafile location.
cp ~oracle/tts_test01.dbf /u01/app/oracle/oradata/orcl/tts_test01.dbfCreate user tts_user and grant required privileges.
Create user tts_useridentified by oracle;
grant connect, resource to tts_user;
Now start import on destination database
impdp dumpfile=tts_test_$(date +%Y_%m_%d).dmp logfile=imp_tts_test_$(date +%Y_%m_%d).log directory=dump_dir transport_datafiles='/u01/app/oracle/oradata/orcl/tts_test01.dbf'Now modify user and set default tablespace and imported tablespace
alter user tts_user default tablespace tts_test;Set imported tablespace to read write.
alter tablespace tts_test read write;Verify table count.
select count(*) from tbl_test;Now insert rows on primary database so that log switch will occur and we can check recovery state on Standby database
insert /*+ APPEND */ into tbl_testselect /*+ Parallel */ * from tbl_test;
insert /*+ APPEND */ into tbl_test
select /*+ Parallel */ * from tbl_test;
insert /*+ APPEND */ into tbl_test
select /*+ Parallel */ * from tbl_test;
Execute following command on the Standby database to verify the status of recovery.
ALTER SESSION SET nls_date_format='DD-MON-YYYY HH24:MI:SS';SELECT sequence#, first_time, next_time, applied
FROM v$archived_log
ORDER BY sequence#;