Transportable Table Spaces

download Transportable Table Spaces

of 3

Transcript of Transportable Table Spaces

  • 7/28/2019 Transportable Table Spaces

    1/3

    Transportable Tablespaces

    Transportable tablespaces were introduced in Oracle 8i to allow whole tablespaces to be copied between databases in the time it takes to copy the datafiles. In Oracle 8i one of the restrictionswas that the block size of both databases must be the same. In Oracle 9i the introduction of multiple block sizes has removed this restriction. In this article I will run through a simple example oftransporting a tablespace between two databases.

    Setup

    Source Database

    Destination Database

    Related articles.

    Oracle Data Pump in Oracle Database 10g (expdp and impdp)

    Data Pump Enhancements in Oracle Database 11g Release 1

    SQL Developer 3.1 Data Pump Wizards (expdp, impdp)

    Setup

    For this example I'm going t o create a new tablespace, user and table t o work with in the source database.

    CONN / AS SYSDBA

    CREATE TABLESPACE test_dataDATAFILE '/u01/app/oracle/oradata/DB11G/test_data01.dbf'SIZE 1M AUTOEXTEND ON NEXT 1M;

    CREATE USER test_user IDENTIFIED BY test_userDEFAULT TABLESPACE test_dataTEMPORARY TABLESPACE tempQUOTA UNLIMITED ON test_data;

    GRANT CREATE SESSION, CREATE TABLE TO test_user;

    CONN test_user/test_user

    CREATE TABLE test_tab (id NUMBER,description VARCHAR2(50),CONSTRAINT test_tab_pk PRIMARY KEY (id)

    );

    INSERT /*+ APPEND */ INTO test_tab (id, description)SELECT level,

    'Description for ' || levelFROM dualCONNECT BY level

  • 7/28/2019 Transportable Table Spaces

    2/3

    CONN / AS SYSDBAEXEC DBMS_TTS.TRANSPORT_SET_CHECK(ts_list => 'TEST_DATA',incl_constraints => TRUE);

    PL/SQL procedure successfully completed.

    SQL>

    TheTRANSPORT_SET_VIOLATIONS view is used to check for any violations.

    SELECT * FROM transport_set_violations;

    no rows selected

    SQL>

    Assuming no violations are produced we are ready to proceed by switching the tablespace to read only mode.

    SQL> ALTER TABLESPACE test_data READ ONLY;

    Tablespace altered.

    SQL>

    Next we export the tablespace metadata using the export (expdp or exp) utility. If you are using 10g or above you should use t he expdp utility. This requires a directory object pointing to a physicaldirectory with the necessary permissions on the database server.

    CONN / AS SYSDBACREATE OR REPLACE DIRECTORY temp_dir AS '/tmp/';GRANT READ, WRITE ON DIRECTORY temp_dir TO system;

    We can now export the tablespace metadata.

    $ expdp userid=system/password directory=temp_dirtransport_tablespaces=test_data dumpfile=test_data.dmplogfile=test_data_exp.log

    If you are using a version prior to 10g, you do not need the directory object and your command would look something like this.

    $ exp userid='system/password as sysdba' transport_tablespace=ytablespaces=test_data file=test_data.dmp log=test_data_exp.log

    Copy the datafile to the appropriate location on the destination database server. Also copy the dump file t o a suitable place on the destination database server. You may use binary FTP or SCP to

    perform this copy.

    The source tablespace can now be switched back to read/write mode.

    ALTER TABLESPACE test_data READ WRITE;

    Tablespace altered.

    SQL>

  • 7/28/2019 Transportable Table Spaces

    3/3

    Destination Database

    Create any users in the destination database that owned objects within the tablespace being transported, assuming they do not already exist.

    CONN / AS SYSDBA

    CREATE USER test_user IDENTIFIED BY test_user;GRANT CREATE SESSION, CREATE TABLE TO test_user;

    Now we import the metadata i nto the destination database. If you are using 10g or above you should use the impdp utility. This requires a directory object pointing to a physical directory with thenecessary permissions on the database server.

    CONN / AS SYSDBACREATE OR REPLACE DIRECTORY temp_dir AS '/tmp/';GRANT READ, WRITE ON DIRECTORY temp_dir TO system;

    We can now import the tablespace metadata.

    $ impdp userid=system/password directory=temp_dirdumpfile=test_data.dmp logfile=test_data_imp.logtransport_datafiles='/u01/app/oracle/oradata/DB11GB/test_data01.dbf'

    If you are using a version prior to 10g, you do not need the directory object and your command would look something like this.

    $ imp userid='system/password as sysdba' transport_tablespace=ydatafiles='/u01/app/oracle/oradata/DB11GB/test_data01.dbf'tablespaces=test_data file=test_data.dmp log=test_data_imp.log

    Switch the new tablespace into read write mode.

    SQL> ALTER TABLESPACE test_data READ WRITE;

    Tablespace altered.

    SQL>

    The tablespace is now available in the destination database.

    SELECT tablespace_name, plugged_in, statusFROM dba_tablespacesWHERE tablespace_name = 'TEST_DATA';

    TABLESPACE_NAME PLU STATUS

    ------------------------------ --- ---------TEST_DATA YES ONLINE

    1 row selected.

    SQL>