Affichage des articles dont le libellé est RMAN. Afficher tous les articles
Affichage des articles dont le libellé est RMAN. Afficher tous les articles

vendredi 13 novembre 2015

Migration From 11gr2 To 12c Using Rman Duplicate NoOpen New Feature

Introduction:

The goal of this article is to show you how i have migrated an 11gr2 database to 12c, using Duplicate with the new feature NOOPEN.


We assume that the the first database is DB1 on the server S1 : 11.2.0.3
and that the second database is DB2 on the server S2 : 12.1.0.2




A. Check list to do Source Database


I. Pre-Upgrade Steps:

Complete Checklist for Manual Upgrades to Oracle Database 12c Release 1 (12.1)
 (Doc ID 1503653.1)

The Pre-upgrade must be applied on the first database DB1.
Run the Pre-Upgrade Information Tool for Collecting Pre-Upgrade Information
* Log into the system as the owner of the Oracle Database 12c Release 1 (12.1) Oracle Home directory.
* Copy the Pre-Upgrade Information Tool script preupgrd.sql and utluppkg.sql from the Oracle

 Database 12c Release 1 (12.1) $ORACLE_HOME/rdbms/admin directory to the
 $ORACLE_HOME/rdbms/admin directory of the source Oracle Home.
 Step 2:
 * Run the new Pre-Upgrade Information Tool. For example, if you copied preupgrd.sql to the /admin
 directory of the source Oracle Home:

SQL> @$ORACLE_HOME/rdbms/admin/preupgrd.sql  <==============ON DB1 !!!!
preupgrade.log, preupgrade_fixups.sql and postupgrade_fixups.sql files are created in
 $ORACLE_HOME/cfgtoollogs/$ORACLE_SID/preupgrade/, which is under the source database
 ORACLE_HOME to be upgraded.
You will obtain three files : the first two files to be applied on the source  DB1 and DB2 for parameters, the last one on the target : DB2

For DB1:
1./apps/oracle/cfgtoollogs/DB1/preupgrade/preupgrade.log
2./apps/oracle/cfgtoollogs/DB1/preupgrade/preupgrade_fixups.sql


For DB2:

Move /apps/oracle/cfgtoollogs/DB1/preupgrade/postupgrade_fixups.sql to the second server, for example on :
 /apps/oracle/cfgtoollogs/DB2/preupgrade/postupgrade_fixups.sql

1./apps/oracle/cfgtoollogs/DB2/preupgrade/postupgrade_fixups.sql
 Be carreful you must change :
      IF con_name = 'DB1' THEN
 to
     IF con_name = 'DB2' THEN
 Other note:
 the first pre-check file can give you some parameters to change : theses parameters must be changed on the target DB: DB2.

II. Rman Backup



Take and RMAN backup on the first database DB1.
rman "target / nocatalog"
RUN
{
ALLOCATE CHANNEL chan_name TYPE DISK;
BACKUP DATABASE FORMAT '<db_backup_directory>%U' TAG before_upgrade;
BACKUP CURRENT CONTROLFILE TO '<controlfile_backup_directory>';
}

Move the backup to the second server S2 : to /apps/oracle/DB2/Backup/













B. Restore the backup on the second database

On  the second database DB2, restore the backup using the Duplicate command.
Startup on nomount DB2 with appropriate 12c parameters : sepecially compatible set to 12.1.0 or higher.

. oraenv
DB2
rman auxiliary /








RMAN> run
{
 allocate auxiliary channel chnl1 device type disk;
 DUPLICATE DATABASE TO DB2 nofilenamecheck
 NOOPEN BACKUP LOCATION '/apps/oracle/DB2/Backup/' NOREDO ;
 }



We use NOOPEN : so RMAN stops at the MOUNT step.
We use NOREDO if the backup was COLD.



When the databse is restored, open it with the upgrade mode :


SQL> alter database open resetlogs upgrade;

C. Migration to 12c


Use catctl.pl to upgrade the database.

Run the catctl.pl script from the new Oracle home.
In this release, the new Upgrade Utility, catctl.pl, replaces catupgrd.sql.



cd $ORACLE_HOME/rdbms/admin
$ORACLE_HOME/perl/bin/perl  catctl.pl -n 6 -l  /apps/orafra/DB2/migration-12c/ catupgrd.sql

