Bulk refresh of test DB environments using RMAN backup based duplication

May 7, 2012 by · 3 Comments 

I don’t know about you folks, but the most boring & time consuming task is always refreshing test environments. If you are working on a billing migration project, than it is a common practice to refresh test, dev, uat and migration databases every 2 weeks. In this case there is a recent RMAN backup of a database named CBIO01 that needs to be restored over 15+ databases (which are not created) and I am going to clone existing RMAN backup like in the previous post

http://database.com.mk/wordpress/2011/08/05/rman-backup-based-duplication-without-a-target-and-without-a-recovery-catalog-connection/

To accomplish this task, I have three staging files:

1) “initSTAGING.ora” – baseline init.ora parameter for the new databases
2) “duplicate_CBIO01_to_ORACLE_STAGING_SID.rmn” – RMAN parameter file used to create a clone/create new database from a previous backup
3) “run_duplicate_CBIO01_to_ORACLE_STAGING_SID.sh” – Shell script that starts RMAN duplicate database

Before creating a new database, ORACLE_STAGING_SID and ORACLE_SID should be set to the desired new DB name that we are about to create.

$ export ORACLE_STAGING_SID=TESTDB
$ export ORACLE_SID=$ORACLE_STAGING_SID

Create folders that are being used by init.ora for the new DB that we are creating. In this case, I am about to clone existing DB backup into a mount point /u03/.

$ mkdir -p /u01/app/oracle/admin/$ORACLE_STAGING_SID/adump
$ mkdir -p /u03/$ORACLE_STAGING_SID/

Next, using SED I will replace the string “_ORACLE_STAGING_SID_” with the previously exported $ORACLE_STAGING_SID in all three staging files and generate 3 new.

$ sed -e "s/_ORACLE_STAGING_SID_/$ORACLE_STAGING_SID/g" initSTAGING.ora > init$ORACLE_STAGING_SID.ora
$ sed -e "s/_ORACLE_STAGING_SID_/$ORACLE_STAGING_SID/g" duplicate_CBIO01_to_ORACLE_STAGING_SID.rmn > duplicate_CBIO01_to_$ORACLE_STAGING_SID.rmn
$ sed -e "s/_ORACLE_STAGING_SID_/$ORACLE_STAGING_SID/g" run_duplicate_CBIO01_to_ORACLE_STAGING_SID.sh > run_duplicate_CBIO01_to_$ORACLE_STAGING_SID.sh
$ chmod 755 run_duplicate_CBIO01_to_$ORACLE_STAGING_SID.sh
$ cp init$ORACLE_STAGING_SID.ora $ORACLE_HOME/dbs
$ alias rmanlog='tail -f /u03/nakinov/00.rman/03.duplicate/duplicate_CBIO01_to_$ORACLE_STAGING_SID.log'
$ alias dud='du -sk /u03/$ORACLE_STAGING_SID/'

$ sqlplus /nolog 2>&1 << EOF
startup nomount;
exit;
EOF

The results of the above statements will be three new files:

- initTESTDB.ora
- duplicate_CBIO01_to_TESTDB.rmn
- run_duplicate_CBIO01_to_TESTDB.sh

To start the RMAN restore/clone simply execute the shell script and monitor the progress of RMAN clone.

# Duplicate database
$ nohup time ./run_duplicate_CBIO01_to_TESTDB.sh &

# Monitor progress of RMAN
$ rmanlog

Contents of initSTAGING.ora

*.audit_file_dest='/u01/app/oracle/admin/_ORACLE_STAGING_SID_/adump'
*.audit_trail='none'
*.compatible='11.2.0.0.0'
*.control_files='/u03/_ORACLE_STAGING_SID_/control01.ctl','/u03/_ORACLE_STAGING_SID_/control02.ctl'
*.db_block_size=8192
*.db_domain=''
*.db_files=600
*.db_name='_ORACLE_STAGING_SID_'
*.diagnostic_dest='/u01/app/oracle'
*.dispatchers='(PROTOCOL=TCP) (SERVICE=_ORACLE_STAGING_SID_XDB)'
*.large_pool_size=33554432
*.open_cursors=500
*.optimizer_index_cost_adj=25
*.pga_aggregate_target=4194304000
*.processes=1000
*.remote_login_passwordfile='EXCLUSIVE'
*.sec_case_sensitive_logon=FALSE
*.sessions=1105
*.sga_target=4194304000
*.undo_tablespace='UNDOTBS1'

