使用DG_broker工具管理DG之switchover

skyin_1603發表於2016-10-22
想到當時我做這個實驗的時候,由於在dg_broker工具使用switchover切換主備庫時候,忘記了具體語法,
官方文件找沒有講到,網上找也完全沒有太多的文章講到dg_broker工具管理DG的,有了文章,都是很粗糙的文章,
很難看的明白,關鍵是參照敲了語句上去,也是報錯,還一直嫌疑自己配錯了引數檔案CONFIGURATION,
試了幾個語句都不行,都切換不了。由於是凌晨了,心想放到明天再更改引數檔案再試一試。第二天,繼續這個測試,
心想著,要是弄出來了,一定要把switchover的測試過程放上去我的部落格裡。第二天更換了引數檔案還是不行,
想著額,難道是庫名那裡有問題,試了把switchover to 備庫名 的庫名用單引號括起,奇蹟出現了,主備庫切換了。
後面問了一些人說這個還是看版本的,說他當時做也是弄了很久。一下是測試過程使用DG_broker工具管理DG:

--主庫配置dg broker監聽並開啟:
SID_LIST_LISTENER=
  (SID_LIST=
    (SID_DESC=
     (GLOBAL_DBNAME=ENMO_DGMGRL.oracle.com)
     (ORACLE_HOME=/u01/app/oracle/product/11.2.0/dbhome_1)
     (SID_NAME=ENMO))
    (SID_DESC=
     (GLOBAL_DBNAME=ORA11GR2)
     (ORACLE_HOME=/u01/app/oracle/product/11.2.0/dbhome_1)
     (SID_NAME=ORA11GR2))
  )
  
SQL> alter system set dg_broker_start=true;
System altered.

--備庫配置dg broker監聽並開啟:
SID_LIST_LISTENER=
  (SID_LIST=
    (SID_DESC=
     (GLOBAL_DBNAME=PROD_DGMGRL.oracle.com)
     (ORACLE_HOME=/u01/app/oracle/product/11.2.0/dbhome_1)
     (SID_NAME=PROD))
  )
  
SQL> alter system set dg_broker_start=true;
System altered.

--登入DG——broker工具:
[oracle@oracle admin]$ export ORACLE_SID=ENMO
[oracle@oracle admin]$ dgmgrl               #登入使用方法與rman相似
DGMGRL for Linux: Version 11.2.0.4.0 - 64bit Production
Copyright (c) 2000, 2009, Oracle. All rights reserved.
Welcome to DGMGRL, type "help" for information.
DGMGRL> 
DGMGRL> 
DGMGRL> connect sys/oracle
Connected.

--首先把之前建立的引數檔案刪除REMOVE:
DGMGRL> REMOVE CONFIGURATION;
Removed configuration
DGMGRL> SHOW CONFIGURATION;
ORA-16532: Data Guard broker configuration does not exist
Configuration details cannot be determined by DGMGRL
DGMGRL> 

--建立新的引數檔案CONFIGURATION:
DGMGRL>  CREATE CONFIGURATION 'ENMO' as  PRIMARY DATABASE IS 'ENMO' CONNECT IDENTIFIER IS ENMO;
Configuration "ENMO" created with primary database "ENMO"

--檢視引數檔案的狀態:
DGMGRL> SHOW CONFIGURATION;
Configuration - ENMO

  Protection Mode: MaxAvailability
  Databases:
    ENMO - Primary database
Fast-Start Failover: DISABLED
Configuration Status:
DISABLED

--新增備庫:
DGMGRL>  ADD DATABASE 'PROD' AS CONNECT IDENTIFIER IS ENMO;
Error: ORA-16662: network timeout when contacting a database    
Failed.
新增備庫錯誤。

--正確的新增方法:
DGMGRL> ADD DATABASE 'PROD' AS CONNECT IDENTIFIER IS PROD;
Database "PROD" added

--啟用引數檔案:
DGMGRL> ENABLE CONFIGURATION;
Enabled.
啟用成功。

--檢視引數檔案狀態:
DGMGRL> SHOW CONFIGURATION;
Configuration - ENMO
  Protection Mode: MaxAvailability
  Databases:
    ENMO - Primary database
    PROD - Physical standby database
Fast-Start Failover: DISABLED
Configuration Status:
SUCCESS
已經使用。

--啟用備庫PROD:
DGMGRL>  ENABLE DATABASE 'PROD'
Enabled.
DGMGRL> 
啟用成功。

--檢視備庫的狀態:
DGMGRL> SHOW CONFIGURATION;
Configuration - ENMO
  Protection Mode: MaxAvailability
  Databases:
    ENMO - Primary database
    PROD - Physical standby database
