OCM 12c升级考试-使用DGMGRL做switchover和fast fail over

一、使用DGMGRL做switchover

按照前面我们Cloud Control安装配置之后,在主库的主机上运行dgmgrl就可以做命令切换操作了。这里我们先查看下配置情况,这里可以看到整个DG是最大性能模式,主库是PROD5T1,Physical standby是PROD5T2。

 [oracle@host01 ~]$ dgmgrl sys/oracle
 DGMGRL for Linux: Version 12.1.0.2.0 - 64bit Production

Copyright (c) 2000, 2013, Oracle. All rights reserved.

Welcome to DGMGRL, type "help" for information.
 Connected as SYSDG.
 DGMGRL> show configuration;

Configuration - PROD5

Protection Mode: MaxPerformance
 Members:
 PROD5T1 - Primary database
 PROD5T2 - Physical standby database

Fast-Start Failover: DISABLED

Configuration Status:
 SUCCESS (status updated 6 seconds ago)

我们直接运行switchover到PROD5T2,但是在切换的时候遇到了ORA-12514错误。

DGMGRL> switchover to "PROD5T2"
Performing switchover NOW, please wait...
Operation requires a connection to instance "PROD5" on database "PROD5T2"
Connecting to instance "PROD5"...
Connected as SYSDBA.
New primary database "PROD5T2" is opening...
Operation requires start up of instance "PROD5" on database "PROD5T1"
Starting instance "PROD5"...
Unable to connect to database using (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=host01.us.oracle.com)(PORT=1521))(CONNECT_DATA=(SERVICE_NAME=PROD5T1_DGMGRL)(INSTANCE_NAME=PROD5)(SERVER=DEDICATED)))
ORA-12514: TNS:listener does not currently know of service requested in connect descriptor
Failed.
Warning: You are no longer connected to ORACLE.

Please complete the following steps to finish switchover:
start up instance "PROD5" of database "PROD5T1"

这个问题主要是因为我们的配置不对, 先根据提示,把PROD5T1s这个实例先mount起来,保证DG先正常。

##########主库运行##########
[oracle@host01 ~]$ sqlplus / as sysdba
SQL*Plus: Release 12.1.0.2.0 Production on Mon May 21 22:43:14 2018
Copyright (c) 1982, 2014, Oracle. All rights reserved.
Connected to an idle instance.
SQL> startup mount;

##########备库运行##########
[oracle@orae12 admin]$ dgmgrl sys/oracle
DGMGRL for Linux: Version 12.1.0.2.0 - 64bit Production

Copyright (c) 2000, 2013, Oracle. All rights reserved.

Welcome to DGMGRL, type "help" for information.
Connected as SYSDG.
DGMGRL> show configuration;

Configuration - PROD5

Protection Mode: MaxPerformance
Members:
PROD5T2 - Primary database
PROD5T1 - Physical standby database

Fast-Start Failover: DISABLED

Configuration Status:
SUCCESS (status updated 14 seconds ago)

可以看到,备库PROD5T2现在成为了主,而主库PROD5T1成为了Physical standby,那么我们在把这个切换回来。

##########备库运行##########
DGMGRL> switchover to "PROD5T1"
Performing switchover NOW, please wait...
Operation requires a connection to instance "PROD5" on database "PROD5T1"
Connecting to instance "PROD5"...
Connected as SYSDBA.
New primary database "PROD5T1" is opening...
Operation requires start up of instance "PROD5" on database "PROD5T2"
Starting instance "PROD5"...
ORACLE instance started.
Database mounted.
Switchover succeeded, new primary is "PROD5T1"

切换回来之后,在主库再次登陆,检查主库的配置。

##########主库运行##########
[oracle@host01 ~]$ dgmgrl sys/oracle
DGMGRL for Linux: Version 12.1.0.2.0 - 64bit Production

Copyright (c) 2000, 2013, Oracle. All rights reserved.

Welcome to DGMGRL, type "help" for information.
Connected as SYSDG.
DGMGRL> show configuration;

Configuration - PROD5

Protection Mode: MaxPerformance
Members:
PROD5T1 - Primary database
PROD5T2 - Physical standby database

Fast-Start Failover: DISABLED

Configuration Status:
SUCCESS (status updated 27 seconds ago)

DGMGRL> show database verbose "PROD5T1"

Database - PROD5T1

Enterprise Manager Name: PROD5
Role: PRIMARY
Intended State: TRANSPORT-ON
Instance(s):
PROD5

