Monday, June 9, 2008

Transportable Tablespace

General You can use the transportable tablespaces feature to move a subset of an Oracle database and "plug" it in to another Oracle database, essentially moving tablespaces between the databases. The tablespaces being transported can be either dictionary managed or locally managed. Starting with Oracle9i, the transported tablespaces are not required to be of the same block size as the target database's standard block size. Transporting tablespaces is particularly useful for:

Moving data from OLTP systems to data warehouse staging systems Updating data warehouses and data marts from staging systems Loading data marts from central data warehouses Archiving OLTP and data warehouse systems efficiently Data publishing to internal and external customers Performing Tablespace Point-in-Time Recovery (TSPITR)

Moving data using transportable tablespaces can be much faster than performing either an export/import or unload/load of the same data, because transporting a tablespace only requires the copying of datafiles and integrating the tablespace structural information. You can also use transportable tablespaces to move index data, thereby avoiding the index rebuilds you would have to perform when importing or loading table data.

LIMITATIONS

Be aware of the following limitations as you plan for transportable tablespace use:

The source and target database must be on the same hardware platform. For example, you can transport tablespaces between Sun Solaris Oracle databases, or you can transport tablespaces between Windows NT Oracle databases. However, you cannot transport a tablespace from a Sun Solaris Oracle database to an Windows NT Oracle database. The source and target database must use the same character set and national character set. You cannot transport a tablespace to a target database in which a tablespace with the same name already exists. Transportable tablespaces do not support: Materialized views/replication Function-based indexes.

Demo:-
conn / as sysdba
set pagesize 20
col platform_name format a35

desc gv$transportable_platform

SELECT * FROM v$transportable_platform ORDER BY 1;

CREATE TABLESPACE tts
DATAFILE 'c:\temp\tts.dbf' size 10M
BLOCKSIZE 8192
EXTENT MANAGEMENT LOCAL UNIFORM SIZE 64K
SEGMENT SPACE MANAGEMENT AUTO ONLINE;

CREATE OR REPLACE DIRECTORY trans_dir AS 'c:\tts';

GRANT READ, WRITE ON DIRECTORY trans_dir TO public;

SELECT tablespace_name, contents, status FROM dba_tablespaces;

ALTER USER amazon QUOTA UNLIMITED ON tts;

conn amazon/amazon

CREATE TABLE t1 (pid NUMBER(5), lname VARCHAR2(20)) TABLESPACE uwdata;

ALTER TABLE t1 ADD CONSTRAINT pk_t1 PRIMARY KEY (pid) USING INDEX PCTFREE 0 TABLESPACE tts;

CREATE TABLE t2 (pid NUMBER(5), lname VARCHAR2(20)) TABLESPACE tts;

ALTER TABLE t2 ADD CONSTRAINT pk_t2 PRIMARY KEY (pid) USING INDEX PCTFREE 0 TABLESPACE uwdata;

conn / as sysdba

EXECUTE DBMS_TTS.TRANSPORT_SET_CHECK('tts', TRUE);

SELECT * FROM TRANSPORT_SET_VIOLATIONS;

conn amazon/amazon

ALTER TABLE t1 MOVE TABLESPACE tts;

ALTER INDEX pk_t2 REBUILD TABLESPACE tts;

conn / as sysdba

EXECUTE DBMS_TTS.TRANSPORT_SET_CHECK('tts', TRUE);

SELECT * FROM TRANSPORT_SET_VIOLATIONS;

ALTER TABLESPACE tts READ ONLY;

-- in o/s window

expdp system/manager
DUMPFILE=tts.dmp
DIRECTORY=trans_dir
TRANSPORT_TABLESPACES = tts

conn / as sysdba

DROP TABLESPACE tts INCLUDING CONTENTS AND DATAFILES;

-- in o/s window

impdp system/manager parfile=trans.par
/*
DUMPFILE=trans.dmp
DIRECTORY=trans_dir
REMAP_SCHEMA=amazon:uwclass
TRANSPORT_DATAFILES='c:\temp\tts.dbf'
*/

conn / as sysdba

SELECT tablespace_name, contents, status FROM dba_tablespaces;