Fast-Start Failover: DISABLED
Configuration Status:
SUCCESS

--檢視詳細資訊:
DGMGRL>  SHOW DATABASE 'PROD';    
Database - PROD
  Role:            PHYSICAL STANDBY
  Intended State:  APPLY-ON
  Transport Lag:   0 seconds (computed 0 seconds ago)
  Apply Lag:       0 seconds (computed 0 seconds ago)
  Apply Rate:      895.00 KByte/s
  Real Time Query: ON
  Instance(s):
    PROD
Database Status:
SUCCESS

--檢視主庫或者備庫更詳細的資訊:
DGMGRL> SHOW DATABASE VERBOSE 'ENMO';       #同樣去檢視另外一個庫的狀態,只需修改唯一庫名
Database - ENMO

  Role:            PRIMARY
  Intended State:  TRANSPORT-ON
  Instance(s):
    ENMO
  Properties:
    DGConnectIdentifier             = 'enmo'
    ObserverConnectIdentifier       = ''
    LogXptMode                      = 'SYNC'
    DelayMins                       = '0'
    Binding                         = 'optional'
    MaxFailure                      = '0'
    MaxConnections                  = '1'
    ReopenSecs                      = '300'
    NetTimeout                      = '30'
    RedoCompression                 = 'DISABLE'
    LogShipping                     = 'ON'
    PreferredApplyInstance          = ''
    ApplyInstanceTimeout            = '0'
    ApplyParallel                   = 'AUTO'
    StandbyFileManagement           = 'AUTO'
    ArchiveLagTarget                = '0'
    LogArchiveMaxProcesses          = '30'
    LogArchiveMinSucceedDest        = '1'
    DbFileNameConvert               = 'PROD, ENMO'
    LogFileNameConvert              = 'PROD, ENMO'
    FastStartFailoverTarget         = ''
    InconsistentProperties          = '(monitor)'
    InconsistentLogXptProps         = '(monitor)'
    SendQEntries                    = '(monitor)'
    LogXptStatus                    = '(monitor)'
    RecvQEntries                    = '(monitor)'
    ApplyLagThreshold               = '0'
    TransportLagThreshold           = '0'
    TransportDisconnectedThreshold  = '30'
    SidName                         = 'ENMO'
    StaticConnectIdentifier         = '(DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=oracle)(PORT=1521))(CONNECT_DATA=(SERVICE_NAME=ENMO_DGMGRL.oracle.com)(INSTANCE_NAME=ENMO)(SERVER=DEDICATED)))'
    StandbyArchiveLocation          = '/home/oracle/arch/ENMO/'
    AlternateLocation               = ''
    LogArchiveTrace                 = '0'
    LogArchiveFormat                = '%t_%s_%r.arc'
    TopWaitEvents                   = '(monitor)'

--切換主備庫:
DGMGRL> switchover to 'PROD';    #這裡特別強調:to備庫名,有些版本不需加單引號括起,有些版本需要括起。
Performing switchover NOW, please wait...
Operation requires a connection to instance "PROD" on database "PROD"
Connecting to instance "PROD"...
Connected.
New primary database "PROD" is opening...
Operation requires startup of instance "ENMO" on database "ENMO"
Starting instance "ENMO"...
ORACLE instance started.
Database mounted.
Database opened.
Switchover succeeded, new primary is "PROD"

--切換之後,檢視新的主庫與備庫資訊:
--檢視主庫狀態:
SQL> select database_role,open_mode from v$database;
DATABASE_ROLE    OPEN_MODE
---------------- --------------------
PRIMARY          READ WRITE

--檢視備庫的狀態:
SQL> select database_role,open_mode from v$database;
DATABASE_ROLE    OPEN_MODE
---------------- --------------------
PHYSICAL STANDBY READ ONLY WITH APPLY

--切換保護模式:
----重新調至最大可用模式:

DGMGRL> EDIT DATABASE 'PROD' SET PROPERTY 'LogXptMode'='ASYNC';
Property "LogXptMode" updated
DGMGRL> EDIT DATABASE 'ENMO' SET PROPERTY 'LogXptMode'='ASYNC';
Error: ORA-16805: change of LogXptMode property violates overall protection mode

Failed.
DGMGRL> EDIT CONFIGURATION SET PROTECTION MODE AS MAXPERFORMANCE;
Succeeded.
DGMGRL> 
DGMGRL> 
DGMGRL> show configuration;

Configuration - ENMO
  Protection Mode: MaxPerformance
  Databases:
    PROD - Primary database
    ENMO - Physical standby database
Fast-Start Failover: DISABLED

Configuration Status:
SUCCESS
最大可用模式切換成功。

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

相關文章