Legal | Privacy

Using Oracle Streams to Maintain Tablespace Data

This module describes how to use Oracle Streams to maintain tablespace data.

This module will discuss the following topics

Overview
Prerequisites
Creating a Source and Destination Database using DBCA
Creating the Tablespace to be Transported on the Source Database
Creating the Users at the Source and Destination Databases
Setting Up Streams on the Destination Database
Setting Up Streams on the Source Database
Maintaining Tablespaces

Place the cursor on this icon to display all screenshots. You can also place the cursor on each icon to see only the screenshot associated with it.

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.

Before starting this module, you should have performed the following:

1.

Completed the Configuring Linux for the Installation of Oracle Database 10g lesson

 

2.

Completed the Installing the Oracle Database 10g on Linux lesson

 

3.

Download the streams.zip into your working directory.

 

This lesson requires two databases: a source database (SITE1) and a destination database (SITE2). Perform the following steps:

1.

From a terminal window, execute the following command:

dbca

 

2.

Click Next.

Move your mouse over this icon to see the image

 

3.

Make sure Create a Database is selected and click Next.

Move your mouse over this icon to see the image

 

4.

Select General Purpose and click Next.

Move your mouse over this icon to see the image

 

5.

Enter site1.us.oracle.com for the Global Database Name and site1 for the SID and click Next.

Move your mouse over this icon to see the image

 

6.

For Management Options, you want to select Use Database Control for Database Management and click Next.

Move your mouse over this icon to see the image

 

7.

Select Use Same Password for All Accounts and enter a password and confirm password and click Next.

Move your mouse over this icon to see the image

 

8.

Make sure File system is selected and click Next.

Move your mouse over this icon to see the image

 

9.

Click the Use Common Location for All Database Files and enter /u01/app/oracle/oradata in the Database Area field. Click Next.

Move your mouse over this icon to see the image

 

10.

Click Enable Archiving and click Next.

Move your mouse over this icon to see the image

 

11.

Select Sample Schemas and click Next.

Move your mouse over this icon to see the image

 

12.

Accept the defaults for Initialization Parameters and click Next.

Move your mouse over this icon to see the image

 

13.

Accept the defaults for Database Storage and click Next.

Move your mouse over this icon to see the image

 

14.

Make sure Create Database is checked and click Next.

Move your mouse over this icon to see the image

 

15.

At the Confirmation screen, click OK to start the database creation.

Move your mouse over this icon to see the image

 

16.

You will see the progress window appear.

Move your mouse over this icon to see the image

 

17.

You need to unlock the HR user. Click Password Management.

Move your mouse over this icon to see the image

 

18.

Scroll down to the HR user, click the Unlock Account? column and enter HR in both the new password and confirm password fields and click OK.

Move your mouse over this icon to see the image

 

19.

After the database has been created, click Exit.

Move your mouse over this icon to see the image

 

20.

You want to perform the same steps again for the site2.us.oracle.com database.

 

To show the new transportable tablespace capability using Streams, you need to create a Tablespace on the SITE1 database. Perform the following steps:

1.

From a terminal window, execute the following command(s):

cd wkdir
sqlplus /nolog
@crtblsp

The crtblsp.sql script contains the following:

connect sys/<password>@SITE1 as sysdba
create tablespace obetbs datafile '<oradata_directory>/obetbs.dbf' size 20m;

Move your mouse over this icon to see the image

 

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>;

Move your mouse over this icon to see the image

 

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:

connect STRMADMIN/<password>@SITE2
exec dbms_streams_adm.set_up_queue();

Move your mouse over this icon to see the image

 

2.

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';

Move your mouse over this icon to see the image

 

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/';

Move your mouse over this icon to see the image

 

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:

connect STRMADMIN/<password>@SITE1
exec dbms_streams_adm.set_up_queue();

Move your mouse over this icon to see the image

 

2.

Now you need to create your database link to the SITE2 database. From your SQL*Plus session, execute the following SQL commands:

@site1_dblink

The site1_dblink.sql script contains the following:

connect STRMADMIN/<password>@SITE1
create database link site2 connect to strmadmin identified by <password> using 'site2';

Move your mouse over this icon to see the image

 

2.

You also need to create the propagation on your SITE2 database. From your SQL*Plus session, execute the following SQL commands:

@site1_propagation

The site1_propagation.sql script contains the following:

connect STRMADMIN/<password>@SITE1
exec dbms_propagation_adm.create_propagation('STRMADMIN_SITE1_STRM',
   'STRMADMIN.STREAMS_QUEUE','STRMADMIN.STREAMS_QUEUE','SITE2',null);

Move your mouse over this icon to see the image

 

3.

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>/';

Move your mouse over this icon to see the image

 

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;

Move your mouse over this icon to see the image

 

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;

Move your mouse over this icon to see the image

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:

BEGIN
DBMS_STREAMS_ADM.MAINTAIN_SIMPLE_TABLESPACE(
tablespace_name=>'OBETBS' ,
source_directory_object=>'OBE_SITE1_FILES' ,
destination_directory_object=>'OBE_SITE2_FILES' ,
destination_database=>'SITE2.US.ORACLE.COM',
setup_streams=>true,
bi_directional=>true);
END;
/

Move your mouse over this icon to see the image

 

3.

Once the script finishes you can rerun the script to check the 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;

Move your mouse over this icon to see the image

Note that you now have data in the SITE2 database.

 

Place the cursor on this icon to hide all screenshots.

 

E-mail this page
Printer View Printer View
Oracle Is The Information Company About Oracle | Oracle RSS Feeds | Careers | Contact Us | Site Maps | Legal Notices | Terms of Use | Privacy