Contents of duplicate_CBIO01_to_ORACLE_STAGING_SID.rmn

run {

		set newname for datafile 1 to '/u03/_ORACLE_STAGING_SID_/bscs_contract_all_01.dbf';
		set newname for datafile 2 to '/u03/_ORACLE_STAGING_SID_/bscs_contract_all_02.dbf';
		set newname for datafile 3 to '/u03/_ORACLE_STAGING_SID_/bscs_contract_all_03.dbf';
		set newname for datafile 4 to '/u03/_ORACLE_STAGING_SID_/bscs_contract_all_04.dbf';
		set newname for datafile 5 to '/u03/_ORACLE_STAGING_SID_/bscs_contract_all_05.dbf';
		set newname for datafile 6 to '/u03/_ORACLE_STAGING_SID_/bscs_contract_service_01.dbf';

		set newname for tempfile 1 to '/u03/_ORACLE_STAGING_SID_/temp_01.dbf';

		allocate auxiliary channel c1 type disk format '/u03/backup/rman/cbio01_d2_22032012/cbio01_d2_%p_%s_%T.bkp';
		allocate auxiliary channel c2 type disk format '/u03/backup/rman/cbio01_d2_22032012/cbio01_d2_%p_%s_%T.bkp';
		allocate auxiliary channel c3 type disk format '/u03/backup/rman/cbio01_d2_22032012/cbio01_d2_%p_%s_%T.bkp';
		allocate auxiliary channel c4 type disk format '/u03/backup/rman/cbio01_d2_22032012/cbio01_d2_%p_%s_%T.bkp';
		allocate auxiliary channel c5 type disk format '/u03/backup/rman/cbio01_d2_22032012/cbio01_d2_%p_%s_%T.bkp';
		allocate auxiliary channel c6 type disk format '/u03/backup/rman/cbio01_d2_22032012/cbio01_d2_%p_%s_%T.bkp';

		 duplicate database to _ORACLE_STAGING_SID_
		 pfile=/u01/app/oracle/product/11.2.0.3/db_1/dbs/init_ORACLE_STAGING_SID_.ora
		 backup location='/u03/backup/rman/cbio01_d2_22032012/'
				logfile group 1 ('/u03/_ORACLE_STAGING_SID_/redo01.log') size 300M reuse,
						group 2 ('/u03/_ORACLE_STAGING_SID_/redo02.log') size 300M reuse,
						group 3 ('/u03/_ORACLE_STAGING_SID_/redo03.log') size 300M reuse;

		release channel c1;
        release channel c2;
        release channel c3;
        release channel c4;
        release channel c5;
        release channel c6;

}

exit;

Contents of run_duplicate_CBIO01_to_ORACLE_STAGING_SID.sh

#!/usr/bin/bash

# TODO: Before running this script
# sqlplus /nolog
# conn / as sysdba
# shutdown immediate
# startup mount
# alter system set large_pool_size=2G;

export ORACLE_HOME=/u01/app/oracle/product/11.2.0.3/db_1
export NLS_LANG=AMERICAN_AMERICA.WE8ISO8859P15
export ORACLE_SID=_ORACLE_STAGING_SID_ 

rman auxiliary / nocatalog cmdfile=duplicate_CBIO01_to__ORACLE_STAGING_SID_.rmn log=duplicate_CBIO01_to__ORACLE_STAGING_SID_.log

#
# End of script
#

Create RAC DB with DBCA and no GUI using silent method

May 4, 2012 by · Leave a Comment 

One feature I love in DBCA is its ability to create a database without using a GUI. These tasks are common for DBAs which work remotely, usually having only shell access. I am using a template which I had created before, since I am using a non standard block size of 32K. You can try with the already provided templates like General_Purpose.dbc which are located in: $ORACLE_HOME/assistants/dbca/templates/

# Create a new RAC DB named RTX01 using two nodes (db1, db2)
# Store data files on an ASM diskgroup DATA
# Total memory allocation (SGA+PGA) is 4000 MB