Analyzing file catupgrd.sql
Log files in /apps/orafra/DB2/migration-12c/
catcon: ALL catcon-related output will be written to /apps/orafra/DB2/migration-12c//catupgrd_catcon_13566188.lst
catcon: See /apps/orafra/DB2/migration-12c//catupgrd*.log files for output generated by scripts
catcon: See /apps/orafra/DB2/migration-12c//catupgrd_*.lst files for spool files, if any
Number of Cpus        = 8
SQL Process Count     = 6
------------------------------------------------------
Phases [0-73]
Serial   Phase #: 0 Files: 1     Time: 82s
Serial   Phase #: 1 Files: 5     Time: 67s
Restart  Phase #: 2 Files: 1     Time: 1s
Parallel Phase #: 3 Files: 18    Time: 17s
Restart  Phase #: 4 Files: 1     Time: 0s
Serial   Phase #: 5 Files: 5     Time: 30s
Serial   Phase #: 6 Files: 1     Time: 12s
Serial   Phase #: 7 Files: 4     Time: 11s
Restart  Phase #: 8 Files: 1     Time: 1s
Parallel Phase #: 9 Files: 62    Time: 40s
Restart  Phase #:10 Files: 1     Time: 1s
Serial   Phase #:11 Files: 1     Time: 27s
Restart  Phase #:12 Files: 1     Time: 1s
Parallel Phase #:13 Files: 91    Time: 13s
Restart  Phase #:14 Files: 1     Time: 0s
Parallel Phase #:15 Files: 111   Time: 23s
Restart  Phase #:16 Files: 1     Time: 0s
Serial   Phase #:17 Files: 3     Time: 2s
Restart  Phase #:18 Files: 1     Time: 0s
Parallel Phase #:19 Files: 32    Time: 21s
Restart  Phase #:20 Files: 1     Time: 1s
Serial   Phase #:21 Files: 3     Time: 8s
Restart  Phase #:22 Files: 1     Time: 1s
Parallel Phase #:23 Files: 23    Time: 88s
Restart  Phase #:24 Files: 1     Time: 1s
Parallel Phase #:25 Files: 11    Time: 42s
Restart  Phase #:26 Files: 1     Time: 0s
Serial   Phase #:27 Files: 1     Time: 1s
Restart  Phase #:28 Files: 1     Time: 0s
Serial   Phase #:30 Files: 1     Time: 0s
Serial   Phase #:31 Files: 257   Time: 27s
Serial   Phase #:32 Files: 1     Time: 0s
Restart  Phase #:33 Files: 1     Time: 0s
Serial   Phase #:34 Files: 1     Time: 8s
Restart  Phase #:35 Files: 1     Time: 0s
Restart  Phase #:36 Files: 1     Time: 1s
Serial   Phase #:37 Files: 4     Time: 53s
Restart  Phase #:38 Files: 1     Time: 1s
Parallel Phase #:39 Files: 13    Time: 50s
Restart  Phase #:40 Files: 1     Time: 1s
Parallel Phase #:41 Files: 10    Time: 10s
Restart  Phase #:42 Files: 1     Time: 1s
Serial   Phase #:43 Files: 1     Time: 7s
Restart  Phase #:44 Files: 1     Time: 1s
Serial   Phase #:45 Files: 1     Time: 7s
Serial   Phase #:46 Files: 1     Time: 0s
Restart  Phase #:47 Files: 1     Time: 0s
Serial   Phase #:48 Files: 1     Time: 345s
Restart  Phase #:49 Files: 1     Time: 0s
Serial   Phase #:50 Files: 1     Time: 42s
Restart  Phase #:51 Files: 1     Time: 1s
Serial   Phase #:52 Files: 1     Time: 1s
Restart  Phase #:53 Files: 1     Time: 0s
Serial   Phase #:54 Files: 1     Time: 214s
Restart  Phase #:55 Files: 1     Time: 0s
Serial   Phase #:56 Files: 1     Time: 78s
Restart  Phase #:57 Files: 1     Time: 0s
Serial   Phase #:58 Files: 1     Time: 145s
Restart  Phase #:59 Files: 1     Time: 0s
Serial   Phase #:60 Files: 1     Time: 294s
Restart  Phase #:61 Files: 1     Time: 1s
Serial   Phase #:62 Files: 1     Time: 1s
Restart  Phase #:63 Files: 1     Time: 1s
Serial   Phase #:64 Files: 1     Time: 2s
Serial   Phase #:65 Files: 1 Calling sqlpatch with LD_LIBRARY_PATH=/apps/oracle/12102/rdb/std/lib; export LD_LIBRARY_PATH; LIBPATH=/apps/oracle/12102/rdb/std/lib; export LIBPATH; LD_LIBRARY_PATH_64=/apps/oracle/12102/rdb/std/lib; export LD_LIBRARY_PATH_64; DYLD_LIBRARY_PATH=/apps/oracle/12102/rdb/std/lib; export DYLD_LIBRARY_PATH; /apps/oracle/12102/rdb/std/perl/bin/perl -I /apps/oracle/12102/rdb/std/rdbms/admin -I /apps/oracle/12102/rdb/std/rdbms/admin/../../sqlpatch /apps/oracle/12102/rdb/std/rdbms/admin/../../sqlpatch/sqlpatch.pl -verbose -upgrade_mode_only > /apps/orafra/DB2/migration-12c//catupgrd_datapatch_upgrade.log 2> /apps/orafra/DB2/migration-12c//catupgrd_datapatch_upgrade.err
returned from sqlpatch
    Time: 46s
