Before You Begin
This 15-minute tutorial shows you how to transfer a SQL tuning set from one Oracle database to another Oracle database.
Background
You can use a staging table to transfer a SQL tuning set from one Oracle database (the source database) to another Oracle database (the target database). On the source database, load the SQL tuning set into a staging table. Use Oracle Data Pump to export the contents of the staging table to a file on the source database host. Transfer the file to the target database host. Use Oracle Data Pump to import the contents of the staging table into the target database, and then unpack the SQL tuning set into the target database.
What Do You Need?
- A source Oracle database
- A target Oracle database
- The
SYSDBA
administrative privilege on both databases - The
SYSTEM
user password on both databases - On the source database, a SQL tuning set. This tutorial assumes that the SQL tuning set is named
MY_WORKLOAD_STS
.
Create a Staging Table in the Source Database
- Use SQL*Plus to log in to the source database as a user who has the
SYSDBA
administrative privilege.$ sqlplus / as sysdba
- Create staging table
MY_STAGING_TABLE
in schemaSYSTEM
.
SQL> BEGIN
2 DBMS_SQLTUNE.CREATE_STGTAB_SQLSET(
3 table_name => 'MY_STAGING_TABLE',
4 schema_name => 'SYSTEM');
5 END;
6 / - Load SQL tuning set
MY_WORKLOAD_STS
into staging tableMY_STAGING_TABLE
.SQL> BEGIN
2 DBMS_SQLTUNE.PACK_STGTAB_SQLSET(
3 sqlset_name => 'MY_WORKLOAD_STS',
4 sqlset_owner => 'SYS',
5 staging_table_name => 'MY_STAGING_TABLE',
6 staging_schema_owner => 'SYSTEM');
7 END;
8 /
Copy the Staging Table from the Source Database to the Target Database
- While still connected to SQL*Plus on the source database, create a directory object that references a staging directory in the
/tmp
directory.SQL> CREATE DIRECTORY stg_dir AS '/tmp/stg_dir';
- Exit SQL*Plus.
SQL> exit
- Create the staging directory.
$ mkdir /tmp/stg_dir
- Use Oracle Data Pump to export the contents of the staging table to a dumpfile in the staging directory. The dumpfile is named
my_workload_sts.dmp
.$ expdp SYSTEM/password DIRECTORY=stg_dir DUMPFILE=my_workload_sts.dmp TABLES=system.my_staging_table
- Copy the dumpfile from the source database host to the target database host by using a secure copy utility like
scp
or WinSCP. - Log in to the target database host.
- Create a staging directory on the target database host.
$ mkdir /tmp/stg_dir
- Navigate to the directory containing the dumpfile that you just transferred to the target database host, and move the dumpfile to the staging directory.
$ mv my_workload_sts.dmp /tmp/stg_dir
- Use SQL*Plus to log in to the target database as a user who has the
SYSDBA
administrative privilege.$ sqlplus / as sysdba
- Create a directory object that references the staging directory.
SQL> CREATE DIRECTORY stg_dir AS '/tmp/stg_dir';
- Exit SQL*Plus.
SQL> exit
- Use Oracle Data Pump to import the contents of the staging table from the dumpfile in the staging directory.
$ impdp SYSTEM/password DIRECTORY=stg_dir DUMPFILE=my_workload_sts.dmp TABLES=system.my_staging_table
Load the SQL Tuning Set into the Target Database
- While still connected to the target database host, invoke SQL*Plus and log in to the target database as a user who has the
SYSDBA
administrative privilege.$ sqlplus / as sysdba
- Load the SQL tuning set
MY_WORKLOAD_STS
from the staging table into the target database.SQL> BEGIN
2 DBMS_SQLTUNE.UNPACK_STGTAB_SQLSET(
3 sqlset_name => 'MY_WORKLOAD_STS',
4 replace => true,
5 staging_table_name => 'MY_STAGING_TABLE',
6 staging_schema_owner => 'SYSTEM');
7 END;
8 /
Clean Up
- While still connected to the target database, delete the staging directory and the staging table.
SQL> DROP DIRECTORY stg_dir;
SQL> DROP TABLE SYSTEM.MY_STAGING_TABLE; - Exit SQL*Plus.
SQL> exit
- Remove the staging directory from the target database host.
$ rm -rf /tmp/stg_dir
- Log in to the source database host.
- Use SQL*Plus to log in to the source database as a user who has the
SYSDBA
administrative privilege.$ sqlplus / as sysdba
- On the source datbase, delete the staging directory and the staging table.
SQL> DROP DIRECTORY stg_dir;
SQL> DROP TABLE SYSTEM.MY_STAGING_TABLE; - Exit SQL*Plus.
SQL> exit
- Remove the staging directory from the source database host.
$ rm -rf /tmp/stg_dir