nohup time dbca -silent
				-nodelist db1,db2
				-createDatabase -templateName RTX.dbt
				-gdbName RTX01 -sid RTX01
				-SysPassword ******** -SystemPassword ********
				-emConfiguration NONE
				-storageType ASM -asmSysPassword ******** -diskGroupName DATA
				-characterSet WE8ISO8859P15
				-totalMemory 4000 &

The output of nohup.out should look like this:

Creating and starting Oracle instance
1% complete
3% complete
Creating database files
4% complete
7% complete
Creating data dictionary views
8% complete
9% complete
10% complete
11% complete
12% complete
13% complete
14% complete
16% complete
17% complete
18% complete
19% complete
Adding Oracle JVM
25% complete
30% complete
36% complete
38% complete
Adding Oracle Text
39% complete
40% complete
41% complete
Adding Oracle XML DB
43% complete
44% complete
45% complete
49% complete
Adding Oracle Multimedia
50% complete
60% complete
Adding Oracle OLAP
61% complete
62% complete
64% complete
Adding Oracle Spatial
65% complete
66% complete
67% complete
71% complete
Adding Enterprise Manager Repository
73% complete
75% complete
Adding Oracle Application Express
78% complete
82% complete
Creating cluster database views
83% complete
90% complete
Completing Database Creation
91% complete
92% complete
95% complete
98% complete
100% complete
Look at the log file "/u01/app/oracle/cfgtoollogs/dbca/RTX01/RTX01.log" for further details.
$ srvctl status database -d RTX01
Instance RTX011 is running on node db1
Instance RTX012 is running on node db2

Oracle Golden Gate – Create unidirectional 1:1 change data capture

April 26, 2012 by · Leave a Comment 

Let us first create some sample tables on both source and target databases.

-- Execute on both src and tgt database
DROP TABLE SYSADM.LAZAR_T2;
DROP TABLE SYSADM.LAZAR_T1;

CREATE TABLE SYSADM.LAZAR_T1
(
	DEPTNO    INTEGER     NOT NULL,
    DEPTNAME  VARCHAR(29),
    MGRNO     CHAR(6),
    ADMRDEPT  CHAR(3),
    LOCATION  CHAR(16),
    PRIMARY KEY (DEPTNO)
);

CREATE TABLE SYSADM.LAZAR_T2
(
	EMPNO     NUMBER(6) NOT NULL PRIMARY KEY,
    FIRSTNME  VARCHAR(12),
    LASTNAME  VARCHAR(15),
    WORKDEPT  INTEGER,
    PHONENO   CHAR(4)
);

alter table SYSADM.LAZAR_T2
add constraint LAZAR_T2_FK1 foreign key( WORKDEPT ) references SYSADM.LAZAR_T1( DEPTNO );

insert into SYSADM.LAZAR_T1 values (1,'Test1', '100','100','FFM1');
insert into SYSADM.LAZAR_T1 values (2,'Test2', '200','200','FFM2');
insert into SYSADM.LAZAR_T1 values (3,'Test3', '300','300','FFM3');

insert into SYSADM.LAZAR_T2 values (1,'A1','B1',1,'1234');
insert into SYSADM.LAZAR_T2 values (2,'A2','B2',2,'1234');
insert into SYSADM.LAZAR_T2 values (3,'A3','B3',3,'1234');
commit;

Using DEFGEN utility, I’ve created file with table structure info that will be used by the replicat process.

# On the SOURCE
ggsci> edit params defgen
defsfile ./dirsql/tables_sysadm.sql
userid ggs_admin password ********
table SYSADM.LAZAR_T1;
table SYSADM.LAZAR_T2;

and from the shell using DEFGEN generate the definition file and scp it to the target server into the GG home.

$ ./defgen paramfile ./dirprm/defgen.prm
$ scp tables_sysadm.sql oracle@192.168.1.111:/ggs/dirsql/

Let’s setup the extract and datapump process on the source.

# On the Source
# Add transaction info for the tables we want to CDC

ggsci> DBLOGIN USERID ggs_admin, PASSWORD ********
ggsci> ADD TRANDATA SYSADM.LAZAR_T1
ggsci> ADD TRANDATA SYSADM.LAZAR_T2

ggsci> edit params EX01 