Serial   Phase #:66 Files: 1     Time: 37s
Serial   Phase #:68 Files: 1     Time: 0s
Serial   Phase #:69 Files: 1 Calling sqlpatch with LD_LIBRARY_PATH=/apps/oracle/12102/rdb/std/lib; export LD_LIBRARY_PATH; LIBPATH=/apps/oracle/12102/rdb/std/lib; export LIBPATH; LD_LIBRARY_PATH_64=/apps/oracle/12102/rdb/std/lib; export LD_LIBRARY_PATH_64; DYLD_LIBRARY_PATH=/apps/oracle/12102/rdb/std/lib; export DYLD_LIBRARY_PATH; /apps/oracle/12102/rdb/std/perl/bin/perl -I /apps/oracle/12102/rdb/std/rdbms/admin -I /apps/oracle/12102/rdb/std/rdbms/admin/../../sqlpatch /apps/oracle/12102/rdb/std/rdbms/admin/../../sqlpatch/sqlpatch.pl -verbose > /apps/orafra/DB2/migration-12c//catupgrd_datapatch_normal.log 2> /apps/orafra/DB2/migration-12c//catupgrd_datapatch_normal.err
returned from sqlpatch
    Time: 48s
Serial   Phase #:70 Files: 1     Time: 13s
Serial   Phase #:71 Files: 1     Time: 1s
Serial   Phase #:72 Files: 1     Time: 0s
Serial   Phase #:73 Files: 1     Time: 19s
Grand Total Time: 1951s




Run the Post-Upgrade Status Tool $ORACLE_HOME/rdbms/admin/utlu121s.sql which provides a summary of
the upgrade at the end of the spool log.
It displays the status of the database components in the upgraded database and the time required to
complete each component upgrade.
Any errors that occur during the upgrade are listed with each component and must be addressed.


$ sqlplus "/as sysdba"
SQL> STARTUP
SQL> @utlu121s.sql








Run catuppst.sql, located in the $ORACLE_HOME/rdbms/admin directory, to perform upgrade actions that
do not require the database to be in UPGRADE mode.

SQL> @catuppst.sql

This script can be run concurrently with utlrp.sql.

Run utlrp.sql to recompile any remaining stored PL/SQL and Java code in another session.

SQL> @utlrp.sql



At this moment, DB2 is migrated to 12c :

Oracle Database 12.1 Post-Upgrade Status Tool           11-07-2015 16:37:11
Component                               Current         Version  Elapsed Time
Name                                    Status          Number   HH:MM:SS
Oracle Server                          UPGRADED      12.1.0.2.0  00:10:57
JServer JAVA Virtual Machine              VALID      12.1.0.2.0  00:05:43
Oracle Workspace Manager                  VALID      12.1.0.2.0  00:01:02
Oracle XDK                                VALID      12.1.0.2.0  00:00:40
Oracle Text                               VALID      12.1.0.2.0  00:01:01
Oracle XML Database                       VALID      12.1.0.2.0  00:02:30
Oracle Database Java Packages             VALID      12.1.0.2.0  00:00:13
Oracle Multimedia                         VALID      12.1.0.2.0  00:02:23
Spatial                                UPGRADED      12.1.0.2.0  00:04:52
Final Actions                                                    00:01:21
Post Upgrade                                                     00:00:09

C. Execute in the NEW environment AFTER upgrade

@/apps/oracle/cfgtoollogs/DB2/preupgrade/postupgrade_fixups.sql


mardi 17 mars 2015

RMAN: backup fails ANU2503E "Backup object already exists on TSM (Doc ID 443900.1)

Problem:


Sending backups to SBT fails with the follwoing error :


RMAN-03009: failure of backup command on ORA_SBT_TAPE_1 channel at 02/19/2015 10:35:07
ORA-19506: failed to create sequential file, name="igpu49hm_1_2", parms=""
ORA-27028: skgfqcre: sbtbackup returned error
ORA-19511: Error received from media manager layer, error text:
ANU2503E Backup object '/adsmorc//igpu49hm_1_2' already exists on TSM Server.
ORA-19600: input file is backup piece (+DGFRA/my_db/backupset/2015_01_31/annnf0_arch_id0_20150131_1807_0.3915.870458935)
ORA-19601: output file is backup piece (igpu49hm_1_2)

 Investigation:


 Based on the metalink note Doc ID 443900.1 :
 The basic problem is that when perform a backup using a disk channel, which does not use TDPO at all.Then allocate a channel with "sbt_tape" and perform a backup of the 'backup recovery area'. The problem is that the name of the backup piece when going to tape will take the same name as the backup piece already on disk.

