This time around, we'll do a switchover and switchback exercise using Oracle dataguard broker. If you need help on setting up the broker, refer my previous post How to setup DGMGRL, broker with example.
Before we start, remember that DG broker does not have the ability to create standby and is used for managing the dataguard configuration. Before proceeding with step-by-step instructions on how to set up DG broker, I would recommend you to get comfortable with the concepts first.
Physical Standby Concepts
DataGuard Broker Concepts
The following configuration was tested on RHEL4U2 64-bit with Oracle 10.1.0.5 database. I used 2-node RAC as the primary and single instance database as the standby for this test.
Pri db_unique_name = 'TESTPRI'
DG db_unique_name = 'TESTDG'
Configuration(any name) = 'DG_TEST'
sys password = 'sys'
Pri conn stg = 'TESTPRI'
Most of the times, switchover using broker fails because the configuration is not set correctly. So to avoid later troubleshooting, let us do a quick sanity check first. Ensure following parameters are set correctly on all instances of primary and standby
1. Ensure SPFILE is used
SQL> sho parameter spfile
2. Verify dmon process is running and broker parameters viz. DG_BROKER_START is set to TRUE and DG_BROKER_CONFIG_FILEn are set correctly
SQL> sho parameter broker
$ps -ef|grep dmon|grep -v grep
3. Check if LOCAL_LISTENER is set(This is needed only if you are non-default port other than 1521)
DGMGRL> show instance 'TESTPRIR1' 'LocalListenerAddress';
4. Verify if GLOBAL_DBNAME in listener.ora is set correctly to <<db_unique_name>>_DGMGRL.<<db_domain>>
Example listener.ora:
SID_LIST_LISTENER_TESTPRIR1 =
(SID_LIST =
(SID_DESC =
(SID_NAME = PLSExtProc)
(ORACLE_HOME = /apps/oracle/product/10g/db)
(PROGRAM = extproc)
)
(SID_DESC =
(SID_NAME = TESTPRIR1)
(GLOBAL_DBNAME = TESTPRI_DGMGRL)
(ORACLE_HOME = /apps/oracle/product/10g/db)
)
)
Note: In the above case, db_domain was null.
5. Verify if START_OPTIONS is set to MOUNT in the OCR
$ srvctl config database -d TESTPRI -a
testprir1 TESTPRIR1 /apps/oracle/product/10g/db
testprir2 TESTPRIR2 /apps/oracle/product/10g/db
DB_NAME: null
ORACLE_HOME: /apps/oracle/product/10g/db
SPFILE: /n01/oradata/TESTPRI/spfileTESTPRI.ora
DOMAIN: null
DB_ROLE: PRIMARY
START_OPTIONS: MOUNT
6. Broker configuration is enabled and state of all members as intended is ONLINE
DGMGRL> show configuration
7. remote_login_passwordfile is set to 'EXCLUSIVE'
SQL> sho parameter remote_login_passwordfile
8. Verify TESTPRI and TESTDG tnspingable from both primary as well as standby and can connect to each other.
Let us do the actual switchover now. Since our primary database is RAC, let us also keep a watch on how the OCR status is changing
9. Ensure <<db_unique_name>>_DGMGRL is part of service names otherwise post switchover, instances may have to be manually started
OCR Config before switchover:
[oracle@testprir1]/apps/oracle/product/10g/db/dbs% srvctl status database -d TESTPRI
Instance TESTPRIR1 is running on node testprir1
Instance TESTPRIR2 is running on node testprir2
[oracle@testprir1]/apps/oracle/product/10g/db/dbs% srvctl config database -d TESTPRI -a
testprir1 TESTPRIR1 /apps/oracle/product/10g/db
testprir2 TESTPRIR2 /apps/oracle/product/10g/db
DB_NAME: null
ORACLE_HOME: /apps/oracle/product/10g/db
SPFILE: /n01/oradata/TESTPRI/spfileTESTPRI.ora
DOMAIN: null
DB_ROLE: PRIMARY
START_OPTIONS: MOUNT
Broker config before switchover:
DGMGRL> show configuration;
Configuration
Name: DG_TEST
Enabled: YES
Protection Mode: MaxPerformance
Databases:
TESTPRI - Primary database
TESTDG - Physical standby database
Current status for "DG_TEST":
SUCCESS
Switchover Now:
DGMGRL> switchover to 'TESTDG';
Performing switchover NOW. Please wait...
Operation requires shutdown of instance "TESTPRIR1" on database "TESTPRI".
Shutting down instance "TESTPRIR1"...
ORA-01109: database not open
Database dismounted.
ORACLE instance shut down.
Operation requires shutdown of instance "TESTPRI" on database "TESTDG".
Shutting down instance "TESTPRI"...
ORA-01109: database not open
Database dismounted.
ORACLE instance shut down.
Operation requires startup of instance "TESTPRIR1" on database "TESTPRI".
Starting instance "TESTPRIR1"...
ORACLE instance started.
Database mounted.
Operation requires startup of instance "TESTPRI" on database "TESTDG".
Starting instance "TESTPRI"...
ORACLE instance started.
Database mounted.
Switchover succeeded. New primary is "TESTDG"
DGMGRL> exit
OCR after switchover:
[oracle@testprir1]/apps/oracle/product/10g/db/dbs% srvctl config database -d TESTPRI -a
testprir1 TESTPRIR1 /apps/oracle/product/10g/db
testprir2 TESTPRIR2 /apps/oracle/product/10g/db
DB_NAME: null
ORACLE_HOME: /apps/oracle/product/10g/db
SPFILE: /n01/oradata/TESTPRI/spfileTESTPRI.ora
DOMAIN: null
DB_ROLE: PHYSICAL_STANDBY
START_OPTIONS: MOUNT
[oracle@testprir1]/apps/oracle/product/10g/db/dbs% srvctl status database -d TESTPRI
Instance TESTPRIR1 is running on node testprir1
Instance TESTPRIR2 is running on node testprir2
Broker config post switchover:
DGMGRL> show configuration;
Configuration
Name: DG_TEST
Enabled: YES
Protection Mode: MaxPerformance
Databases:
TESTPRI - Physical standby database
TESTDG - Primary database
Current status for "DG_TEST":
SUCCESS
Switchback Now:
DGMGRL> connect sys/sys@TESTDG
Connected.
DGMGRL> switchover to 'TESTPRI';
Performing switchover NOW. Please wait...
Operation requires shutdown of instance "TESTPRI" on database "TESTDG".
Shutting down instance "TESTPRI"...
ORA-01109: database not open
Database dismounted.
ORACLE instance shut down.
Operation requires shutdown of instance "TESTPRIR1" on database "TESTPRI".
Shutting down instance "TESTPRIR1"...
ORA-01109: database not open
Database dismounted.
ORACLE instance shut down.
Operation requires startup of instance "TESTPRI" on database "TESTDG".
Starting instance "TESTPRI"...
ORACLE instance started.
Database mounted.
Operation requires startup of instance "TESTPRIR1" on database "TESTPRI".
Starting instance "TESTPRIR1"...
ORACLE instance started.
Database mounted.
Switchover succeeded. New primary is "TESTPRI"
DGMGRL> exit
Back to original config:
[oracle@testprir1]/apps/oracle/product/10g/db/dbs% srvctl status database -d TESTPRI
Instance TESTPRIR1 is running on node testprir1
Instance TESTPRIR2 is running on node testprir2
[oracle@testprir1]/apps/oracle/product/10g/db/dbs% srvctl config database -d TESTPRI -a
testprir1 TESTPRIR1 /apps/oracle/product/10g/db
testprir2 TESTPRIR2 /apps/oracle/product/10g/db
DB_NAME: null
ORACLE_HOME: /apps/oracle/product/10g/db
SPFILE: /n01/oradata/TESTPRI/spfileTESTPRI.ora
DOMAIN: null
DB_ROLE: PRIMARY
START_OPTIONS: MOUNT
Troubleshooting Tips:
1. Remember to create TEMP files on DG(new primary) after switchover
2. Give sys passsword explicitly as time of connecting using DGMGRL for switchover else it fails. Let us take an example where sys password was not given.
DGMGRL> connect /
Connected.
DGMGRL> switchover to 'TESTDG';
Performing switchover NOW. Please wait...
Operation requires shutdown of instance "TESTPRIR1" on database "TESTPRI".
Shutting down instance "TESTPRIR1"...
ORA-01017: invalid username/password; logon denied
You are no longer connected to ORACLE
Please connect again.
Unable to shut down instance "TESTPRIR1".
You must shut down instance "TESTPRIR1" manually.
Operation requires shutdown of instance "TESTPRI" on database "TESTDG".
You must shut down instance "TESTPRI" manually.
Operation requires startup of instance "TESTPRIR1" on database "TESTPRI".
You must start instance "TESTPRIR1" manually.
Operation requires startup of instance "TESTPRI" on database "TESTDG".
You must start instance "TESTPRI" manually.
Switchover succeeded. New primary is "TESTDG"
Fix:
Just manually stop and start the instances. Switchover of role reversal is already done.
3. Before executing the switchover you may reduce the number of ARCH processes to the minimum needed for both remote and local archiving. Additional ARCH processes can take additional time to shutdown thereby increasing overall switchover timings. Once the switchover has been completed you can reenable the additional ARCH processes.'log_archive_max_processes' is the parameter in question here.
This is it. So we saw how easy it was to switchover/switchback using Oracle Dataguard broker. If the configuration is set correctly, it's very easy to manage.