【DataGuard】10g物理standby主備switchover方式切換詳述

secooler發表於2009-03-27
以下給大家展現一下10g物理standby主備之間透過switchover方式進行切換的詳細步驟,供參考。

1、主庫檢查是否為“TO STANDBY”狀態,若不是,需要重新啟動一下主庫(主庫ora10g操作)
sys@ora10g> select switchover_status from v$database;

SWITCHOVER_STATUS
--------------------
SESSIONS ACTIVE

sys@ora10g> startup force ;
ORACLE instance started.

Total System Global Area  104857600 bytes
Fixed Size                  1266056 bytes
Variable Size              83889784 bytes
Database Buffers           16777216 bytes
Redo Buffers                2924544 bytes
Database mounted.
Database opened.
sys@ora10g> select switchover_status from v$database;

SWITCHOVER_STATUS
--------------------
TO STANDBY

2.將primary轉換為standby角色(主庫ora10g操作)
sys@ora10g> alter database commit to switchover to physical standby;

Database altered.

3.原主庫重啟動到mount狀態(原主庫ora10g操作)
NotConnected@> shutdown immediate;
ORA-01507: database not mounted


ORACLE instance shut down.
NotConnected@>
NotConnected@> startup mount;
ORACLE instance started.

Total System Global Area  104857600 bytes
Fixed Size                  1266056 bytes
Variable Size              88084088 bytes
Database Buffers           12582912 bytes
Redo Buffers                2924544 bytes
Database mounted.

4.檢查原備庫是否為“TO PRIMARY”狀態,如果為“SWITCHOVER PENDING”狀態,需要先進行一下恢復再切換 (待切換備庫ora10gdg操作)
ora10g@linux5 /home/oracle$ export ORACLE_SID=ora10gdg
ora10gdg@linux5 /home/oracle$ sqlplus / as sysdba

SQL*Plus: Release 10.2.0.4.0 - Production on Sat Mar 28 08:26:53 2009

Copyright (c) 1982, 2007, Oracle.  All Rights Reserved.


Connected to:
Oracle Database 10g Enterprise Edition Release 10.2.0.4.0 - Production
With the Partitioning, Data Mining and Real Application Testing options

NotConnected@> select switchover_status from v$database;

SWITCHOVER_STATUS
--------------------
SWITCHOVER PENDING

NotConnected@> alter database commit to switchover to primary;
alter database commit to switchover to primary
*
ERROR at line 1:
ORA-16139: media recovery required

NotConnected@> alter database recover managed standby database disconnect from session;

Database altered.

NotConnected@> alter database recover managed standby database cancel;

Database altered.

NotConnected@> select switchover_status from v$database;

SWITCHOVER_STATUS
--------------------
TO PRIMARY

5.原備庫轉換角色到primary (待切換備庫ora10gdg操作)
NotConnected@> alter database commit to switchover to primary;

Database altered.

6.主備切換完成,open新的primary資料庫  (待切換備庫ora10gdg操作)
NotConnected@> alter database open;

Database altered.

7.最後驗證階段
1).新的primary庫在sec使用者建立一個新表test_new
sec@ora10g> create table test_new (a int);

Table created.

sec@ora10g> insert into test_new values ( 100 );

1 row created.

sec@ora10g> commit;

Commit complete.

sec@ora10g> select * from test_new;

         A
----------
       100

sec@ora10g> conn / as sysdba
Connected.
sys@ora10g> alter system switch logfile;

System altered.

sys@ora10g> select max(sequence#) from v$archived_log;

MAX(SEQUENCE#)
--------------
            69

2).檢視新standby庫,驗證切換是否成功
ora10gdg@linux5 /home/oracle$ export ORACLE_SID=ora10g
ora10g@linux5 /home/oracle$ sqlplus / as sysdba

SQL*Plus: Release 10.2.0.4.0 - Production on Sat Mar 28 08:55:09 2009

Copyright (c) 1982, 2007, Oracle.  All Rights Reserved.


Connected to:
Oracle Database 10g Enterprise Edition Release 10.2.0.4.0 - Production
With the Partitioning, Data Mining and Real Application Testing options

NotConnected@> alter database recover managed standby database disconnect from session;

Database altered.

NotConnected@> select max(sequence#) from v$archived_log;

MAX(SEQUENCE#)
--------------
            69

NotConnected@> alter database recover managed standby database cancel;

Database altered.

NotConnected@> alter database open read only;

Database altered.

NotConnected@> conn sec/sec
Connected.
sec@ora10g> select * from test_new;

         A
----------
       100

OK!到此主備之間的switchover方式切換成功。

secooler
09.03.27

-- The End --

來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/519536/viewspace-580380/,如需轉載,請註明出處,否則將追究法律責任。

相關文章