In this case, this attempted to backup the same backup piece using TDPO twice. This caused the second backup attempt to fail, since this already had an image with the same name.

Since, TDPO does not choose the image name, but rather it's determined and passed by rman. TDPO will not allow duplicate backup images to be created to prevent overwriting an existing backup.

VERITAS is unwavering on allowing a backup_id within the catalog to be overwritten or reused. It will NOT happen. 



Solution:

Use the %t backup format option , so that the TDPO backup_id that is generated is unique for each copy.
so :

 run {
 allocate channel oem_disk_backup device type disk;
 recover copy of database with tag 'ORA$OEM_LEVEL_0';
 backup incremental level 1 cumulative copies=1 for recover of copy with tag 'ORA$OEM_LEVEL_0' database;
 release channel oem_disk_backup;
 allocate channel oem_sbt_backup1 type 'SBT_TAPE' format '"MY_FORMAT"_%d_d%s_p%p_%U_%t.bkp' maxpiecesize 100G parms='ENV=(TDPO_OPTFILE=/usr/tivoli/tsm/client/oracle/bin64/tdpo.opt)';
 backup archivelog all not backed up;
 backup recovery area;
 backup backupset all not backed up since time 'SYSDATE-1';
 }
RUN


Or just to send some backupieces :

{

CONFIGURE CONTROLFILE AUTOBACKUP OFF;

BACKUP DEVICE type SBT backupset 19941,19942,19943,19944,19945,19946,19947,19948,19949,19950,19951,19952,19953,19954,19955,19956,19957,19958,19959,19960,19961,19962,
 19963,19964,19965,19966,19967,19968,19969,19970,19971,19972,19973,19974,19975,19976,19977,19978,19979,19980,19981,19982,19983,19984,19985,19986,19987,19988,19989
format="MY_FORMAT_%U" ;

}

RMAN : ORA-00245: control file backup operation failed

Problem

The RMAN backup of a database in RAC environnement fails with the error: ORA-00245: control file backup operation failed.
 

Solution

What is a snapshot controlfile  ?
A snapshot controlfile is a read consistent copy of a database controlfile which RMAN creates because the controlfile is changed constantly.

The snapshot controlfile must be on a location shared by all RAC nodes in a cluster (it must be accessable by all nodes on which instances for an RAC database can run).
 
 

RMAN> show all;

CONFIGURE SNAPSHOT CONTROLFILE NAME TO '/apps/oracle/11202/rdb/rac/dbs/snapcf_MY_DB.f'; # default
 
 

1 . Find a shared location

for example : +DGDATA/MY_DB/CONTROLFILE/
 
2. Change the location
RMAN> CONFIGURE SNAPSHOT CONTROLFILE NAME TO '+DGDATA/MY_DB/CONTROLFILE/snapcf_MY_DB.f';

RMAN : ORA-01210: data file header is media corrupt

Problem:


Following a restore of a cold backup, we can not open the database (resetlogs) because of the error :
ORA-01210: data file header is media corrupt


ORA-01110: data file 50: '/apps/oracledata/MY_DB/indx0001/arc_event_index_069.dbf'
ORA-01122: database file 50 failed verification check
ORA-01110: data file 50:
'/apps/oracledata/MY_DB/indx0001/arc_event_index_069.dbf'
ORA-01210: data file header is media corrupt




 
 
 

Solution :

 1. Transform the database to archivelog mode to avoid


ORA-01145: offline immediate disallowed unless media recovery enabled

2. Put the datafile in offline mode



SQL> alter database datafile '/apps/oracledata/MY_DB/indx0001/arc_event_index_069.dbf' offline;

Database altered.

 


3. Move the datafile ..


SQL> !mv /apps/oracledata/ARC1EUP0/indx0001/arc_event_index_069.dbf /apps/oracledata/ARC1EUP0/indx0001/arc_event_index_069.dbf.old

 

 

4. Restore the datafile


