1.当前情况:
prod1 主库
sbdb1 备库
DGMGRL> show configuration;
Configuration - cfgocm1
Protection Mode: MaxPerformance
Databases:
prod1 - Primary database
sbdb1 - Physical standby database
Fast-Start Failover: DISABLED
Configuration Status:
SUCCESS
2.直接使用 switchover进行切换到备库
DGMGRL> SWITCHOVER TO sbdb1;
Performing switchover NOW, please wait...
New primary database "sbdb1" is opening...
Operation requires shutdown of instance "prod1" on database "prod1"
Shutting down instance "prod1"...
ORACLE instance shut down.
Operation requires startup of instance "prod1" on database "prod1"
Starting instance "prod1"...
ORACLE instance started.
Database mounted.
Database opened.
Switchover succeeded, new primary is "sbdb1"
--如果我们这个时候去看报警日志文件,就会发现以前在sqlplus 中执行的 Completed: ALTER DATABASE COMMIT TO SWITCHOVER TO PHYSICAL STANDBY WITH SESSION SHUTDOWN,会自动执行。
3.确认已经主库已经切换为备库,备库已经切换为主库:
DGMGRL> show configuration;
Configuration - cfgocm1
Protection Mode: MaxPerformance
Databases:
sbdb1 - Primary database
prod1 - Physical standby database
Fast-Start Failover: DISABLED
Configuration Status:
SUCCESS
4.再次回切,把 prod1切换为主库:
DGMGRL> SWITCHOVER TO prod1
Performing switchover NOW, please wait...
New primary database "prod1" is opening...
Operation requires shutdown of instance "sbdb1" on database "sbdb1"
Shutting down instance "sbdb1"...
ORACLE instance shut down.
Operation requires startup of instance "sbdb1" on database "sbdb1"
Starting instance "sbdb1"...
ORACLE instance started.
Database mounted.
Database opened.
Switchover succeeded, new primary is "prod1"
5.再次确认:
DGMGRL> show configuration;
Configuration - cfgocm1
Protection Mode: MaxPerformance
Databases:
prod1 - Primary database
sbdb1 - Physical standby database
Fast-Start Failover: DISABLED
Configuration Status:
是不是又回来了
这个操作和手工使用sql命令进行切换是不是要简单很多,而且至始至终都在一台机器上操作,不需要来回在多台机器上操作。
下面附相关配置文件及监听信息:
1.备库:
[oracle@ocm2 admin]$ lsnrctl status
LSNRCTL for Linux: Version 11.2.0.3.0 - Production on 26-MAR-2019 19:39:22
Copyright (c) 1991, 2011, Oracle. All rights reserved.
Connecting to (DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=ocm2.sztech.com)(PORT=1521)))
STATUS of the LISTENER
------------------------
Alias LISTENER
Version TNSLSNR for Linux: Version 11.2.0.3.0 - Production
Start Date 26-MAR-2019 16:47:53
Uptime 0 days 2 hr. 51 min. 28 sec
Trace Level off
Security ON: Local OS Authentication
SNMP OFF
Listener Parameter File /u01/app/oracle/product/11.2.0/db_1/network/admin/listener.ora
Listener Log File /u01/app/oracle/diag/tnslsnr/ocm2/listener/alert/log.xml
Listening Endpoints Summary...
(DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=ocm2.sztech.com)(PORT=1521)))
Services Summary...
Service "sbdb1.example.com" has 2 instance(s).
Instance "sbdb1", status UNKNOWN, has 1 handler(s) for this service...
Instance "sbdb1", status READY, has 1 handler(s) for this service...
Service "sbdb1_DGB.example.com" has 1 instance(s).
Instance "sbdb1", status READY, has 1 handler(s) for this service...
Service "sbdb1_DGMGRL.example.com" has 1 instance(s).
Instance "sbdb1", status UNKNOWN, has 1 handler(s) for this service...
The command completed successfully
[oracle@ocm2 admin]$ cat listener.ora
# listener3996222964392981269.ora Network Configuration File: /tmp/listener3996222964392981269.ora
# Generated by Oracle configuration tools.
SID_LIST_LISTENER =
(SID_LIST =
(SID_DESC =
(GLOBAL_DBNAME = sbdb1.example.com)
(ORACLE_HOME = /u01/app/oracle/product/11.2.0/db_1)
(SID_NAME = sbdb1)
)
(SID_DESC =
(GLOBAL_DBNAME = sbdb1_DGMGRL.example.com) --这部分要手工加的
(ORACLE_HOME = /u01/app/oracle/product/11.2.0/db_1)
(SID_NAME = sbdb1)
)
)
LISTENER =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = ocm2.sztech.com)(PORT = 1521))
)
ADR_BASE_LISTENER = /u01/app/oracle
[oracle@ocm2 admin]$
[oracle@ocm2 admin]$
[oracle@ocm2 admin]$ cat tnsnames.ora
# tnsnames4598767396086864223.ora Network Configuration File: /tmp/tnsnames4598767396086864223.ora
# Generated by Oracle configuration tools.
SBDB1 =
(DESCRIPTION =
(ADDRESS_LIST =
(ADDRESS = (PROTOCOL = TCP)(HOST = ocm2.sztech.com)(PORT = 1521))
)
(CONNECT_DATA =
(SERVICE_NAME = sbdb1.example.com)
)
)
PROD1 =
(DESCRIPTION =
(ADDRESS_LIST =
(ADDRESS = (PROTOCOL = TCP)(HOST = ocm1.sztech.com)(PORT = 1521))
)
(CONNECT_DATA =
(SERVICE_NAME = prod1.example.com)
)
)
SBDB1_DGMGRL =
(DESCRIPTION =
(ADDRESS_LIST =
(ADDRESS = (PROTOCOL = TCP)(HOST = ocm2.sztech.com)(PORT = 1521))
)
(CONNECT_DATA =
(SERVICE_NAME = sbdb1_DGMGRL)
)
)
2.主库prod1:
[oracle@ocm1 ~]$ lsnrctl status
LSNRCTL for Linux: Version 11.2.0.3.0 - Production on 26-MAR-2019 19:46:22
Copyright (c) 1991, 2011, Oracle. All rights reserved.
Connecting to (DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=ocm1.sztech.com)(PORT=1521)))
STATUS of the LISTENER
------------------------
Alias LISTENER
Version TNSLSNR for Linux: Version 11.2.0.3.0 - Production
Start Date 26-MAR-2019 11:49:01
Uptime 0 days 7 hr. 57 min. 20 sec
Trace Level off
Security ON: Local OS Authentication
SNMP OFF
Listener Parameter File /u01/app/oracle/product/11.2.0/dbhome_1/network/admin/listener.ora
Listener Log File /u01/app/oracle/diag/tnslsnr/ocm1/listener/alert/log.xml
Listening Endpoints Summary...
(DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=ocm1.sztech.com)(PORT=1521)))
Services Summary...
Service "prod1.example.com" has 2 instance(s).
Instance "prod1", status UNKNOWN, has 1 handler(s) for this service...
Instance "prod1", status READY, has 1 handler(s) for this service...
Service "prod1XDB.example.com" has 1 instance(s).
Instance "prod1", status READY, has 1 handler(s) for this service...
Service "prod1_DGB.example.com" has 1 instance(s).
Instance "prod1", status READY, has 1 handler(s) for this service...
Service "prod1_DGMGRL.example.com" has 1 instance(s).
Instance "prod1", status UNKNOWN, has 1 handler(s) for this service...
The command completed successfully
[oracle@ocm1 ~]$
[oracle@ocm1 admin]$ cat listener.ora
# listener7430401327825906778.ora Network Configuration File: /tmp/listener7430401327825906778.ora
# Generated by Oracle configuration tools.
SID_LIST_LISTENER =
(SID_LIST =
(SID_DESC =
(GLOBAL_DBNAME = prod1.example.com)
(ORACLE_HOME = /u01/app/oracle/product/11.2.0/dbhome_1)
(SID_NAME = prod1)
)
(SID_DESC =
(GLOBAL_DBNAME = prod1_DGMGRL.example.com)
(ORACLE_HOME = /u01/app/oracle/product/11.2.0/dbhome_1)
(SID_NAME = prod1)
)
)
LISTENER =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = ocm1.sztech.com)(PORT = 1521))
)
ADR_BASE_LISTENER = /u01/app/oracle
[oracle@ocm1 admin]$
[oracle@ocm1 admin]$ cat tnsnames.ora
# tnsnames6882316049089510493.ora Network Configuration File: /tmp/tnsnames6882316049089510493.ora
# Generated by Oracle configuration tools.
SBDB1 =
(DESCRIPTION =
(ADDRESS_LIST =
(ADDRESS = (PROTOCOL = TCP)(HOST = ocm2.sztech.com)(PORT = 1521))
)
(CONNECT_DATA =
(SERVICE_NAME = sbdb1.example.com)
)
)
PROD1 =
(DESCRIPTION =
(ADDRESS_LIST =
(ADDRESS = (PROTOCOL = TCP)(HOST = ocm1.sztech.com)(PORT = 1521))
)
(CONNECT_DATA =
(SERVICE_NAME = prod1.example.com)
)
)
|