Properties:
DGConnectIdentifier = '(DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=host01.us.oracle.com)(PORT=1521))(CONNECT_DATA=(SERVICE_NAME=PROD5T1)(SERVER=DEDICATED)))'
ObserverConnectIdentifier = ''
LogXptMode = 'ASYNC'
RedoRoutes = ''
DelayMins = '0'
Binding = 'optional'
MaxFailure = '0'
MaxConnections = '1'
ReopenSecs = '300'
NetTimeout = '30'
RedoCompression = 'DISABLE'
LogShipping = 'ON'
PreferredApplyInstance = ''
ApplyInstanceTimeout = '0'
ApplyLagThreshold = '0'
TransportLagThreshold = '0'
TransportDisconnectedThreshold = '30'
ApplyParallel = 'AUTO'
StandbyFileManagement = 'AUTO'
ArchiveLagTarget = '0'
LogArchiveMaxProcesses = '4'
LogArchiveMinSucceedDest = '1'
DbFileNameConvert = ''
LogFileNameConvert = ''
FastStartFailoverTarget = ''
InconsistentProperties = '(monitor)'
InconsistentLogXptProps = '(monitor)'
SendQEntries = '(monitor)'
LogXptStatus = '(monitor)'
RecvQEntries = '(monitor)'
StaticConnectIdentifier = '(DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=host01.us.oracle.com)(PORT=1521))(CONNECT_DATA=(SERVICE_NAME=PROD5T1_DGMGRL)(INSTANCE_NAME=PROD5)(SERVER=DEDICATED)))'
StandbyArchiveLocation = 'USE_DB_RECOVERY_FILE_DEST'
AlternateLocation = ''
LogArchiveTrace = '0'
LogArchiveFormat = '%t_%s_%r.dbf'
TopWaitEvents = '(monitor)'

Database Status:
SUCCESS

这里我们看StaticConnectIdentifier,指向的SERVICE_NAME是PROD5T1_DGMGRL,端口是1521,那么我们通过监听来看一下。

##########主库运行##########
[oracle@host01 admin]$ lsnrctl status

LSNRCTL for Linux: Version 12.1.0.2.0 - Production on 21-MAY-2018 22:37:31

Copyright (c) 1991, 2014, Oracle. All rights reserved.

Connecting to (DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=host01.us.oracle.com)(PORT=1521)))
STATUS of the LISTENER
------------------------
Alias LISTENER
Version TNSLSNR for Linux: Version 12.1.0.2.0 - Production
Start Date 21-MAY-2018 22:36:10
Uptime 0 days 0 hr. 1 min. 21 sec
Trace Level off
Security ON: Local OS Authentication
SNMP OFF
Listener Parameter File /u01/app/oracle/product/12.1.0/dbhome_1/network/admin/listener.ora
Listener Log File /u01/app/oracle/diag/tnslsnr/host01/listener/alert/log.xml
Listening Endpoints Summary...
(DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=host01.us.oracle.com)(PORT=1521)))
(DESCRIPTION=(ADDRESS=(PROTOCOL=ipc)(KEY=EXTPROC1521)))
(DESCRIPTION=(ADDRESS=(PROTOCOL=tcps)(HOST=host01.us.oracle.com)(PORT=5502))(Security=(my_wallet_directory=/u01/app/oracle/admin/PROD5T1/xdb_wallet))(Presentation=HTTP)(Session=RAW))
Services Summary...
Service "PROD5T1" has 1 instance(s).
Instance "PROD5", status READY, has 1 handler(s) for this service...
Service "PROD5T1_DGB" has 1 instance(s).
Instance "PROD5", status READY, has 1 handler(s) for this service...
Service "PROD5XDB" has 1 instance(s).
Instance "PROD5", status READY, has 1 handler(s) for this service...

可以看到监听里面并没有这个Service,那么这需要我们自己手工注册一个静态的Service。修改listener.ora文件,增加静态的SID_LIST_LISTENER。然后重启监听服务。

##########主库运行##########
# listener.ora Network Configuration File: /u01/app/oracle/product/12.1.0/dbhome_1/network/admin/listener.ora
# Generated by Oracle configuration tools.

LISTENER =
(DESCRIPTION_LIST =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = host01.us.oracle.com)(PORT = 1521))
(ADDRESS = (PROTOCOL = IPC)(KEY = EXTPROC1521))
)
)

SID_LIST_LISTENER =
(SID_LIST =
(SID_DESC =
(GLOBAL_DBNAME = PROD5T1_DGMGRL)
(ORACLE_HOME = /u01/app/oracle/product/12.1.0/dbhome_1)
(SID_NAME = PROD5)
)
)

[oracle@host01 admin]$ lsnrctl status

LSNRCTL for Linux: Version 12.1.0.2.0 - Production on 21-MAY-2018 22:52:11

Copyright (c) 1991, 2014, Oracle. All rights reserved.