RMAN> restore datafile 50;
Starting restore at 13-MAR-15
using target database control file instead of recovery catalog
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=82 device type=DISK
allocated channel: ORA_DISK_2
channel ORA_DISK_2: SID=102 device type=DISK
allocated channel: ORA_DISK_3
channel ORA_DISK_3: SID=122 device type=DISK
allocated channel: ORA_DISK_4
channel ORA_DISK_4: SID=142 device type=DISK
channel ORA_DISK_1: starting datafile backup set restore
channel ORA_DISK_1: specifying datafile(s) to restore from backup set
channel ORA_DISK_1: restoring datafile 00050 to /apps/oracledata/ARC1EUP0/indx0001/arc_event_index_069.dbf
channel ORA_DISK_1: reading from backup piece /apps/orafra/MY_DB/backupset/2015_02_20/o1_mf_nnnd0_COLD_I0_20150220_181_bggxzomh_.bkp
channel ORA_DISK_1: piece handle=/apps/orafra/MY_DB/backupset/2015_02_20/o1_mf_nnnd0_COLD_I0_20150220_181_bggxzomh_.bkp tag=COLD_I0_20150220_181
channel ORA_DISK_1: restored backup piece 1
channel ORA_DISK_1: reading from backup piece /apps/orafra/MY_DB/backupset/2015_02_20/o1_mf_nnnd0_COLD_I0_20150220_181_bggyof1t_.bkp
channel ORA_DISK_1: piece handle=/apps/orafra/MY_DB/backupset/2015_02_20/o1_mf_nnnd0_COLD_I0_20150220_181_bggyof1t_.bkp tag=COLD_I0_20150220_181
channel ORA_DISK_1: restored backup piece 2
channel ORA_DISK_1: restore complete, elapsed time: 00:19:50
Finished restore at 13-MAR-15

 

 

 


5. Open the database


SQL> alter database open resetlogs;

Database altered.




 

jeudi 15 mars 2012

Oracle active Data Guard for standby database : RMAN

You can use Oracle active Data Guard to create a physical standby database by using RMAN backups.
For my example, the primary database is STATTAR (host=hots1), and the standby is STATSTDB (host=hots2).
The OS is linux x86_64 and the oracle version is 11.2.0.1.

I. Set up Standby database

1. Ensure that  STATTAR  is in archivelog mode, otherwise convert it.

2. Enable the logging mode
SQL> ALTER DATABASE FORCE LOGGING;

3. do a complete backup of STATTAR
export ORACLE_SID=STATTAR
rman target /
RMAN> backup database plus archivelog;


4. tnsnames
STATSTDB  =
  (DESCRIPTION =
    (ADDRESS = (PROTOCOL = TCP)(HOST = host2)(PORT = 1521))
    (CONNECT_DATA =
      (SERVER = DEDICATED)
      (SERVICE_NAME = STATSTDB)
    )
  )

5. listner (host2)
(SID_DESC =
       (GLOBAL_DBNAME =  STATSTDB )
       (ORACLE_HOME = /u01/app/oracle/product/11.2.0/dbhome_1)
       (SID_NAME      =  STATSTDB )
     )
 
Check with the SQL*Net configuration using the following commands on the Primary AND Standby


from host1 server, check the communication beetween the 2 databases :
tnsping  STATSTDB
tnsping 
STATTAR


6. on host2, create the directories  for data, controlfile and redo log files
 mkdir -p /u01/app/oracle/admin/ STATSTDB /adump
 mkdir -p /u01/app/oracle/admin/ STATSTDB /dpdump
 mkdir -p /u01/app/oracle/admin/ STATSTDB /pfile
 mkdir -p /u01/app/oracle/admin/ STATSTDB /scripts
 mkdir -p /u02/oracle/oradata/ STATSTDB /controlfile/
 mkdir -p /u03/oracle/oradata/ STATSTDB /controlfile/
 mkdir -p /u04/oracle/oradata/ STATSTDB /controlfile/
 mkdir -p /u02/oracle/oradata/ STATSTDB /data_system
 mkdir -p /u02/oracle/oradata/ STATSTDB /data
 mkdir -p /u02/oracle/oradata/ STATSTDB /data
 mkdir -p /u03/oracle/oradata/ STATSTDB /data
 mkdir -p /u04/oracle/oradata/ STATSTDB /data
 mkdir -p /u02/oracle/oradata/ STATSTDB /redo
 mkdir -p /u03/oracle/oradata/ STATSTDB /redo
 mkdir -p /u04/oracle/oradata/ STATSTDB /redo


7. create pfile for standby (host2)
db_name=STATTAR
db_unique_name=STATSTDB
REMOTE_LOGIN_PASSWORDFILE='EXCLUSIVE'
db_block_size=8192
memory_max_target=1500M
memory_target=1500M



8. create pwdfile : the same as the target DB (host2)
orapwd file=/u01/app/oracle/product/11.2.0/dbhome_1/dbs/orapw STATSTDB  password=<syspwd>



9. startup  STATSTDB  in nomount mode
  export ORACLE_SID=STATSTDB
  sqlplus / as sysdba
  SQL> startup nomount pfile='/u01/app/oracle/admin/STATSTDB/pfile/STATSTDB_init.ora';

10. Create stanby redo log on the on primary db STATTAR

SQL> alter database add standby logfile group 4 ('/u02/oracle/oradata/ STATTAR /redostdb.ora') size 50M;


11. Modify the primary initialization parameter for dataguard on primary db STATTAR
 -- primary DB

