使用Docker测试Oracle 11g高可用DG功能
一、下载镜像
小麦苗DG环境的hub地址:
https://hub.docker.com/r/lhrbest/dg_pri_11.2.0.4/tags
https://hub.docker.com/r/lhrbest/dg_phy_11.2.0.4/tags
nohup docker pull registry.cn-hangzhou.aliyuncs.com/lhrbest/dg_phy_11.2.0.4:1.0 &
nohup docker pull registry.cn-hangzhou.aliyuncs.com/lhrbest/dg_pri_11.2.0.4:1.0 &
查看镜像:
[root@docker36 ~]# docker images | grep dg
registry.cn-hangzhou.aliyuncs.com/lhrbest/dg_phy_11.2.0.4 1.0 f2ea019fe540 15 hours ago 10.7GB
registry.cn-hangzhou.aliyuncs.com/lhrbest/dg_pri_11.2.0.4 1.0 b7fae2029b40 15 hours ago 10.8GB
给镜像打tag:
[root@docker36 ~]# docker tag registry.cn-hangzhou.aliyuncs.com/lhrbest/dg_phy_11.2.0.4:1.0 lhrbest/dg_phy_11.2.0.4:1.0
[root@docker36 ~]# docker tag registry.cn-hangzhou.aliyuncs.com/lhrbest/dg_pri_11.2.0.4:1.0 lhrbest/dg_pri_11.2.0.4:1.0
[root@docker36 ~]# docker images | grep dg
lhrbest/dg_phy_11.2.0.4 1.0 f2ea019fe540 15 hours ago 10.7GB
registry.cn-hangzhou.aliyuncs.com/lhrbest/dg_phy_11.2.0.4 1.0 f2ea019fe540 15 hours ago 10.7GB
lhrbest/dg_pri_11.2.0.4 1.0 b7fae2029b40 15 hours ago 10.8GB
registry.cn-hangzhou.aliyuncs.com/lhrbest/dg_pri_11.2.0.4 1.0 b7fae2029b40 15 hours ago 10.8GB
二、初始化环境
DG环境情况见下表:
项目 | 主库 | 物理备库 |
---|---|---|
db 类型 | 单实例 | 单实例 |
db version | 11.2.0.4.0 | 11.2.0.4.0 |
db 存储 | FS | FS |
OS版本 | RHEL7.6 64位 | CentOS7.6 64位 |
OS hostname | LHR11G | LHR11GDG |
IP地址 | 192.168.68.68 | 192.168.68.69 |
ORACLE_SID | LHR11G | LHR11GDG |
db_name/GLOBAL_DBNAME | LHR11G | LHR11G |
db_unique_name | LHR11G | LHR11GDG |
TNS_NAME | LHR11G | LHR11GDG |
监听端口 | 1521 | 1521 |
映射的主机端口 | 1528 | 1529 |
ORACLE_HOME | /u01/app/oracle/product/11.2.0.4/dbhome_1 | /u01/app/oracle/product/11.2.0.4/dbhome_1 |
dbid | 2007947551 | 2007947551 |
-- 创建DG的网络
docker network create --subnet=192.168.68.0/16 mhalhr
docker network inspect mhalhr
-- 分别初始化主库和备库
docker run -itd --name LHR11G -h LHR11G \
-p 1528:1521 -p 1128:1158 -p 228:22 -p 3398:3389 \
--network mhalhr --ip 192.168.68.68 \
--privileged=true \
lhrbest/dg_pri_11.2.0.4:1.0 init
docker run -itd --name LHR11GDG -h LHR11GDG \
-p 1529:1521 -p 1129:1158 -p 229:22 -p 3399:3389 \
--network mhalhr --ip 192.168.68.69 \
--privileged=true \
lhrbest/dg_phy_11.2.0.4:1.0 init
-- 添加网卡
docker network connect bridge LHR11G
docker network connect bridge LHR11GDG
-- 进入容器
docker exec -it LHR11G bash
docker exec -it LHR11GDG bash
-- 分别启动主库、备库和监听
su - oracle
lsnrctl start
sas
startup
启动主库过程:
[root@docker36 ~]# docker exec -it LHR11G bash
[root@lhr11g /]# su - oracle
[oracle@lhr11g ~]$ sas
SQL*Plus: Release 11.2.0.4.0 Production on Wed Oct 28 08:43:43 2020
Copyright (c) 1982, 2013, Oracle. All rights reserved.
Connected to an idle instance.
SYS@LHR11G> startup
ORACLE instance started.
Total System Global Area 325685248 bytes
Fixed Size 2252944 bytes
Variable Size 188747632 bytes
Database Buffers 130023424 bytes
Redo Buffers 4661248 bytes
Database mounted.
Database opened.
SYS@LHR11G> exit
Disconnected from Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
[oracle@lhr11g ~]$ lsnrctl start
LSNRCTL for Linux: Version 11.2.0.4.0 - Production on 28-OCT-2020 08:48:58
Copyright (c) 1991, 2013, Oracle. All rights reserved.
Starting /u01/app/oracle/product/11.2.0.4/dbhome_1/bin/tnslsnr: please wait...
TNSLSNR for Linux: Version 11.2.0.4.0 - Production
System parameter file is /u01/app/oracle/product/11.2.0.4/dbhome_1/network/admin/listener.ora
Log messages written to /u01/app/oracle/diag/tnslsnr/lhr11g/listener/alert/log.xml
Listening on: (DESCRIPTION=(ADDRESS=(PROTOCOL=ipc)(KEY=EXTPROC1521)))
Listening on: (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=LHR11G)(PORT=1521)))
Connecting to (DESCRIPTION=(ADDRESS=(PROTOCOL=IPC)(KEY=EXTPROC1521)))
STATUS of the LISTENER
------------------------
Alias LISTENER
Version TNSLSNR for Linux: Version 11.2.0.4.0 - Production
Start Date 28-OCT-2020 08:48:59
Uptime 0 days 0 hr. 0 min. 0 sec
Trace Level off
Security ON: Local OS Authentication
SNMP OFF
Listener Parameter File /u01/app/oracle/product/11.2.0.4/dbhome_1/network/admin/listener.ora
Listener Log File /u01/app/oracle/diag/tnslsnr/lhr11g/listener/alert/log.xml
Listening Endpoints Summary...
(DESCRIPTION=(ADDRESS=(PROTOCOL=ipc)(KEY=EXTPROC1521)))
(DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=LHR11G)(PORT=1521)))
Services Summary...
Service "LHR11G" has 1 instance(s).
Instance "LHR11G", status UNKNOWN, has 1 handler(s) for this service...
Service "LHR11G_dgmgrl" has 1 instance(s).
Instance "LHR11G", status UNKNOWN, has 1 handler(s) for this service...
The command completed successfully
[oracle@lhr11g ~]$ lsnrctl status
LSNRCTL for Linux: Version 11.2.0.4.0 - Production on 28-OCT-2020 08:49:46
Copyright (c) 1991, 2013, Oracle. All rights reserved.
Connecting to (DESCRIPTION=(ADDRESS=(PROTOCOL=IPC)(KEY=EXTPROC1521)))
STATUS of the LISTENER
------------------------
Alias LISTENER
Version TNSLSNR for Linux: Version 11.2.0.4.0 - Production
Start Date 28-OCT-2020 08:48:59
Uptime 0 days 0 hr. 0 min. 47 sec
Trace Level off
Security ON: Local OS Authentication
SNMP OFF
Listener Parameter File /u01/app/oracle/product/11.2.0.4/dbhome_1/network/admin/listener.ora
Listener Log File /u01/app/oracle/diag/tnslsnr/lhr11g/listener/alert/log.xml
Listening Endpoints Summary...
(DESCRIPTION=(ADDRESS=(PROTOCOL=ipc)(KEY=EXTPROC1521)))
(DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=LHR11G)(PORT=1521)))
Services Summary...
Service "LHR11G" has 2 instance(s).
Instance "LHR11G", status UNKNOWN, has 1 handler(s) for this service...
Instance "LHR11G", status READY, has 1 handler(s) for this service...
Service "LHR11GXDB" has 1 instance(s).
Instance "LHR11G", status READY, has 1 handler(s) for this service...
Service "LHR11G_DGB" has 1 instance(s).
Instance "LHR11G", status READY, has 1 handler(s) for this service...
Service "LHR11G_dgmgrl" has 1 instance(s).
Instance "LHR11G", status UNKNOWN, has 1 handler(s) for this service...
Service "dg_taf_lhr" has 1 instance(s).
Instance "LHR11G", status READY, has 1 handler(s) for this service...
The command completed successfully
启动备库过程:
[root@docker36 ~]# docker exec -it LHR11GDG bash
[root@lhr11gdg /]# su - oracle
[oracle@lhr11gdg ~]$ sas
SQL*Plus: Release 11.2.0.4.0 Production on Wed Oct 28 08:43:51 2020
Copyright (c) 1982, 2013, Oracle. All rights reserved.
Connected to an idle instance.
SYS@LHR11GDG> startup
ORACLE instance started.
Total System Global Area 346562560 bytes
Fixed Size 2253144 bytes
Variable Size 209718952 bytes
Database Buffers 130023424 bytes
Redo Buffers 4567040 bytes
Database mounted.
Database opened.
SYS@LHR11GDG> exit
Disconnected from Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
[oracle@lhr11gdg ~]$ lsnrctl start
LSNRCTL for Linux: Version 11.2.0.4.0 - Production on 28-OCT-2020 08:49:05
Copyright (c) 1991, 2013, Oracle. All rights reserved.
Starting /u01/app/oracle/product/11.2.0.4/dbhome_1/bin/tnslsnr: please wait...
TNSLSNR for Linux: Version 11.2.0.4.0 - Production
System parameter file is /u01/app/oracle/product/11.2.0.4/dbhome_1/network/admin/listener.ora
Log messages written to /u01/app/oracle/diag/tnslsnr/lhr11gdg/listener/alert/log.xml
Listening on: (DESCRIPTION=(ADDRESS=(PROTOCOL=ipc)(KEY=EXTPROC1521)))
Listening on: (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=LHR11GDG)(PORT=1521)))
Connecting to (DESCRIPTION=(ADDRESS=(PROTOCOL=IPC)(KEY=EXTPROC1521)))
STATUS of the LISTENER
------------------------
Alias LISTENER
Version TNSLSNR for Linux: Version 11.2.0.4.0 - Production
Start Date 28-OCT-2020 08:49:05
Uptime 0 days 0 hr. 0 min. 0 sec
Trace Level off
Security ON: Local OS Authentication
SNMP OFF
Listener Parameter File /u01/app/oracle/product/11.2.0.4/dbhome_1/network/admin/listener.ora
Listener Log File /u01/app/oracle/diag/tnslsnr/lhr11gdg/listener/alert/log.xml
Listening Endpoints Summary...
(DESCRIPTION=(ADDRESS=(PROTOCOL=ipc)(KEY=EXTPROC1521)))
(DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=LHR11GDG)(PORT=1521)))
Services Summary...
Service "LHR11GDG" has 1 instance(s).
Instance "LHR11GDG", status UNKNOWN, has 1 handler(s) for this service...
Service "LHR11GDG_dgmgrl" has 1 instance(s).
Instance "LHR11GDG", status UNKNOWN, has 1 handler(s) for this service...
The command completed successfully
[oracle@lhr11gdg ~]$ lsnrctl status
LSNRCTL for Linux: Version 11.2.0.4.0 - Production on 28-OCT-2020 08:50:31
Copyright (c) 1991, 2013, Oracle. All rights reserved.
Connecting to (DESCRIPTION=(ADDRESS=(PROTOCOL=IPC)(KEY=EXTPROC1521)))
STATUS of the LISTENER
------------------------
Alias LISTENER
Version TNSLSNR for Linux: Version 11.2.0.4.0 - Production
Start Date 28-OCT-2020 08:49:05
Uptime 0 days 0 hr. 1 min. 26 sec
Trace Level off
Security ON: Local OS Authentication
SNMP OFF
Listener Parameter File /u01/app/oracle/product/11.2.0.4/dbhome_1/network/admin/listener.ora
Listener Log File /u01/app/oracle/diag/tnslsnr/lhr11gdg/listener/alert/log.xml
Listening Endpoints Summary...
(DESCRIPTION=(ADDRESS=(PROTOCOL=ipc)(KEY=EXTPROC1521)))
(DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=LHR11GDG)(PORT=1521)))
Services Summary...
Service "LHR11GDG" has 2 instance(s).
Instance "LHR11GDG", status UNKNOWN, has 1 handler(s) for this service...
Instance "LHR11GDG", status READY, has 1 handler(s) for this service...
Service "LHR11GDG_DGB" has 1 instance(s).
Instance "LHR11GDG", status READY, has 1 handler(s) for this service...
Service "LHR11GDG_dgmgrl" has 1 instance(s).
Instance "LHR11GDG", status UNKNOWN, has 1 handler(s) for this service...
Service "LHR11GXDB" has 1 instance(s).
Instance "LHR11GDG", status READY, has 1 handler(s) for this service...
The command completed successfully
三、测试DG的高可用功能
下面会分别测试DG环境的以下几个功能:
1、验证同步
2、switchover
3、failover
4、fsfo
5、故障切换
3.1 主备同步
主库查询DG情况:
SYS@LHR11G> alter system switch logfile;
System altered.
SYS@LHR11G> alter system switch logfile;
System altered.
SYS@LHR11G> alter system switch logfile;
System altered.
SYS@LHR11G> @dg_info
THREAD# DEST_ID DEST_NAME TARGET DATABASE_MODE STATUS ERROR RECOVERY_MODE DB_UNIQUE_NAME DESTINATION GAP_STATUS CURRENT_SEQ# LAST_ARCHIVED APPLIED_SEQ# APPLIED_SCN
---------- ---------- -------------------- -------------------------------------------- ------------------------------ ------------------ ---------- ---------------------------------------------- --------------- --------------- ---------- ------------ ------------- ------------ ----------------
1 1 LOG_ARCHIVE_DEST_1 LOCAL PRIMARY OPEN VALID IDLE LHR11G 12 11 0
1 2 LOG_ARCHIVE_DEST_2 PHYSICAL STANDBY OPEN_READ-ONLY VALID MANAGED REAL TIME APPLY LHR11GDG lhr11gdg NO GAP 12 11 10 1363798
SYS@LHR11G> @dg_status
THREAD# NAME SEQUENCE# APPLIED FIRST_TIME
---------- --------------- ---------- ------------------ -------------------
1 lhr11gdg 7 YES 2020-10-28 09:45:48
1 lhr11gdg 8 YES 2020-10-28 09:45:51
1 lhr11gdg 9 YES 2020-10-28 09:46:48
1 lhr11gdg 10 YES 2020-10-28 09:55:02
1 lhr11gdg 11 NO 2020-10-28 09:55:06
SYS@LHR11G> create table lhr.testdg as select * from scott.emp;
Table created.
SYS@LHR11G> select count(*) from lhr.testdg;
COUNT(*)
----------
14
备库查询日志应用情况:
SYS@LHR11GDG> @dg_status
THREAD# NAME SEQUENCE# APPLIED FIRST_TIME
---------- ---------------------------------------------------------------------------------------------------- ---------- ------------------ -------------------
1 /u01/app/oracle/flash_recovery_area/LHR11GDG/archivelog/2020_10_28/o1_mf_1_8_hskmd9nq_.arc 8 YES 2020-10-28 09:45:51
1 /u01/app/oracle/flash_recovery_area/LHR11GDG/archivelog/2020_10_28/o1_mf_1_9_hskmvpld_.arc 9 YES 2020-10-28 09:46:48
1 /u01/app/oracle/flash_recovery_area/LHR11GDG/archivelog/2020_10_28/o1_mf_1_10_hskmvtc1_.arc 10 YES 2020-10-28 09:55:02
1 /u01/app/oracle/flash_recovery_area/LHR11GDG/archivelog/2020_10_28/o1_mf_1_11_hskmvvrb_.arc 11 IN-MEMORY 2020-10-28 09:55:06
SYS@LHR11GDG> select count(*) from lhr.testdg;
COUNT(*)
----------
14
可以看到,主备是实时同步的。
3.2 switchover
接下来使用dgmgrl来验证switchover功能。
[oracle@lhr11g ~]$ dgmgrl sys/lhr@lhr11g
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.
Connected.
DGMGRL> show configuration
Configuration - LHR11G
Protection Mode: MaxPerformance
Databases:
LHR11G - Primary database
LHR11GDG - Physical standby database
Fast-Start Failover: DISABLED
Configuration Status:
SUCCESS
DGMGRL> switchover to 'LHR11GDG'
Performing switchover NOW, please wait...
Operation requires a connection to instance "LHR11GDG" on database "LHR11GDG"
Connecting to instance "LHR11GDG"...
Connected.
New primary database "LHR11GDG" is opening...
Operation requires startup of instance "LHR11G" on database "LHR11G"
Starting instance "LHR11G"...
ORACLE instance started.
Database mounted.
Database opened.
Switchover succeeded, new primary is "LHR11GDG"
DGMGRL> show configuration
Configuration - LHR11G
Protection Mode: MaxPerformance
Databases:
LHR11GDG - Primary database
LHR11G - Physical standby database
Fast-Start Failover: DISABLED
Configuration Status:
SUCCESS
可以看到,主备角色已成功切换,接下来验证同步功能。
主库操作,注意此时主库为LHR11GDG:
SYS@LHR11GDG> @dg_info
THREAD# DEST_ID DEST_NAME TARGET DATABASE_MODE STATUS ERROR RECOVERY_MODE DB_UNIQUE_NAME DESTINATION GAP_STATUS CURRENT_SEQ# LAST_ARCHIVED APPLIED_SEQ# APPLIED_SCN
---------- ---------- -------------------- -------------------------------------------- ------------------------------ ------------------ ---------- ---------------------------------------------- --------------- --------------- ---------- ------------ ------------- ------------ ----------------
1 1 LOG_ARCHIVE_DEST_1 LOCAL PRIMARY OPEN VALID IDLE LHR11GDG 18 17 0
1 2 LOG_ARCHIVE_DEST_2 PHYSICAL STANDBY OPEN_READ-ONLY VALID MANAGED REAL TIME APPLY LHR11G lhr11g NO GAP 18 17 16 1384751
SYS@LHR11GDG> @dg_status
THREAD# NAME SEQUENCE# APPLIED FIRST_TIME
---------- ---------------------------------------------------------------------------------------------------- ---------- ------------------ -------------------
1 lhr11g 13 YES 2020-10-28 10:00:22
1 lhr11g 14 YES 2020-10-28 10:00:27
1 lhr11g 15 YES 2020-10-28 10:00:29
1 lhr11g 16 YES 2020-10-28 10:00:32
1 lhr11g 17 NO 2020-10-28 10:00:41
SYS@LHR11GDG> insert into lhr.testdg select * from lhr.testdg;
14 rows created.
SYS@LHR11GDG> commit;
Commit complete.
SYS@LHR11GDG> select count(*) from lhr.testdg;
COUNT(*)
----------
28
备库操作,注意此时备库为LHR11G:
SYS@LHR11G> @dg_status
THREAD# NAME SEQUENCE# APPLIED FIRST_TIME
---------- ---------------------------------------------------------------------------------------------------- ---------- ------------------ -------------------
1 /u01/app/oracle/flash_recovery_area/LHR11G/archivelog/2020_10_28/o1_mf_1_16_hskn6bfj_.arc 16 YES 2020-10-28 10:00:32
1 /u01/app/oracle/flash_recovery_area/LHR11G/archivelog/2020_10_28/o1_mf_1_17_hskn6vql_.arc 17 IN-MEMORY 2020-10-28 10:00:41
SYS@LHR11G> select count(*) from lhr.testdg;
COUNT(*)
----------
28
可以看到,同步功能正常。
3.3 failover
接下来使用dgmgrl来验证failover功能。
[oracle@lhr11g ~]$ dgmgrl sys/lhr@lhr11g
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.
Connected.
DGMGRL> show configuration
Configuration - LHR11G
Protection Mode: MaxPerformance
Databases:
LHR11GDG - Primary database
LHR11G - Physical standby database
Fast-Start Failover: DISABLED
Configuration Status:
SUCCESS
DGMGRL> failover to 'LHR11G'
Performing failover NOW, please wait...
Failover succeeded, new primary is "LHR11G"
DGMGRL> show configuration
Configuration - LHR11G
Protection Mode: MaxPerformance
Databases:
LHR11G - Primary database
LHR11GDG - Physical standby database (disabled)
ORA-16661: the standby database needs to be reinstated
Fast-Start Failover: DISABLED
Configuration Status:
SUCCESS
failover成功,主库变为LHR11G。
接下来需要修复LHR11GDG,重启LHR11GDG到MOUNT状态,再执行reinstate即可。
-- 启动到mount状态
SYS@LHR11GDG> startup force mount
ORACLE instance started.
Total System Global Area 346562560 bytes
Fixed Size 2253144 bytes
Variable Size 209718952 bytes
Database Buffers 130023424 bytes
Redo Buffers 4567040 bytes
Database mounted.
SYS@LHR11GDG>
-- 修复failover后的备库
DGMGRL> show configuration
Configuration - LHR11G
Protection Mode: MaxPerformance
Databases:
LHR11G - Primary database
LHR11GDG - Physical standby database (disabled)
ORA-16661: the standby database needs to be reinstated
Fast-Start Failover: DISABLED
Configuration Status:
SUCCESS
DGMGRL> REINSTATE DATABASE 'LHR11GDG'
Reinstating database "LHR11GDG", please wait...
Operation requires shutdown of instance "LHR11GDG" on database "LHR11GDG"
Shutting down instance "LHR11GDG"...
ORA-01109: database not open
Database dismounted.
ORACLE instance shut down.
Operation requires startup of instance "LHR11GDG" on database "LHR11GDG"
Starting instance "LHR11GDG"...
ORACLE instance started.
Database mounted.
Continuing to reinstate database "LHR11GDG" ...
Reinstatement of database "LHR11GDG" succeeded
DGMGRL> show configuration
Configuration - LHR11G
Protection Mode: MaxPerformance
Databases:
LHR11G - Primary database
LHR11GDG - Physical standby database
Fast-Start Failover: DISABLED
Configuration Status:
SUCCESS
修复成功,主库为LHR11G,备库为LHR11GDG。
3.4 FSFO(Fast-Start Failover)
首先启用Fast-Start Failover:
DGMGRL> show configuration
Configuration - LHR11G
Protection Mode: MaxPerformance
Databases:
LHR11G - Primary database
LHR11GDG - Physical standby database
Fast-Start Failover: DISABLED
Configuration Status:
SUCCESS
DGMGRL> ENABLE FAST_START FAILOVER
Enabled.
DGMGRL> show configuration
Configuration - LHR11G
Protection Mode: MaxPerformance
Databases:
LHR11G - Primary database
LHR11GDG - (*) Physical standby database
Fast-Start Failover: ENABLED
Configuration Status:
SUCCESS
-- 启动观察进程
DGMGRL> stop Observer
Done.
[oracle@lhr11g trace]$ nohup dgmgrl -logfile '/tmp/observer_LHR11G.log' sys/lhr@LHR11GDG "start observer" &
[1] 3753
[oracle@lhr11g trace]$ nohup: ignoring input and appending output to 'nohup.out'
[oracle@lhr11g trace]$
[oracle@lhr11g trace]$
[oracle@lhr11g trace]$ tailf /tmp/observer_LHR11G.log
Observer stopped
Observer started
[W000 10/28 11:13:52.28] Observer started.
DGMGRL> SHOW FAST_START FAILOVER;
Fast-Start Failover: ENABLED
Threshold: 10 seconds
Target: LHR11GDG
Observer: lhr11gdg
Lag Limit: 30 seconds
Shutdown Primary: TRUE
Auto-reinstate: TRUE
Observer Reconnect: (none)
Observer Override: FALSE
Configurable Failover Conditions
Health Conditions:
Corrupted Controlfile YES
Corrupted Dictionary YES
Inaccessible Logfile NO
Stuck Archiver NO
Datafile Offline YES
Oracle Error Conditions:
(none)
接下来,我们shutdown abort掉主库LHR11G,等待10秒后,会发现主备自动切换:
SYS@LHR11G> select sysdate from dual;
SYSDATE
-------------------
2020-10-28 11:16:56
SYS@LHR11G> shutdown abort
ORACLE instance shut down.
从观察者进程的日志查看(/tmp/observer_LHR11G.log):
11:17:11.77 Wednesday, October 28, 2020
Initiating Fast-Start Failover to database "LHR11GDG"...
Performing failover NOW, please wait...
Failover succeeded, new primary is "LHR11GDG"
11:17:16.91 Wednesday, October 28, 2020
查询切换后的DG状态:
[oracle@lhr11g ~]$ dgmgrl sys/lhr@lhr11gdg
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.
Connected.
DGMGRL> show configuration
Configuration - LHR11G
Protection Mode: MaxPerformance
Databases:
LHR11GDG - Primary database
Warning: ORA-16829: fast-start failover configuration is lagging
LHR11G - (*) Physical standby database (disabled)
ORA-16661: the standby database needs to be reinstated
Fast-Start Failover: ENABLED
Configuration Status:
WARNING
FSFO后,在重启LHR11G后,dgmgrl会自动修复(/tmp/observer_LHR11G.log):
[oracle@lhr11g ~]$ sas
SQL*Plus: Release 11.2.0.4.0 Production on Wed Oct 28 11:20:09 2020
Copyright (c) 1982, 2013, Oracle. All rights reserved.
Connected to an idle instance.
SYS@LHR11G> startup mount
ORACLE instance started.
Total System Global Area 325685248 bytes
Fixed Size 2252944 bytes
Variable Size 188747632 bytes
Database Buffers 130023424 bytes
Redo Buffers 4661248 bytes
Database mounted.
SYS@LHR11G> exit
Disconnected from Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
[oracle@lhr11g ~]$ dgmgrl sys/lhr@lhr11gdg
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.
Connected.
DGMGRL> show configuration
Configuration - LHR11G
Protection Mode: MaxPerformance
Databases:
LHR11GDG - Primary database
LHR11G - (*) Physical standby database
Fast-Start Failover: ENABLED
Configuration Status:
ORA-16610: command "REINSTATE DATABASE LHR11G" in progress
DGM-17017: unable to determine configuration status
-- 等待几分钟后自动恢复
DGMGRL> show configuration
Configuration - LHR11G
Protection Mode: MaxPerformance
Databases:
LHR11GDG - Primary database
LHR11G - (*) Physical standby database
Fast-Start Failover: ENABLED
Configuration Status:
SUCCESS
等待几分钟后,DG环境恢复正常,观察者进程的日志输出:
11:20:35.27 Wednesday, October 28, 2020
Initiating reinstatement for database "LHR11G"...
Reinstating database "LHR11G", please wait...
Operation requires shutdown of instance "LHR11G" on database "LHR11G"
Shutting down instance "LHR11G"...
ORA-01109: database not open
Database dismounted.
ORACLE instance shut down.
Operation requires startup of instance "LHR11G" on database "LHR11G"
Starting instance "LHR11G"...
ORACLE instance started.
Database mounted.
Continuing to reinstate database "LHR11G" ...
Reinstatement of database "LHR11G" succeeded
11:21:35.85 Wednesday, October 28, 2020
3.5 故障切换
本文最后一个内容,测试一下DG环境中的自动切换功能。
我们在Windows客户端配置tns如下,包含了TAF透明故障转移:
dg_taf =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = tcp)(HOST = 192.168.68.68)(PORT = 1521))
(ADDRESS = (PROTOCOL = tcp)(HOST = 192.168.68.69)(PORT = 1521))
(LOAD_BALANCE = yes)
(CONNECT_DATA =
(SERVER = DEDICATED)
(SERVICE_NAME = dg_taf_lhr)
(FAILOVER_MODE =
(TYPE = session)
(METHOD = basic)
(RETRIES = 180)
(DELAY = 5)
)
)
)
使用客户端连接:
C:\Users\lhrxxt>sqlplus system/lhr@dg_taf
SQL*Plus: Release 12.1.0.2.0 Production on Wed Oct 28 11:31:50 2020
Copyright (c) 1982, 2014, Oracle. All rights reserved.
Connected to:
Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
SYSTEM@dg_taf> show parameter name
NAME TYPE VALUE
------------------------------------ ---------------------- ------------------------------
cell_offloadgroup_name string
db_file_name_convert string LHR11G, LHR11GDG
db_name string LHR11G
db_unique_name string LHR11GDG
global_names boolean FALSE
instance_name string LHR11GDG
lock_name_space string
log_file_name_convert string LHR11G, LHR11GDG
processor_group_name string
service_names string dg_taf_lhr
SYSTEM@dg_taf>
可见,当前连接到的是LHR11GDG库。
接下来,我们shutdown abort掉LHR11GDG库,后台DG自动进行主备切换,而客户端连接不用改变就可以执行查询,若是SELECT操作一半,那么对客户来说只是中间卡顿,而不会断开操作,如下:
我们重启LHR11GDG库,等待几分钟后,DG环境恢复正常:
DGMGRL> show configuration
Configuration - LHR11G
Protection Mode: MaxPerformance
Databases:
LHR11G - Primary database
LHR11GDG - (*) Physical standby database
Fast-Start Failover: ENABLED
Configuration Status:
SUCCESS
- 点赞
- 收藏
- 关注作者
评论(0)