Documente Academic
Documente Profesional
Documente Cultură
1. Verify the standby database and make sure standby database is in sync with primary database.
2. Tail the alert log on both primary and standby to monitor the database during the entire switch
over time. Use this command : tail -f alert_$ORACLE_SID.log
3. Make sure below data guard parameters(log_archive_dest, log_archive_dest_state,
log_archive_config, fal_client, fal_server etc) are correctly configured on standby site. This would help log
shipping go smooth after the switch over.
Let application team bring the application down. Now DBA start switching over the database!
Step 2 Database Active Connection Verification
Make sure, no application connection on the database.
select count(*),username from v$session group by v$session
To be safer side, run the below script to kill any non local process to complete our switch over
smoothly.
tokill=`ps -ef | grep LOCAL=NO | grep -v grep | awk '{print $2}'`; echo $tokill;
tokill=`ps -ef | grep LOCAL=NO | grep -v grep | awk '{print $2}'`; kill -9 $tokill;
Step 3 The primary and standby should show the status as below.
set linesize 200
col DB_UNIQUE_NAME form a30
col DATABASE_ROLE for a20
col OPEN_MODE for a30
col SWITCHOVER_STATU for a30
select DB_UNIQUE_NAME,Database_role,open_mode,switchover_status from v$database;
At this stage, the primary database(devdb12) is not completely converted to standby. The primary
database is down and it is ready to covert for standby database. The standby database (devdb12_dg and
devdb12_dr) are ready to convert to primary. After completing Step 6, the primary(devdb12) will be
turned to standby. Step 6 can be executed on this step. But it is always good practice to start standby
after starting the primary to reduce the application down time. All three database status should show as
below after running the above command.
Now devdb12_dg becomes primary and ready to take the transactions. Still it is not ready to ship the
archive log file. At this moment, DBA can ask application team to start the application. Now application is
pointing to new primary(devdb12_dg). The old primary(devdb12) and second standby(devdb12_dr)
status should be as below. The old primary(devdb12) switch over status is RECOVERY_NEEDED. The
second standby(devdb12_dr) switch over status is NOT ALLOWED.
shutdown immediate;
startup nomount;
alter database mount standby database;
alter database recover managed standby database disconnect from session;
-- Wait for few minutes and make sure archive logs are shipping to standby database
alter database recover managed standby database cancel;
alter database open;
alter database recover managed standby database using current logfile disconnect;
Step 7 Verify the database mode for both primary and standby. Now devdb12 is standby and
devdb12_dg is primary database. Devdb12_dr is still standby and no change on devdb12_dr.
Step 8 Verify that archive logs are shipping correctly.
Or
----
(In case of RAC database, shutdown all the nodes except the primary one. Perform log switch in primary
node again)
(Go to to the next step when all Standby Sequences = Primary Sequences or are different by not more
than 1)
----
SWITCHOVER_STATUS
-----------------
SESSIONS ACTIVE
During normal operations it is acceptable to see the following values for SWITCHOVER_STATUS on the
primary to be SESSIONS ACTIVE or TO STANDBY.
10
Database altered.
-----
-----
Database altered.
SWITCHOVER_STATUS
-----------------
NOT ALLOWED
During normal operations on the standby it is acceptable to see the values of NOT ALLOWED or
SESSIONS ACTIVE.
Database altered.
Check the status of Database Role to confirm the conversion from Standby to Primary
SQL> startup;
3
SQL> alter database recover managed standby database disconnect;
or
Data Guard Switchover to a Physical
Standby
A switchover can be used to reduce downtime for planned outages such as patching to
the database or host OS and hardware upgrades. In a switchover the primary database
is transitioned to the standby role and the standby database is transitioned to the
primary role.
Verify there is no log file gap between the primary and the standby database.
Verify that the standby database has temporary files that match the primary.
Primary
If you received SESSIONS ACTIVE in the prior step you might have connections that may
prevent the switchover. Verify the active connections by querying V$SESSION.
The command to switch the primary database to a standby database is ALTER DATABASE
COMMIT TO SWITCHOVER TO PHYSICAL STANDBY. If your database has
a SWITCHOVER_STATUS of ACTIVE SESSIONS you will need to append the WITH SESSION
SHUTDOWN clause.
Note: the alter session statement is not required for switchover. I typically set the trace
identifier prior to performing tasks such as this to make identifying any trace file
generated during the process easier.
1
SQL> alter session set tracefile_identifier='SWITCHOVERTEST_06032010';
2
3 Session altered.
4
5 SQL> alter database commit to switchover to physical standby;
6 alter database commit to switchover to physical standby
7 *
ERROR at line 1:
8 ORA-01093: ALTER DATABASE CLOSE only permitted with no sessions connected
9
10
11 SQL>
12
If you get this error you have connected sessions that need to be shutdown. Re-issue
the command with the WITH SESSION SHUTDOWN clause.
1 SQL> alter database commit to switchover to physical standby with session shutdown;
2
3 Database altered.
4
5 SQL>
If you still get the error run the query presented earlier to identify the connection
sessions. Note: The connected sessions reported in the output of the query
against V$SESSION earlier were shutdown with the WITH SESSION SHUTDOWN clause.
Next we need to shutdown and then mount the new standby (former primary).
1
2 SQL> shutdown immediate
3 ORA-01507: database not mounted
4
5
ORACLE instance shut down.
6 SQL> startup mount
7 ORACLE instance started.
8
9 Total System Global Area 830930944 bytes
10 Fixed Size 2217912 bytes
Variable Size 620759112 bytes
11 Database Buffers 205520896 bytes
12 Redo Buffers 2433024 bytes
13 Database mounted.
14 SQL>
15
After mounting the database notice that alert.log states that the database is now a
Physical Standby database.
1
SQL> select sid, process, program
2 2 from v$session where type = 'USER';
3
4 SID PROCESS PROGRAM
5 ---------- ------------------------ ------------------------------------------------
6 19 23147 sqlplus@dreco.localdomain (TNS V1-V3)
36 18592 oracle@prod.localdomain (TNS V1-V3)
7 42 1234 OMS
8
9 SQL>
10
As with the switchover to standby, some connected sessions may prevent the
switchover to primary. Since we have a SWITCHOVER_STATUS of SESSIONS ACTIVE we will
need to apply the WITH SESSION SHUTDOWN clause.
The command to switch the standby database to a primary database is ALTER DATABASE
COMMIT TO SWITCHOVER TO PRIMARY. If your database has
a SWITCHOVER_STATUS of ACTIVE SESSIONS you will need to append the WITH SESSION
SHUTDOWN clause.
As the last step we will restart the Redo Apply services on the new standby. Below is an
exampled of enabling real-time apply. If for some reason you do not want to use real-
time apply remove the USING CURRENT LOGFILE from the command.
1 SQL> alter database recover managed standby database using current logfile disconnect
2
3 Database altered.
4
5 SQL>
Switch the log files a couple of times on the new primary and check the status.
Keep in mind that if your primary and standby database are being monitored through
Enterprise Manager you will need to reflect these changes manually. Enterprise
Manager will not know about the switchover or that the primary is now the standby and
old standby is now the new primary. It will just report the blocked connection to the old
primary.