SQL> alter system set LOG_ARCHIVE_CONFIG='DG_CONFIG=(STATTAR,STATSTDB)';
System altered.

SQL> alter system set LOG_ARCHIVE_DEST_1='LOCATION=/u06/oracle/oradata/STATTAR/archive VALID_FOR=(ALL_LOGFILES,ALL_ROLES) DB_UNIQUE_NAME=STATTAR';
System altered.

SQL> alter system set LOG_ARCHIVE_DEST_2='SERVICE=STATSTDB LGWR ASYNC VALID_FOR=(ONLINE_LOGFILES,PRIMARY_ROLE) DB_UNIQUE_NAME=STATSTDB';
System altered.

SQL> alter system set LOG_ARCHIVE_DEST_STATE_1=ENABLE;
System altered.

SQL> alter system set FAL_SERVER=STATSTDB;
System altered.

SQL> alter system set FAL_CLIENT=STATTAR;
System altered.

SQL> alter system set DB_FILE_NAME_CONVERT= '/u02/oracle/oradata/STATSTDB/redo',
                          '/u02/oracle/oradata/STATTAR/redo',
                          '/u03/oracle/oradata/STATSTDB/redo',
                          '/u03/oracle/oradata/STATTAR/redo',
'/u04/oracle/oradata/STATSTDB/redo',
                          '/u04/oracle/oradata/STATTAR/redo' scope=spfile;
System altered.

SQL> alter system set LOG_FILE_NAME_CONVERT= '/u02/oracle/oradata/STATSTDB/data_system',
                        '/u02/oracle/oradata/STATTAR/data_system',
'/u02/oracle/oradata/STATSTDB/data',
          '/u02/oracle/oradata/STATTAR/data',
'/u03/oracle/oradata/STATSTDB/data',
        '/u03/oracle/oradata/STATTAR/data',
'/u04/oracle/oradata/STATSTDB/data',
          '/u04/oracle/oradata/STATTAR/data' scope=spfile;
System altered.


12. on primary host (host1) invoke RMAN :
 rman target sys/<password>@STATTAR

RMAN>
connect auxiliary sys/<password>@STATSTDB
run {
allocate channel prmy1 type disk;
allocate channel prmy2 type disk;
allocate channel prmy3 type disk;
allocate channel prmy4 type disk;
allocate auxiliary channel stby type disk;

duplicate target database for standby from active database
spfile
  parameter_value_convert 'STATTAR','STATSTDB'
  set db_unique_name='STATSTDB'
  set db_file_name_convert='/STATTAR/','/STATSTDB/'
  set log_file_name_convert='/STATTAR/','/STATSTDB/'
  set control_files='/u02/oracle/oradata/STATSTDB/controlfile/control01.ctl','/u03/oracle/oradata/STATSTDB/controlfile/control02.ctl','/u04/oracle/oradata/STATSTDB/controlfile/control03.ctl'
  set log_archive_max_processes='5'
  set fal_client='STATSTDB'
  set fal_server='STATTAR'
  set standby_file_management='AUTO'
  set log_archive_config='dg_config=(STATTAR,STATSTDB)'
  set log_archive_dest_1='service=STATTAR ASYNC valid_for=(ONLINE_LOGFILE,PRIMARY_ROLE) db_unique_name=STATTAR'
;
}

...

 ''STATMAC'' comment=
 '''' scope=spfile";
   sql clone "alter system set  standby_file_management =
 ''AUTO'' comment=
 '''' scope=spfile";
   sql clone "alter system set  log_archive_config =
 ''dg_config=(STATMAC,STATSTDB)'' comment=
 '''' scope=spfile";
   sql clone "alter system set  log_archive_dest_1 =
 ''service=STATMAC ASYNC valid_for=(ONLINE_LOGFILE,PRIMARY_ROLE) db_unique_name=                                                                                                                                                              STATMAC'' comment=
 '''' scope=spfile";
   shutdown clone immediate;
   startup clone nomount;
}
executing Memory Script

sql statement: alter system set  audit_file_dest =  ''/u01/app/oracle/admin/STAT                                                                                                                                                              STDB/adump'' comment= '''' scope=spfile

sql statement: alter system set  dispatchers =  ''(PROTOCOL=TCP) (SERVICE=STATST                                                                                                                                                              DBXDB)'' comment= '''' scope=spfile

sql statement: alter system set  db_unique_name =  ''STATSTDB'' comment= '''' sc                                                                                                                                                              ope=spfile

sql statement: alter system set  db_file_name_convert =  ''/STATMAC/'', ''/STATS                                                                                                                                                              TDB/'' comment= '''' scope=spfile