Connecting to (DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=host01.us.oracle.com)(PORT=1521)))
STATUS of the LISTENER
------------------------
Alias LISTENER
Version TNSLSNR for Linux: Version 12.1.0.2.0 - Production
Start Date 21-MAY-2018 22:51:40
Uptime 0 days 0 hr. 0 min. 30 sec
Trace Level off
Security ON: Local OS Authentication
SNMP OFF
Listener Parameter File /u01/app/oracle/product/12.1.0/dbhome_1/network/admin/listener.ora
Listener Log File /u01/app/oracle/diag/tnslsnr/host01/listener/alert/log.xml
Listening Endpoints Summary...
(DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=host01.us.oracle.com)(PORT=1521)))
(DESCRIPTION=(ADDRESS=(PROTOCOL=ipc)(KEY=EXTPROC1521)))
(DESCRIPTION=(ADDRESS=(PROTOCOL=tcps)(HOST=host01.us.oracle.com)(PORT=5502))(Security=(my_wallet_directory=/u01/app/oracle/admin/PROD5T1/xdb_wallet))(Presentation=HTTP)(Session=RAW))
Services Summary...
Service "PROD5T1" has 1 instance(s).
Instance "PROD5", status READY, has 1 handler(s) for this service...
Service "PROD5T1_DGB" has 1 instance(s).
Instance "PROD5", status READY, has 1 handler(s) for this service...
Service "PROD5T1_DGMGRL" has 1 instance(s).
Instance "PROD5", status UNKNOWN, has 1 handler(s) for this service...
Service "PROD5XDB" has 1 instance(s).
Instance "PROD5", status READY, has 1 handler(s) for this service...
The command completed successfully

当监听服务里面有PROD5T1_DGMGRL之后,我们再次运行DGMGRL进行切换,这次顺利切换成功,没有在报ORA-12514了。

##########主库运行##########
[oracle@host01 ~]$ dgmgrl sys/oracle
DGMGRL for Linux: Version 12.1.0.2.0 - 64bit Production

Copyright (c) 2000, 2013, Oracle. All rights reserved.

Welcome to DGMGRL, type "help" for information.
Connected as SYSDG.
DGMGRL> switchover to "PROD5T2"
Performing switchover NOW, please wait...
Operation requires a connection to instance "PROD5" on database "PROD5T2"
Connecting to instance "PROD5"...
Connected as SYSDBA.
New primary database "PROD5T2" is opening...
Operation requires start up of instance "PROD5" on database "PROD5T1"
Starting instance "PROD5"...
ORACLE instance started.
Database mounted.
Switchover succeeded, new primary is "PROD5T2"

二、使用DGMGRL做fast fail over

Cloud Control创建的配置为MaxPerformance,然后是ASYNC日志传送方式,这对于fast fail over配置不正确,我们需要把这个修改成maxavailability,Sync模式。

DGMGRL> edit database "PROD5T1" set property LogXptMode='SYNC';
Property "logxptmode" updated
DGMGRL> edit database "PROD5T2" set property LogXptMode='SYNC';
Property "logxptmode" updated
DGMGRL> edit configuration set protection mode as  maxavailability;
Succeeded.

第二个需要我们启动flashback on

##########主库运行##########
sqlplus / as sysdba
alter database flashback on; 
DGMGRL> edit database "PROD5T1" set property FastStartFailoverTarget='PROD5T2'
DGMGRL> edit database "PROD5T2" set property FastStartFailoverTarget='PROD5T1'
DGMGRL> edit database "PROD5T2" set state='apply-off';
##########备库运行##########
sqlplus / as sysdba
alter database flashback on; 
##########主库运行##########
DGMGRL> edit database "PROD5T2" set state='apply-on';

在根据要求配置TransportLagThreshold和ApplyLagThreshold

DGMGRL> edit database 'PROD5T1' set property TransportLagThreshold=30; 
DGMGRL> edit database 'PROD5T2' set property TransportLagThreshold=30;
DGMGRL> edit database 'PROD5T1' set property ApplyLagThreshold=45; 
DGMGRL> edit database 'PROD5T2' set property ApplyLagThreshold=45; 

接下来开启fast fail over,然后启动观察者

DGMGRL> ENABLE FAST_START FAILOVER
DGMGRL> start observer

此时如果我们shutdown abort主库,我们可以在观察者中观察到下面的情况。主库遇到故障,观察者发现后直接做Failover,此时备库成为了新的主库。整个过程不需要人工进行干预

DGMGRL> start observer
Observer started

23:39:39.65  Monday, May 21, 2018
Initiating Fast-Start Failover to database "PROD5T2"...
Performing failover NOW, please wait...
Failover succeeded, new primary is "PROD5T2"
23:39:45.42  Monday, May 21, 2018

关注dbDao.com的新浪微博

扫码加入微信Oracle小密圈,了解Oracle最新技术下载分享资源

TEL/電話+86 13764045638
Email service@parnassusdata.com
QQ 47079569