Oracle Dataguard - Configuring Physical Standby
Step 1 : To Check the primary database datafiles and logfiles location Primary : SQL> select name from v$datafile; NAME ------------------------------------------------ /u01/app/oracle/oradata/tesprim/system01.dbf /u01/app/oracle/oradata/tesprim/sysaux01.dbf /u01/app/oracle/oradata/tesprim/undotbs01.dbf /u01/app/oracle/oradata/tesprim/users01.dbf SQL> select member from v$logfile; MEMBER ------------------------------------------------- /u01/app/oracle/oradata/tesprim/redo03.log /u01/app/oracle/oradata/tesprim/redo02.log /u01/app/oracle/oradata/tesprim/redo01.log SQL> show parameter spfile NAME TYPE VALUE ------------------------------------ ----------- ------------------ spfile string /u01/app/oracle/product/12.2.0 /dbhome_1/dbs/spfiletesprim.or AStep 2 : Check the database name, mode SQL> select name,open_mode, database_role, db_unique_name from v$database; NAME OPEN_MODE DATABASE_ROLE DB_UNIQUE_NAME --------- -------------------- ---------------- -------------- TESPRIM READ WRITE PRIMARY tesprimStep 3 : Check the datafile size SQL> select sum(bytes/1024/1024/1024) as GB from dba_data_files; GB ---------- 1.34765625Step 4 : Add standby log file v SQL> alter database add standby logfile group 4 '/u01/app/oracle/oradata/tesprim/redo04.log' size 20m; Database altered. SQL> alter database add standby logfile group 5 '/u01/app/oracle/oradata/tesprim/redo05.log' size 20m; Database altered. SQL> alter database add standby logfile group 6 '/u01/app/oracle/oradata/tesprim/redo06.log' size 20m; Database altered.Step 5 : Set the below parameters SQL> alter system set db_unique_name='tesprim' scope=spfile; System altered. SQL> alter system set log_archive_config='dg_config=(tesprim, stand)' scope=spfile; System altered. SQL> alter system set log_archive_dest_1='location=/u01/app/oracle/oradata/ valid_for=(all_logfiles, all_roles) db_unique_name=tesprim' scope=spfile; System altered. SQL> SQL> alter system set log_archive_dest_2='service=stand async valid_for= (online_logfiles, primary_role) db_unique_name=stand' scope=spfile; System altered. SQL> alter system set fal_client='tesprim' scope=spfile; System altered. SQL> alter system set fal_server='stand' scope=spfile; System altered. SQL> alter system set standby_file_management='AUTO' scope=spfile; SQL> System altered. SQL> SQL> SQL> alter system set db_file_name_convert= '/home/oracle/stand/oradata/data', '/u01/app/oracle/oradata/tesprim/' scope=spfile; System altered. SQL> alter system set log_file_name_convert= ' /home/oracle/stand/oradata/log', '/u01/app/oracle/oradata/tesprim/' scope=spfile; System altered.Step 6 : To create structure for standby database [oracle@tesdb ~]$ mkdir stand [oracle@tesdb ~]$ cd stand/ [oracle@tesdb stand]$ mkdir admin oradata [oracle@tesdb stand]$ cd admin/ [oracle@tesdb admin]$ mkdir pfile diag adump [oracle@tesdb admin]$ cd .. [oracle@tesdb stand]$ cd oradata/ [oracle@tesdb oradata]$ mkdir log control data archiveStep 7 : Create entry in listener and tnsname(primary and standby database) [oracle@tesdb ~]$ cd $ORACLE_HOME [oracle@tesdb dbhome_1]$ cd network/admin/ [oracle@tesdb admin]$ vi listener.ora LISTENER = (DESCRIPTION_LIST = (DESCRIPTION = (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.1.16)(PORT = 1521)) (ADDRESS = (PROTOCOL = IPC)(KEY = EXTPROC1521)) ) ) SID_LIST_LISTENER = (SID_LIST = (SID_DESC = (SID_NAME = tesprim) (ORACLE_HOME = /u01/app/oracle/product/12.2.0/dbhome_1/) ) (SID_DESC = (SID_NAME = stand) (ORACLE_HOME = /u01/app/oracle/product/12.2.0/dbhome_1/) ) ) [[oracle@tesdb admin]$ vi tnsnames.ora TESPRIM = (DESCRIPTION = (ADDRESS_LIST = (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.1.16)(PORT = 1521)) ) (CONNECT_DATA = (SERVICE_NAME = tesprim) ) ) STAND = (DESCRIPTION = (ADDRESS_LIST = (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.1.16)(PORT = 1521)) ) (CONNECT_DATA = (SERVICE_NAME = stand) ) )Step 8 : Start the listener and tnsping check both primary and standby [oracle@tesdb admin]$ lsnrctl start LSNRCTL for Linux: Version 12.2.0.1.0 - Production on 30-OCT-2023 16:05:07 Copyright (c) 1991, 2016, Oracle. All rights reserved. Starting /u01/app/oracle/product/12.2.0/dbhome_1//bin/tnslsnr: please wait... TNSLSNR for Linux: Version 12.2.0.1.0 - Production System parameter file is /u01/app/oracle/product/12.2.0/ dbhome_1/network/admin/listener.ora Log messages written to /u01/app/oracle/diag/tnslsnr/tesdb/ listener/alert/log.xml Listening on: (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=192.168.1.16) (PORT=1521))) Listening on: (DESCRIPTION=(ADDRESS=(PROTOCOL=ipc)(KEY=EXTPROC1521))) Connecting to (DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=192.168.1.16) (PORT=1521))) STATUS of the LISTENER ------------------------ Alias LISTENER Version TNSLSNR for Linux: Version 12.2.0.1.0 - Production Start Date 30-OCT-2023 16:05:07 Uptime 0 days 0 hr. 0 min. 0 sec Trace Level off Security ON: Local OS Authentication SNMP OFF Listener Parameter File /u01/app/oracle/product/12.2.0/ dbhome_1/network/admin/listener.ora Listener Log File /u01/app/oracle/diag/tnslsnr/tesdb/ listener/alert/log.xml Listening Endpoints Summary... (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=192.168.1.16)(PORT=1521))) (DESCRIPTION=(ADDRESS=(PROTOCOL=ipc)(KEY=EXTPROC1521))) Services Summary... Service "stand" has 1 instance(s). Instance "stand", status UNKNOWN, has 1 handler(s) for this service... Service "tesprim" has 1 instance(s). Instance "tesprim", status UNKNOWN, has 1 handler(s) for this service... The command completed successfully [oracle@tesdb admin]$ tnsping stand 5 TNS Ping Utility for Linux: Version 12.2.0.1.0 - Production on 30-OCT-2023 16:05:40 Copyright (c) 1997, 2016, Oracle. All rights reserved. Used parameter files: Used TNSNAMES adapter to resolve the alias Attempting to contact (DESCRIPTION = (ADDRESS_LIST = (ADDRESS = (PROTOCOL = TCP) (HOST = 192.168.1.16)(PORT = 1521))) (CONNECT_DATA = (SERVICE_NAME = stand))) OK (10 msec) OK (0 msec) OK (0 msec) OK (0 msec) OK (0 msec) [oracle@tesdb admin]$ tnsping tesprim 5 TNS Ping Utility for Linux: Version 12.2.0.1.0 - Production on 30-OCT-2023 16:05:48 Copyright (c) 1997, 2016, Oracle. All rights reserved. Used parameter files: Used TNSNAMES adapter to resolve the alias Attempting to contact (DESCRIPTION = (ADDRESS_LIST = (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.1.16)(PORT = 1521))) (CONNECT_DATA = (SERVICE_NAME = tesprim))) OK (0 msec) OK (0 msec) OK (0 msec) OK (0 msec) OK (10 msec)Step 9 : Create orapwd in primary and standby [oracle@tesdb ~]$ cd $ORACLE_HOME/dbs [oracle@tesdb dbs]$ ll total 1276636 -rw-r-----. 1 oracle oinstall 1079074816 Oct 28 12:38 012a29mp_1_1 -rw-r-----. 1 oracle oinstall 181369856 Oct 30 11:30 arch1_2_1151400700.dbf -rw-r-----. 1 oracle oinstall 14884864 Oct 30 15:52 arch1_3_1151400700.dbf -rw-r-----. 1 oracle oinstall 10698752 Oct 28 12:38 c-449484857-20231028-00 -rw-rw----. 1 oracle oinstall 1544 Oct 30 15:11 hc_dev.dat -rw-rw----. 1 oracle oinstall 1544 Oct 30 15:52 hc_tesprim.dat -rw-r--r--. 1 oracle oinstall 3079 May 15 2015 init.ora -rw-r-----. 1 oracle oinstall 24 Mar 2 2022 lkDEV -rw-r-----. 1 oracle oinstall 24 Oct 28 09:27 lkTESPRIM -rw-r-----. 1 oracle oinstall 3584 Mar 2 2022 orapwdev -rw-r-----. 1 oracle oinstall 3584 Oct 28 09:33 orapwtesprim -rw-r-----. 1 oracle oinstall 10600448 Oct 30 15:11 snapcf_dev.f -rw-r-----. 1 oracle oinstall 10600448 Oct 28 12:38 snapcf_tesprim.f -rw-r-----. 1 oracle oinstall 3584 Oct 30 15:11 spfiledev.ora -rw-r-----. 1 oracle oinstall 4608 Oct 30 16:13 spfiletesprim.ora [oracle@tesdb dbs]$ orapwd file=orapwtesprim password=abcd#123 force=y; [oracle@tesdb dbs]$ orapwd file=orapwstand password=abcd#123Step 10 : Create pfile in my location standby [oracle@tesdb pfile]$ cd /home/oracle/stand/admin/pfile [oracle@tesdb pfile]$ vi initstand.ora db_name=stand [oracle@tesdb fast_recovery_area]$ export ORACLE_SID=stand [oracle@tesdb fast_recovery_area]$ sqlplus / as sysdba SQL*Plus: Release 12.2.0.1.0 Production on Mon Oct 30 16:27:14 2023 Copyright (c) 1982, 2016, Oracle. All rights reserved. Connected to an idle instance.Step 11 : Start the database in nomount stage SQL> startup nomount pfile='/home/oracle/stand/admin/pfile/initstand.ora' ORACLE instance started. Total System Global Area 268435456 bytes Fixed Size 8619496 bytes Variable Size 201329176 bytes Database Buffers 50331648 bytes Redo Buffers 8155136 bytesStep 12 : Start the primary database [oracle@tesdb ~]$ export ORACLE_SID=tesprimStep 13 : Connect to RMAN [oracle@tesdb ~]$ rman target sys/abcd#123@tesprim auxiliary sys/abcd#123@stand Recovery Manager: Release 12.2.0.1.0 - Production on Mon Oct 30 16:32:17 2023 Copyright (c) 1982, 2017, Oracle and/or its affiliates. All rights reserved. connected to target database: TESPRIM (DBID=449484857) connected to auxiliary database: STAND (not mounted) RMAN> run { allocate channel p1 type disk; allocate channel p2 type disk; allocate channel p3 type disk; allocate channel p4 type disk; allocate auxiliary channel s1 type disk; duplicate target database for standby from active database spfile parameter_value_convert 'tesprim','stand' set db_name='tesprim' set db_unique_name='stand' set db_file_name_convert='/u01/app/oracle/oradata/tesprim/', '/home/oracle/stand/oradata/data' set log_file_name_convert='/u01/app/oracle/oradata/dev/', '/home/oracle/stand/oradata/log' set control_files='/home/oracle/stand/oradata/control/ standby1.ctl' set log_archive_max_processes='5' set fal_client='stand' set fal_server='tesprim' set standby_file_management='AUTO' set log_archive_config='dg_config=(tesprim,stand)' nofilenamecheck; }2> 3> 4> 5> 6> 7> 8> 9> 10> 11> 12> 13> 14> 15> 16> 17> 18> 19> 20> 21> 22> using target database control file instead of recovery catalog allocated channel: p1 channel p1: SID=266 device type=DISK allocated channel: p2 channel p2: SID=39 device type=DISK allocated channel: p3 channel p3: SID=269 device type=DISK allocated channel: p4 channel p4: SID=40 device type=DISK allocated channel: s1 channel s1: SID=20 device type=DISK Starting Duplicate Db at 30-OCT-23 contents of Memory Script: { backup as copy reuse targetfile '/u01/app/oracle/product/12.2.0/dbhome_1/dbs/ orapwtesprim' auxiliary format '/u01/app/oracle/product/12.2.0/dbhome_1/dbs/ orapwstand' targetfile '/u01/app/oracle/product/12.2.0/dbhome_1/dbs/ spfiletesprim.ora' auxiliary format '/u01/app/oracle/product/12.2.0/dbhome_1/dbs/ spfilestand.ora' ; sql clone "alter system set spfile= '' /u01/app/oracle/product/12.2.0/dbhome_1/dbs/spfilestand.ora''"; } executing Memory Script Starting backup at 30-OCT-23 Finished backup at 30-OCT-23 sql statement: alter system set spfile= '' /u01/app/oracle/product/12.2.0/dbhome_1/dbs/spfilestand.ora'' contents of Memory Script: { sql clone "alter system set audit_file_dest = ''/u01/app/oracle/admin/stand/adump'' comment= '''' scope=spfile"; sql clone "alter system set dispatchers = ''(PROTOCOL=TCP) (SERVICE=standXDB)'' comment= '''' scope=spfile"; sql clone "alter system set log_archive_dest_1 = ''location=/u01/app/oracle/oradata/ valid_for=(all_logfiles, all_roles) db_unique_name=stand'' comment= '''' scope=spfile"; sql clone "alter system set db_name = ''tesprim'' comment= '''' scope=spfile"; sql clone "alter system set db_unique_name = ''stand'' comment= '''' scope=spfile"; sql clone "alter system set db_file_name_convert = ''/u01/app/oracle/oradata/tesprim/'', ''/home/oracle/stand/oradata/data'' comment= '''' scope=spfile"; sql clone "alter system set log_file_name_convert = ''/u01/app/oracle/oradata/dev/'', ''/home/oracle/stand/oradata/log'' comment= '''' scope=spfile"; sql clone "alter system set control_files = ''/home/oracle/stand/oradata/control/standby1.ctl'' comment='''' scope=spfile"; sql clone "alter system set log_archive_max_processes = 5 comment= '''' scope=spfile"; sql clone "alter system set fal_client = ''stand'' comment= '''' scope=spfile"; sql clone "alter system set fal_server = ''tesprim'' 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=(tesprim,stand)'' comment= '''' scope=spfile"; shutdown clone immediate; startup clone nomount; } executing Memory Script sql statement: alter system set audit_file_dest = ''/u01/app/oracle/admin/stand/adump'' comment= '''' scope=spfile sql statement: alter system set dispatchers = ''(PROTOCOL=TCP) (SERVICE=standXDB)'' comment= '''' scope=spfile sql statement: alter system set log_archive_dest_1 = ''location=/u01/app/oracle/oradata/ valid_for=(all_logfiles, all_roles) db_unique_name=stand'' comment= '''' scope=spfile sql statement: alter system set db_name = ''tesprim'' comment= '''' scope=spfile sql statement: alter system set db_unique_name = ''stand'' comment= '''' scope=spfile sql statement: alter system set db_file_name_convert = ''/u01/app/oracle/oradata/tesprim/'', ''/home/oracle/stand/oradata/data'' comment= '''' scope=spfile sql statement: alter system set log_file_name_convert = ''/u01/app/oracle/oradata/dev/'', ''/home/oracle/stand/oradata/log'' comment= '''' scope=spfile sql statement: alter system set control_files = ''/home/oracle/stand/oradata/control/standby1.ctl'' comment= '''' scope=spfile sql statement: alter system set log_archive_max_processes = 5 comment= '''' scope=spfile sql statement: alter system set fal_client = ''stand'' comment= '''' scope=spfile sql statement: alter system set fal_server = ''tesprim'' 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=(tesprim,stand)'' comment= '''' scope=spfile Oracle instance shut down connected to auxiliary database (not started) Oracle instance started Total System Global Area 532676608 bytes Fixed Size 8622720 bytes Variable Size 297799040 bytes Database Buffers 218103808 bytes Redo Buffers 8151040 bytes allocated channel: s1 channel s1: SID=255 device type=DISK contents of Memory Script: { backup as copy current controlfile for standby auxiliary format '/home/oracle/stand/oradata/control/standby1.ctl'; } executing Memory Script Starting backup at 30-OCT-23 channel p1: starting datafile copy copying standby control file output file name=/u01/app/oracle/product/12.2.0/ dbhome_1/dbs/snapcf_tesprim.f tag=TAG20231030T163620 channel p1: datafile copy complete, elapsed time: 00:00:02 Finished backup at 30-OCT-23 contents of Memory Script: { sql clone 'alter database mount standby database'; } executing Memory Script sql statement: alter database mount standby database contents of Memory Script: { set newname for tempfile 1 to "/home/oracle/stand/oradata/datatemp01.dbf"; switch clone tempfile all; set newname for datafile 1 to "/home/oracle/stand/oradata/datasystem01.dbf"; set newname for datafile 3 to "/home/oracle/stand/oradata/datasysaux01.dbf"; set newname for datafile 4 to "/home/oracle/stand/oradata/dataundotbs01.dbf"; set newname for datafile 7 to "/home/oracle/stand/oradata/datausers01.dbf"; backup as copy reuse datafile 1 auxiliary format "/home/oracle/stand/oradata/datasystem01.dbf" datafile 3 auxiliary format "/home/oracle/stand/oradata/datasysaux01.dbf" datafile 4 auxiliary format "/home/oracle/stand/oradata/dataundotbs01.dbf" datafile 7 auxiliary format "/home/oracle/stand/oradata/datausers01.dbf" ; sql 'alter system archive log current'; } executing Memory Script executing command: SET NEWNAME renamed tempfile 1 to /home/oracle/stand/oradata/ datatemp01.dbf in control file executing command: SET NEWNAME executing command: SET NEWNAME executing command: SET NEWNAME executing command: SET NEWNAME Starting backup at 30-OCT-23 channel p1: starting datafile copy input datafile file number=00001 name=/u01/app/oracle/ oradata/tesprim/system01.dbf channel p2: starting datafile copy input datafile file number=00003 name=/u01/app/oracle/ oradata/tesprim/sysaux01.dbf channel p3: starting datafile copy input datafile file number=00004 name=/u01/app/oracle/ oradata/tesprim/undotbs01.dbf channel p4: starting datafile copy input datafile file number=00007 name=/u01/app/oracle/ oradata/tesprim/users01.dbf output file name=/home/oracle/stand/ oradata/datausers01.dbf tag=TAG20231030T163627 channel p4: datafile copy complete, elapsed time: 00:00:10 output file name=/home/oracle/stand/ oradata/dataundotbs01.dbf tag=TAG20231030T163627 channel p3: datafile copy complete, elapsed time: 00:00:15 output file name=/home/oracle/stand/ oradata/datasysaux01.dbf tag=TAG20231030T163627 channel p2: datafile copy complete, elapsed time: 00:00:16 output file name=/home/oracle/stand/ oradata/datasystem01.dbf tag=TAG20231030T163627 channel p1: datafile copy complete, elapsed time: 00:00:23 Finished backup at 30-OCT-23 sql statement: alter system archive log current contents of Memory Script: { switch clone datafile all; } executing Memory Script datafile 1 switched to datafile copy input datafile copy RECID=1 STAMP=1151599011 file name=/home/oracle/stand/oradata/datasystem01.dbf datafile 3 switched to datafile copy input datafile copy RECID=2 STAMP=1151599011 file name=/home/oracle/stand/oradata/datasysaux01.dbf datafile 4 switched to datafile copy input datafile copy RECID=3 STAMP=1151599011 file name=/home/oracle/stand/oradata/dataundotbs01.dbf datafile 7 switched to datafile copy input datafile copy RECID=4 STAMP=1151599011 file name=/home/oracle/stand/oradata/datausers01.dbf Finished Duplicate Db at 30-OCT-23 released channel: p1 released channel: p2 released channel: p3 released channel: p4 released channel: s1Step 14 : Startup the primary database and the check archive log sequence export ORACLE_SID=tesprim sqlplus / as sysdba SQL*Plus: Release 12.2.0.1.0 Production on Sat Nov 23 11:43:35 2019 Copyright (c) 1982, 2016, Oracle. All rights reserved. Connected to: Oracle Database 12c Enterprise Edition Release 12.2.0.1.0 - 64bit Production SQL> archive log list Database log mode Archive Mode Automatic archival Enabled Archive destination /u01/app/oracle/product/ 12.2.0/dbhome_1/dbs/arch Oldest online log sequence 3 Next log sequence to archive 5 Current log sequence 5 SQL> conn / as sysdba Connected.Step 15 : Check standby databse SQL> select DB_UNIQUE_NAME, name , open_mode from v$database; DB_UNIQUE_NAME NAME OPEN_MODE ------------------------------ --------- ----------- stand TESPRIM MOUNTED SQL> archive log list Database log mode Archive Mode Automatic archival Enabled Archive destination /u01/app/oracle/oradata/ Oldest online log sequence 0 Next log sequence to archive 0 Current log sequence 0STEP 16 : Create spfile in pfile for standby database and start database SQL> create spfile from pfile= '/home/oracle/stand/admin/pfile/initstand.ora'; File created. SQL> startup force mount; ORACLE instance started. Total System Global Area 1560281088 bytes Fixed Size 8621088 bytes Variable Size 385876960 bytes Database Buffers 1157627904 bytes Redo Buffers 8155136 bytes Database mounted. SQL> archive log list Database log mode Archive Mode Automatic archival Enabled Archive destination /home/oracle/stand/oradata/archive/ Oldest online log sequence 0 Next log sequence to archive 0 Current log sequence 0Step 17 : Check the sequence in standby database for mount stange select SEQUENCE#,APPLIED from v$archived_log; SEQUENCE# APPLIED ---------- --------- 16 NO 15 NO 17 NOStep 18 : Apply the MRP from standby database SQL> recover managed standby database disconnect from session; Media recovery complete.Step 19 : Check the sequence in standby database SQL> select SEQUENCE#,APPLIED from v$archived_log; SEQUENCE# APPLIED ---------- --------- 16 YES 15 YES 17 YESStep 20 : Find name, mode of database SQL> select name,open_mode,db_unique_name from v$database; NAME OPEN_MODE DB_UNIQUE_NAME --------- -------------------- --------------- TESPRIM MOUNTED stand SQL> select protection_mode from v$database; PROTECTION_MODE -------------------- MAXIMUM PERFORMANCEStep 21 : To cancel the MRP from standby database SQL> recover managed standby database cancel; Media recovery complete. « Previous Next Topic » (Oracle Dataguard - Configuring Logical Standby) |