sql statement: alter system set  log_file_name_convert =  ''/STATMAC/'', ''/STAT                                                                                                                                                              STDB/'' comment= '''' scope=spfile

sql statement: alter system set  control_files =  ''/u02/oracle/oradata/STATSTDB                                                                                                                                                              /controlfile/control01.ctl'', ''/u03/oracle/oradata/STATSTDB/controlfile/control                                                                                                                                                              02.ctl'', ''/u04/oracle/oradata/STATSTDB/controlfile/control03.ctl'' comment= ''                                                                                                                                                              '' scope=spfile

sql statement: alter system set  log_archive_max_processes =  5 comment= '''' scope=spfile

sql statement: alter system set  fal_client =  ''STATSTDB'' comment= '''' scope=spfile

sql statement: alter system set  fal_server =  ''STATMAC'' comment= '''' scope=spfile

sql statement: alter system set  standby_file_management =  ''AUTO'' comment= ''                                                                                                                                                              '' scope=spfile

sql statement: alter system set  log_archive_config =  ''dg_config=(STATMAC,STAT                                                                                                                                                              STDB)'' comment= '''' scope=spfile

sql statement: alter system set  log_archive_dest_1 =  ''service=STATMAC ASYNC v                                                                                                                                                              alid_for=(ONLINE_LOGFILE,PRIMARY_ROLE) db_unique_name=STATMAC'' comment= '''' sc                                                                                                                                                              ope=spfile

Oracle instance shut down

connected to auxiliary database (not started)
Oracle instance started

Total System Global Area    1570009088 bytes

Fixed Size                     2213696 bytes
Variable Size                905971904 bytes
Database Buffers             637534208 bytes
Redo Buffers                  24289280 bytes
allocated channel: stby
channel stby: SID=63 device type=DISK
....
input datafile copy RECID=156 STAMP=778006506 file name=/u03/oracle/oradata/STATSTDB/data/TBS_FMA_DATA_01.ora
datafile 49 switched to datafile copy
input datafile copy RECID=157 STAMP=778006506 file name=/u03/oracle/oradata/STATSTDB/data/TBS_FMA_DATA_02.ora
Finished Duplicate Db at 15-MAR-12
released channel: prmy1
released channel: prmy2
released channel: prmy3
released channel: prmy4
released channel: stby


exit;

II. Manage Standby database

1. Stop the managed recovery process and open STATSTDB: 
export ORACLE_SID=STATSTDB
  sqlplus / as sysdba
SQL>  select * from v$instance;
INSTANCE_NUMBER INSTANCE_NAME
--------------- ----------------
HOST_NAME
----------------------------------------------------------------
VERSION           STARTUP_T STATUS       PAR    THREAD# ARCHIVE LOG_SWITCH_WAIT
----------------- --------- ------------ --- ---------- ------- ---------------
LOGINS     SHU DATABASE_STATUS   INSTANCE_ROLE      ACTIVE_ST BLO
---------- --- ----------------- ------------------ --------- ---
              1 STATSTDB
pprod_db.local
11.2.0.1.0        15-MAR-12 MOUNTED      NO           1 STARTED
ALLOWED    NO  ACTIVE            PRIMARY_INSTANCE   NORMAL    NO
SQL> alter database recover managed standby database cancel;
Database altered.
SQL> SQL> alter database open;
Database altered.
SQL>

2. Restart the managed recovery process


SQL> alter database recover managed standby database 
             using current logfile disconnect;


3. Test the active data guard:
on the primary database for user SCOTT:

create table my_test (id number);
insert into my_test(id) vlaues (1);
commit;
witth sys user : alter system switch logfile;

on the auxiliary database :
the table my_test is created with one record.









mardi 6 mars 2012

Duplicate Database on the Same Host Using RMAN

You can use RMAN to create a duplicate database on the same server by using RMAN backups.
For my example, the target database is STATTAR, and the duplicate is STATDUP.
The OS is linux x86_64 and the oracle version is 11.2.0.1.

1. Ensure that  STATTAR  is in archivelog mode, otherwise convert it.

2. Enable the logging mode

SQL> ALTER DATABASE FORCE LOGGING;



3. do a complete backup of STATTAR
export ORACLE_SID=STATTAR
rman target /
RMAN> backup database plus archivelog;


4. tnsnames 
STATDUP =
  (DESCRIPTION =
    (ADDRESS = (PROTOCOL = TCP)(HOST = xxxx)(PORT = 1521))
    (CONNECT_DATA =
      (SERVER = DEDICATED)
      (SERVICE_NAME = STATDUP)
    )
  )

5. listner
(SID_DESC =
       (GLOBAL_DBNAME = STATDUP)
       (ORACLE_HOME = /u01/app/oracle/product/11.2.0/dbhome_1)
       (SID_NAME      = STATDUP)
     )
   
