Leveraging the Oracle Transportable Tablespaces and Oracle
Streams, the Oracle database offers an efficient way for migrating applications
to the Grid. With a single command, the database administrator can identify
a set of tablespaces from one database, ship the tablespace set to another database
even if the second database is on a different operating system or platform,
and plug this set into the second database. During this time, both the source
and destination databases are open and available for any user activity. Meanwhile,
Oracle Streams has begun to capture any changes from the source database that
occur during the tablespace copy to the replica database. After the tablespace
set is available at the replica database, the replica database is synchronized
by Oracle Streams with the changes from the source database. All of this is
done with a single command with no downtime required.
Creating the Users at the Source and Destination
Databases
You need to create a Streams Administrator and General User
on both the SITE1 and SITE2 databases. Perform the following steps:
1.
From your SQL*Plus session, execute the following SQL
command(s):
@crusers
The crusers.sql
script contains the following:
REM
REM Create STRMADMIN and OBE users at SITE1.US.ORACLE.COM
REM
grant connect, resource, dba, select_catalog_role to strmadmin
identified by <password>;
exec dbms_streams_auth.grant_admin_privilege('STRMADMIN',TRUE);
grant connect, resource to obe identified by <password>;
alter user OBE default tablespace OBETBS;
REM
REM Create STRMADMIN and OBE users at SITE2.US.ORACLE.COM
REM
connect sys/<password>@SITE2 as sysdba
grant connect, resource, dba, select_catalog_role to strmadmin
identified by <password>;
exec dbms_streams_auth.grant_admin_privilege('STRMADMIN',TRUE);
grant connect, resource to obe identified by <password>;
Setting Up Streams on the Destination Database
You need to now setup the Streams Queues, database links and
directories on the SITE2 database. Perform the following steps:
1.
You need to first setup your queue. From your SQL*Plus
session, execute the following SQL commands:
@site2_queue
The site2_queue.sql
script contains the following:
Now you need to create your database link to the site1
database. From your SQL*Plus session, execute the following SQL commands:
@site2_dblink
The site2_dblink.sql
script contains the following:
connect STRMADMIN/<password>@SITE2 create database link site1 connect to strmadmin identified by <password> using 'site1';
3.
The last step to setting up streams on the site2 database
is to create the directories where the files will go. From your SQL*Plus
session, execute the following SQL commands:
@site2_directory
The site2_directory.sql
script contains the following:
connect STRMADMIN/<password>@SITE2
drop directory OBE_SITE1_FILES;
drop directory OBE_SITE2_FILES;
create directory OBE_SITE1_FILES as '<oradata_directory>/site1/';
create directory OBE_SITE2_FILES as '<oradata_directory>/site2/';
Setting Up Streams on the Source Database
You need to now setup the Streams Queues, database links and
directories on the SITE1 database. Perform the following steps:
1.
You need to first setup your queue. From your SQL*Plus
session, execute the following SQL commands:
@site1_queue
The site1_queue.sql
script contains the following:
Next you need to create the directories on the SITE1
database where the files will go. From your SQL*Plus session, execute
the following SQL commands:
@site1_directory
The site1_directory.sql
script contains the following:
connect STRMADMIN/<password>@SITE1 drop directory OBE_SITE1_FILES; drop directory OBE_SITE2_FILES; drop directory ORACLE_DBS_DIR ;
create directory OBE_SITE1_FILES as '<oradata_directory>/site1/'; create directory OBE_SITE2_FILES as '<oradata_directory>/site2/'; create directory ORACLE_DBS_DIR as '<oradata_directory>/';
3.
The last step is to create a table in the tablespace
and put some data in it for streams to transport. From your SQL*Plus session,
execute the following SQL commands:
@loaddata
The loaddata.sql
script contains the following:
connect sys/<password>@SITE1 as sysdba grant all on hr.employees to obe;
connect obe/<password>@SITE1 create table employees as select * from hr.employees;
Maintaining Tablespaces
Now you are ready to run streams that will transport the tablespace
from the SITE1 database to the SITE2 database. Perform the following steps:
1.
First, you want to view the contents of the database
to see that there is data in the SITE1 database that is not in the SITE2
database. From your SQL*Plus session, execute the following script:
@chkdb
The chkdb.sql
script contains the following:
connect obe/<password>@SITE1 select * from employees;
connect obe/<password>@SITE2 select * from employees;
Note that there is no employees table in the SITE2 database.
2.
Now you want to run the streams process to transport
the tablespace. From your SQL*Plus session, execute the following script:
connect strmadmin/<password>@SITE1
@maintain_ts
The maintain_ts.sql
script contains the following: