Dataguard物理Standby Switchover 角色轉換

梓沐發表於2016-02-15

無損轉換,通常是使用者手動觸發或者有計劃的讓其自動觸發,比如硬體升級啦,軟體升級啦之類的。通常它給你帶來的工作量非常小並且都是可預計的。其執行分兩個階段,第一步,primary資料庫轉換為standby角色,第二步,standby資料庫(之一)轉換為primary角色,primarystandby只是簡單的角色互換,這也印證了我們前面關於角色轉換是primary/standby互動的猜測。

--primary資料庫操作

1.檢查是否支援switchover操作

SQL> select switchover_status from v$database;

SWITCHOVER_STATUS

--------------------

TO STANDBY

2.啟動switchover,primary轉換為standby的角色

SQL> alter database commit to switchover to physical standby;

Database altered.

語句執行完畢後,primary資料庫將會轉換為standby資料庫,並自動備份控制檔案到trace

--standby資料庫操作

1.如果備庫啟動先關閉資料庫,並重啟到mount階段

SQL> shutdown immediate

Database closed.

Database dismounted.

ORACLE instance shut down.

SQL> startup mount

ORACLE instance started.

2.檢查備庫是否支援switchover操作

SQL> select switchover_status from v$database;

SWITCHOVER_STATUS

--------------------

TO PRIMARY

3.執行轉換standbyprimary角色語句

SQL> alter database commit to switchover to primary;

alter database commit to switchover to primary

*

ERROR at line 1:

ORA-00344: unable to re-create online log '/u01/oracle/oradata/orcl/redo01.log'

ORA-27040: file create error, unable to create file

Linux-x86_64 Error: 2: No such file or directory

Additional information: 1

--這裡報了一個錯,是因為備庫中在/u01/oracle/oradata下沒有orcl的執行目錄和許可權,建立orcl目錄並賦予對應許可權後:

SQL> alter database commit to switchover to primary;

Database altered.

4.開啟資料庫

SQL> alter database open;

Database altered.

5.開啟原primary資料庫

SQL> alter database open;

Database altered.

6.將原primary資料庫開啟恢復模式

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

Database altered.

--驗證結果

primary資料庫

SQL> show parameter db_unique

NAME                                 TYPE        VALUE

------------------------------------ ----------- ------------------------------

db_unique_name                       string      dg

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

MAX(SEQUENCE#)

--------------

            30

SQL> alter system switch logfile;

System altered.

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

MAX(SEQUENCE#)

--------------

            31

新的standby資料庫

SQL>  show parameter db_unique

NAME                                 TYPE        VALUE

------------------------------------ ----------- ------------------------------

db_unique_name                       string      orcl

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

MAX(SEQUENCE#)

--------------

            30

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

MAX(SEQUENCE#)

--------------

            31

轉換成功

```

```

2.備庫在轉換為主庫時狀態為:NOT ALLOWED--可能需要恢復或者退出恢復模式。

SQL> select switchover_status from v$database;

SWITCHOVER_STATUS

--------------------

NOT ALLOWED

SQL> alter database commit to switchover to primary;

alter database commit to switchover to primary

*

ERROR at line 1:

ORA-16139: media recovery required

或者如下:--RECOVERY NEEDED

SQL> select switchover_status from v$database;

SWITCHOVER_STATUS

--------------------

RECOVERY NEEDED

###############

SQL> alter database recover managed standby database disconnect from session;

Database altered.

SQL> select switchover_status from v$database;

SWITCHOVER_STATUS

--------------------

TO PRIMARY

SQL> alter database commit to switchover to primary;

Database altered.


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

相關文章