-- Extract Collector
EXTRACT EX01
USERID ggs_admin, PASSWORD ********
EXTTRAIL ./dirdat/aa
TABLE SYSADM.LAZAR_T1;

ggsci> edit params EX02 

EXTRACT EX02
USERID ggs_admin, PASSWORD ********
EXTTRAIL ./dirdat/ab
TABLE SYSADM.LAZAR_T2;

ggsci> add extract EX01, tranlog, begin now
ggsci> add exttrail ./dirdat/aa, extract EX01, megabytes 50

ggsci> add extract EX02, tranlog, begin now
ggsci> add exttrail ./dirdat/ab, extract EX02, megabytes 50

-- Extract Datapump
ggsci> edit params EXPMP01

EXTRACT EXPMP01
PASSTHRU
RMTHOST 192.168.1.111, MGRPORT 7809
RMTTRAIL ./dirdat/aa
TABLE SYSADM.LAZAR_T1;

ggsci> edit params EXPMP02

EXTRACT EXPMP02
PASSTHRU
RMTHOST 192.168.1.111, MGRPORT 7809
RMTTRAIL ./dirdat/ab
TABLE SYSADM.LAZAR_T2;

ggsci> add extract EXPMP02, EXTTRAILSOURCE ./dirdat/ab
ggsci> add rmttrail ./dirdat/ab, EXTRACT EXPMP02, megabytes 50

-- Start extract
ggsci> start extract EX01
ggsci> start extract EX02

-- Start datapump
ggsci> start extract EXPMP01
ggsci> start extract EXPMP02

-- Check if both extracts and datapump processes are running
ggsci> info all

Program     Status      Group        Lag           Time Since Chkpt

MANAGER     RUNNING
EXTRACT     RUNNING     EX01     	 00:00:00      00:00:07
EXTRACT     RUNNING     EX02     	 00:00:00      00:00:08
EXTRACT     RUNNING     EXPMP01      00:00:00      00:00:08
EXTRACT     RUNNING     EXPMP02      00:00:00      00:00:02

And on the target host, create the replicate groups, associate with the trail files and start them.

-- Target
ggsci> DBLOGIN USERID ggs_admin, PASSWORD ********
ggsci> ADD TRANDATA SYSADM.LAZAR_T1
ggsci> ADD TRANDATA SYSADM.LAZAR_T2

ggsci> edit params REP01

REPLICAT REP01
USERID ggs_admin, PASSWORD ********
SOURCEDEFS ./dirsql/tables_sysadm.sql
DISCARDFILE ./dirrpt/REP01.dsc, PURGE
MAP SYSADM.*, TARGET SYSADM.*;

ggsci> edit params REP02

REPLICAT REP02
USERID ggs_admin, PASSWORD ********
SOURCEDEFS ./dirsql/tables_sysadm.sql
DISCARDFILE ./dirrpt/REP02.dsc, PURGE
MAP SYSADM.*, TARGET SYSADM.*;

ggsci> add replicat REP01, exttrail ./dirdat/aa
ggsci> add replicat REP02, exttrail ./dirdat/ab
ggsci> start replicat REP01
ggsci> start replicat REP02

ggsci> info all

Program     Status      Group       Lag           Time Since Chkpt

MANAGER     RUNNING
REPLICAT    RUNNING     REP01     	00:00:00      00:00:07
REPLICAT    RUNNING     REP02     	00:00:00      00:00:05

To test the configuration login to the source database, make a few DMLs, inserts firsts, than updates & deletes and check if the changes are being replicated to the target.

-- On the source DB
insert into SYSADM.LAZAR_T1 values (4,'Test4', '400','400','FFM4');
insert into SYSADM.LAZAR_T1 values (5,'Test5', '500','500','FFM5');
commit;

-- On the target DB
select count(0) from SYSADM.LAZAR_T1;

-- On the source DB
insert into SYSADM.LAZAR_T1 values (6,'Test6', '600','600','FFM6');
insert into SYSADM.LAZAR_T1 values (7,'Test7', '700','700','FFM7');
commit;

-- On the target DB
select count(0) from SYSADM.LAZAR_T1;

-- On the source DB
delete from SYSADM.LAZAR_T1 where DEPTNO > 3;
commit;

-- On the target DB
select count(0) from SYSADM.LAZAR_T1;

Next Page »