Want to quickly copy 1000's of tables from one Oracle database to another Oracle database in just 5 minutes! Even if there are thousand of tables with million of rows in each of them. Even if Oracle databases are running on different platforms.
You would be wondering how it is possible. Well yes it is possible and today I am going to show you how you could achieve this. So read on.
As you must be knowing that in Oracle all tables reside in tablespaces and each tablespace have at least one or more datafiles attached to it.
From Oracle version 9i onwards Oracle has introduced the concept of transportable tablespaces. i.e. you can transport a tablespace along with its datafiles from one Oracle database to another Oracle database. Here are the steps you will need to perform tablespace transportation.
Migrating a tablespace from one Oracle database to another involves creating a transportable tablespace set and integrating it into the target database. Here’s a detailed guide:
On the source database, make the tablespace read-only to ensure data consistency during the export.
ALTER TABLESPACE tablespace_name READ ONLY;
Use the Data Pump Export (expdp) utility to export the metadata for the tablespace.
expdp system/password DIRECTORY=dp_dir DUMPFILE=tablespace.dmp LOGFILE=tablespace.log TRANSPORT_TABLESPACES=tablespace_name
Manually copy the physical data files of the tablespace from the source database server to the target database server.
Run the following query in the source database to find the file paths:
SELECT FILE_NAME FROM DBA_DATA_FILES WHERE TABLESPACE_NAME = 'tablespace_name';
Use secure copy tools like scp or a shared directory to copy the files.
scp /source_path/file_name.dbf user@target_host:/target_path
On the target database, use Data Pump Import (impdp) to import the metadata.
impdp system/password DIRECTORY=dp_dir DUMPFILE=tablespace.dmp LOGFILE=tablespace_import.log
TRANSPORT_DATAFILES='/target_path/file_name.dbf'
TRANSPORT_DATAFILES: Specify the location of the copied data files.
Once the import is complete, set the tablespace to read-write mode in the target database.
ALTER TABLESPACE tablespace_name READ WRITE;
Run the following query in the target database to ensure all objects are intact:
SELECT * FROM DBA_SEGMENTS WHERE TABLESPACE_NAME = 'tablespace_name';
Confirm that applications or users can access the data without issues.
If the tablespace is no longer required on the source database, you can drop it.
DROP TABLESPACE tablespace_name INCLUDING CONTENTS AND DATAFILES;
This method provides a robust and efficient way to migrate tablespaces between Oracle databases while minimizing downtime.
Here’s a practical example demonstrating how to migrate the
USERS_DATA
tablespace from one Oracle database to another:
ORCL_SRC
ORCL_TGT
USERS_DATA
/u01/app/oracle/oradata/ORCL_SRC/users_data01.dbf
DATA_PUMP_DIR
On the source database (ORCL_SRC
), set the USERS_DATA
tablespace to read-only mode:
ALTER TABLESPACE USERS_DATA READ ONLY;
Run the Data Pump Export command on the source database server to export metadata for the USERS_DATA tablespace:
expdp system/password DIRECTORY=DATA_PUMP_DIR DUMPFILE=users_data.dmp LOGFILE=users_data.log TRANSPORT_TABLESPACES=USERS_DATA
Locate the data file(s) for USERS_DATA in the source database:
SELECT FILE_NAME FROM DBA_DATA_FILES WHERE TABLESPACE_NAME = 'USERS_DATA';
/u01/app/oracle/oradata/ORCL_SRC/users_data01.dbf
Copy the file to the target database server using scp:
scp /u01/app/oracle/oradata/ORCL_SRC/users_data01.dbf oracle@target_host:/u01/app/oracle/oradata/ORCL_TGT/
On the target database (ORCL_TGT), import the metadata for USERS_DATA:
impdp system/password DIRECTORY=DATA_PUMP_DIR DUMPFILE=users_data.dmp
LOGFILE=users_data_import.log TRANSPORT_DATAFILES='/u01/app/oracle/oradata/ORCL_TGT/users_data01.dbf'
Once the import completes, change the USERS_DATA tablespace to read-write mode in the target database:
ALTER TABLESPACE USERS_DATA READ WRITE;
Check the imported objects in the target database:
SELECT * FROM DBA_SEGMENTS WHERE TABLESPACE_NAME = 'USERS_DATA';
Ensure all objects are listed as expected.
If the tablespace is no longer required on the source database, drop it:
DROP TABLESPACE USERS_DATA INCLUDING CONTENTS AND DATAFILES;
If the DATA_PUMP_DIR
directory doesn’t exist on either
server, create it:
CREATE OR REPLACE DIRECTORY DATA_PUMP_DIR AS '/u01/app/oracle/admin/ORCL_SRC/dpdump'; GRANT READ, WRITE ON DIRECTORY DATA_PUMP_DIR TO SYSTEM;
The USERS_DATA
tablespace is successfully migrated from
ORCL_SRC
to ORCL_TGT
, ensuring seamless
availability of data on the target database.
So here it is. This is how easy it is to transport one tablespace from one Oracle database to another Oracle database.