6. create the directories  for data, controlfile and redo log files
 mkdir -p /u01/app/oracle/admin/STATDUP/adump
 mkdir -p /u01/app/oracle/admin/STATDUP/dpdump
 mkdir -p /u01/app/oracle/admin/STATDUP/pfile
 mkdir -p /u01/app/oracle/admin/STATDUP/scripts
 mkdir -p /u02/oracle/oradata/STATDUP/controlfile/
 mkdir -p /u03/oracle/oradata/STATDUP/controlfile/
 mkdir -p /u04/oracle/oradata/STATDUP/controlfile/
 mkdir -p /u02/oracle/oradata/STATDUP/data_system
 mkdir -p /u02/oracle/oradata/STATTAR/data
 mkdir -p /u02/oracle/oradata/STATDUP/data
 mkdir -p /u03/oracle/oradata/STATDUP/data
 mkdir -p /u04/oracle/oradata/STATDUP/data
 mkdir -p /u02/oracle/oradata/STATDUP/redo
 mkdir -p /u03/oracle/oradata/STATDUP/redo
 mkdir -p /u04/oracle/oradata/STATDUP/redo



7. create pfile 
db_name=STATDUP
db_block_size=8192
compatible='11.2.0.0.0'
remote_login_passwordfile=exclusive
control_files = ('/u02/oracle/oradata/STATDUP/controlfile/control01.ctl',
                 '/u03/oracle/oradata/STATDUP/controlfile/control01.ctl',
                 '/u04/oracle/oradata/STATDUP/controlfile/control01.ctl')
db_file_name_convert = ('/u02/oracle/oradata/STATTAR/data_system',
                        '/u02/oracle/oradata/STATDUP/data_system',
'/u02/oracle/oradata/STATTAR/data',
         '/u02/oracle/oradata/STATDUP/data',
'/u03/oracle/oradata/STATTAR/data',
         '/u03/oracle/oradata/STATDUP/data',
'/u04/oracle/oradata/STATTAR/data',
         '/u04/oracle/oradata/STATDUP/data'
                        )
log_file_name_convert = ('/u02/oracle/oradata/STATTAR/redo',
                         '/u02/oracle/oradata/STATDUP/redo',
                         '/u03/oracle/oradata/STATTAR/redo',
                         '/u03/oracle/oradata/STATDUP/redo',
'/u04/oracle/oradata/STATTAR/redo',
                         '/u04/oracle/oradata/STATDUP/redo'
)


8. create pwdfile : the same as the target DB
orapwd file=/u01/app/oracle/product/11.2.0/dbhome_1/dbs/orapwSTATDUP password=<syspwd>



9. startup STATDUP in nomount mode
  export ORACLE_SID=STATDUP
  sqlplus / as sysdba
  SQL> startup nomount pfile='/u01/app/oracle/admin/STATDUP/pfile/STATDUP_init.ora';


10. duplicate the target DB
 export ORACLE_SID=STATDUP
 rman target sys/<syspwd>@STATTAR auxiliary/

Recovery Manager: Release 11.2.0.1.0 - Production on Tue Mar 6 10:46:38 2012
Copyright (c) 1982, 2009, Oracle and/or its affiliates.  All rights reserved.
connected to target database: STATTAR (DBID=2026*****)
connected to auxiliary database: STATDUP (not mounted)

RMAN > duplicate target database to STATDUP;

Starting Duplicate Db at 06-MAR-12
using target database control file instead of recovery catalog
allocated channel: ORA_AUX_DISK_1
channel ORA_AUX_DISK_1: SID=57 device type=DISK

contents of Memory Script:
{
   sql clone "create spfile from memory";
}
executing Memory Script

sql statement: create spfile from memory

contents of Memory Script:
{
   shutdown clone immediate;
   startup clone nomount;
}
executing Memory Script

Oracle instance shut down

connected to auxiliary database (not started)
Oracle instance started

Total System Global Area     233861120 bytes

Fixed Size                     2212088 bytes
Variable Size                159387400 bytes
Database Buffers              67108864 bytes
Redo Buffers                   5152768 bytes

contents of Memory Script:
{
   sql clone "alter system set  db_name =
 ''STATTAR'' comment=
 ''Modified by RMAN duplicate'' scope=spfile";
   sql clone "alter system set  db_unique_name =
 ''STATDUP'' comment=
 ''Modified by RMAN duplicate'' scope=spfile";
   shutdown clone immediate;
   startup clone force nomount
   restore clone primary controlfile;
   alter clone database mount;
}
executing Memory Script

sql statement: alter system set  db_name =  ''STATTAR'' comment= ''Modified by RMAN duplicate'' scope=spfile

sql statement: alter system set  db_unique_name =  ''STATDUP'' comment= ''Modified by RMAN duplicate'' scope=spfile

.....

contents of Memory Script:
{
   Alter clone database open resetlogs;
}
executing Memory Script

database opened
Finished Duplicate Db at 06-MAR-12


exit;