【DB宝30】使用Docker测试Oracle 11g高可用DG功能
2021/4/10 2:32:48
本文主要是介绍【DB宝30】使用Docker测试Oracle 11g高可用DG功能,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!
目录
一、下载镜像二、初始化环境三、测试DG的高可用功能 3.1 主备同步 3.2 switchover 3.3 failover 3.4 FSFO(Fast-Start Failover) 3.5 故障切换四、重建DG
一、下载镜像
Oracle 11g DG搭建方法参考:【DB宝29】使用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
1nohup docker pull registry.cn-hangzhou.aliyuncs.com/lhrbest/dg_phy_11.2.0.4:1.0 & 2nohup docker pull registry.cn-hangzhou.aliyuncs.com/lhrbest/dg_pri_11.2.0.4:1.0 &
查看镜像:
1[root@docker36 ~]# docker images | grep dg 2registry.cn-hangzhou.aliyuncs.com/lhrbest/dg_phy_11.2.0.4 1.0 f2ea019fe540 15 hours ago 10.7GB 3registry.cn-hangzhou.aliyuncs.com/lhrbest/dg_pri_11.2.0.4 1.0 b7fae2029b40 15 hours ago 10.8GB
给镜像打tag:
1[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 2[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 3 4[root@docker36 ~]# docker images | grep dg 5lhrbest/dg_phy_11.2.0.4 1.0 f2ea019fe540 15 hours ago 10.7GB 6registry.cn-hangzhou.aliyuncs.com/lhrbest/dg_phy_11.2.0.4 1.0 f2ea019fe540 15 hours ago 10.7GB 7lhrbest/dg_pri_11.2.0.4 1.0 b7fae2029b40 15 hours ago 10.8GB 8registry.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 |
1-- 创建DG的网络 2docker network create --subnet=192.168.68.0/16 mhalhr 3docker network inspect mhalhr 4 5-- 分别初始化主库和备库 6docker run -itd --name LHR11G -h LHR11G \ 7 -p 1528:1521 -p 1128:1158 -p 228:22 -p 3398:3389 \ 8 --network mhalhr --ip 192.168.68.68 \ 9 --privileged=true \ 10 lhrbest/dg_pri_11.2.0.4:1.0 init 11 12 13docker run -itd --name LHR11GDG -h LHR11GDG \ 14 -p 1529:1521 -p 1129:1158 -p 229:22 -p 3399:3389 \ 15 --network mhalhr --ip 192.168.68.69 \ 16 --privileged=true \ 17 lhrbest/dg_phy_11.2.0.4:1.0 init 18 19 20 -- 添加网卡 21docker network connect bridge LHR11G 22docker network connect bridge LHR11GDG 23 24 25-- 进入容器 26docker exec -it LHR11G bash 27docker exec -it LHR11GDG bash 28 29-- 分别启动主库、备库和监听 30su - oracle 31lsnrctl start 32sas 33startup
启动主库过程:
1[root@docker36 ~]# docker exec -it LHR11G bash 2[root@lhr11g /]# su - oracle 3[oracle@lhr11g ~]$ sas 4 5SQL*Plus: Release 11.2.0.4.0 Production on Wed Oct 28 08:43:43 2020 6 7Copyright (c) 1982, 2013, Oracle. All rights reserved. 8 9Connected to an idle instance. 10 11SYS@LHR11G> startup 12ORACLE instance started. 13 14Total System Global Area 325685248 bytes 15Fixed Size 2252944 bytes 16Variable Size 188747632 bytes 17Database Buffers 130023424 bytes 18Redo Buffers 4661248 bytes 19Database mounted. 20Database opened. 21SYS@LHR11G> exit 22Disconnected from Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit Production 23With the Partitioning, OLAP, Data Mining and Real Application Testing options 24[oracle@lhr11g ~]$ lsnrctl start 25 26LSNRCTL for Linux: Version 11.2.0.4.0 - Production on 28-OCT-2020 08:48:58 27 28Copyright (c) 1991, 2013, Oracle. All rights reserved. 29 30Starting /u01/app/oracle/product/11.2.0.4/dbhome_1/bin/tnslsnr: please wait... 31 32TNSLSNR for Linux: Version 11.2.0.4.0 - Production 33System parameter file is /u01/app/oracle/product/11.2.0.4/dbhome_1/network/admin/listener.ora 34Log messages written to /u01/app/oracle/diag/tnslsnr/lhr11g/listener/alert/log.xml 35Listening on: (DESCRIPTION=(ADDRESS=(PROTOCOL=ipc)(KEY=EXTPROC1521))) 36Listening on: (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=LHR11G)(PORT=1521))) 37 38Connecting to (DESCRIPTION=(ADDRESS=(PROTOCOL=IPC)(KEY=EXTPROC1521))) 39STATUS of the LISTENER 40------------------------ 41Alias LISTENER 42Version TNSLSNR for Linux: Version 11.2.0.4.0 - Production 43Start Date 28-OCT-2020 08:48:59 44Uptime 0 days 0 hr. 0 min. 0 sec 45Trace Level off 46Security ON: Local OS Authentication 47SNMP OFF 48Listener Parameter File /u01/app/oracle/product/11.2.0.4/dbhome_1/network/admin/listener.ora 49Listener Log File /u01/app/oracle/diag/tnslsnr/lhr11g/listener/alert/log.xml 50Listening Endpoints Summary... 51 (DESCRIPTION=(ADDRESS=(PROTOCOL=ipc)(KEY=EXTPROC1521))) 52 (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=LHR11G)(PORT=1521))) 53Services Summary... 54Service "LHR11G" has 1 instance(s). 55 Instance "LHR11G", status UNKNOWN, has 1 handler(s) for this service... 56Service "LHR11G_dgmgrl" has 1 instance(s). 57 Instance "LHR11G", status UNKNOWN, has 1 handler(s) for this service... 58The command completed successfully 59[oracle@lhr11g ~]$ lsnrctl status 60 61LSNRCTL for Linux: Version 11.2.0.4.0 - Production on 28-OCT-2020 08:49:46 62 63Copyright (c) 1991, 2013, Oracle. All rights reserved. 64 65Connecting to (DESCRIPTION=(ADDRESS=(PROTOCOL=IPC)(KEY=EXTPROC1521))) 66STATUS of the LISTENER 67------------------------ 68Alias LISTENER 69Version TNSLSNR for Linux: Version 11.2.0.4.0 - Production 70Start Date 28-OCT-2020 08:48:59 71Uptime 0 days 0 hr. 0 min. 47 sec 72Trace Level off 73Security ON: Local OS Authentication 74SNMP OFF 75Listener Parameter File /u01/app/oracle/product/11.2.0.4/dbhome_1/network/admin/listener.ora 76Listener Log File /u01/app/oracle/diag/tnslsnr/lhr11g/listener/alert/log.xml 77Listening Endpoints Summary... 78 (DESCRIPTION=(ADDRESS=(PROTOCOL=ipc)(KEY=EXTPROC1521))) 79 (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=LHR11G)(PORT=1521))) 80Services Summary... 81Service "LHR11G" has 2 instance(s). 82 Instance "LHR11G", status UNKNOWN, has 1 handler(s) for this service... 83 Instance "LHR11G", status READY, has 1 handler(s) for this service... 84Service "LHR11GXDB" has 1 instance(s). 85 Instance "LHR11G", status READY, has 1 handler(s) for this service... 86Service "LHR11G_DGB" has 1 instance(s). 87 Instance "LHR11G", status READY, has 1 handler(s) for this service... 88Service "LHR11G_dgmgrl" has 1 instance(s). 89 Instance "LHR11G", status UNKNOWN, has 1 handler(s) for this service... 90Service "dg_taf_lhr" has 1 instance(s). 91 Instance "LHR11G", status READY, has 1 handler(s) for this service... 92The command completed successfully
启动备库过程:
1[root@docker36 ~]# docker exec -it LHR11GDG bash 2[root@lhr11gdg /]# su - oracle 3[oracle@lhr11gdg ~]$ sas 4 5SQL*Plus: Release 11.2.0.4.0 Production on Wed Oct 28 08:43:51 2020 6 7Copyright (c) 1982, 2013, Oracle. All rights reserved. 8 9Connected to an idle instance. 10 11SYS@LHR11GDG> startup 12ORACLE instance started. 13 14Total System Global Area 346562560 bytes 15Fixed Size 2253144 bytes 16Variable Size 209718952 bytes 17Database Buffers 130023424 bytes 18Redo Buffers 4567040 bytes 19Database mounted. 20Database opened. 21SYS@LHR11GDG> exit 22Disconnected from Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit Production 23With the Partitioning, OLAP, Data Mining and Real Application Testing options 24[oracle@lhr11gdg ~]$ lsnrctl start 25 26LSNRCTL for Linux: Version 11.2.0.4.0 - Production on 28-OCT-2020 08:49:05 27 28Copyright (c) 1991, 2013, Oracle. All rights reserved. 29 30Starting /u01/app/oracle/product/11.2.0.4/dbhome_1/bin/tnslsnr: please wait... 31 32TNSLSNR for Linux: Version 11.2.0.4.0 - Production 33System parameter file is /u01/app/oracle/product/11.2.0.4/dbhome_1/network/admin/listener.ora 34Log messages written to /u01/app/oracle/diag/tnslsnr/lhr11gdg/listener/alert/log.xml 35Listening on: (DESCRIPTION=(ADDRESS=(PROTOCOL=ipc)(KEY=EXTPROC1521))) 36Listening on: (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=LHR11GDG)(PORT=1521))) 37 38Connecting to (DESCRIPTION=(ADDRESS=(PROTOCOL=IPC)(KEY=EXTPROC1521))) 39STATUS of the LISTENER 40------------------------ 41Alias LISTENER 42Version TNSLSNR for Linux: Version 11.2.0.4.0 - Production 43Start Date 28-OCT-2020 08:49:05 44Uptime 0 days 0 hr. 0 min. 0 sec 45Trace Level off 46Security ON: Local OS Authentication 47SNMP OFF 48Listener Parameter File /u01/app/oracle/product/11.2.0.4/dbhome_1/network/admin/listener.ora 49Listener Log File /u01/app/oracle/diag/tnslsnr/lhr11gdg/listener/alert/log.xml 50Listening Endpoints Summary... 51 (DESCRIPTION=(ADDRESS=(PROTOCOL=ipc)(KEY=EXTPROC1521))) 52 (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=LHR11GDG)(PORT=1521))) 53Services Summary... 54Service "LHR11GDG" has 1 instance(s). 55 Instance "LHR11GDG", status UNKNOWN, has 1 handler(s) for this service... 56Service "LHR11GDG_dgmgrl" has 1 instance(s). 57 Instance "LHR11GDG", status UNKNOWN, has 1 handler(s) for this service... 58The command completed successfully 59[oracle@lhr11gdg ~]$ lsnrctl status 60 61LSNRCTL for Linux: Version 11.2.0.4.0 - Production on 28-OCT-2020 08:50:31 62 63Copyright (c) 1991, 2013, Oracle. All rights reserved. 64 65Connecting to (DESCRIPTION=(ADDRESS=(PROTOCOL=IPC)(KEY=EXTPROC1521))) 66STATUS of the LISTENER 67------------------------ 68Alias LISTENER 69Version TNSLSNR for Linux: Version 11.2.0.4.0 - Production 70Start Date 28-OCT-2020 08:49:05 71Uptime 0 days 0 hr. 1 min. 26 sec 72Trace Level off 73Security ON: Local OS Authentication 74SNMP OFF 75Listener Parameter File /u01/app/oracle/product/11.2.0.4/dbhome_1/network/admin/listener.ora 76Listener Log File /u01/app/oracle/diag/tnslsnr/lhr11gdg/listener/alert/log.xml 77Listening Endpoints Summary... 78 (DESCRIPTION=(ADDRESS=(PROTOCOL=ipc)(KEY=EXTPROC1521))) 79 (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=LHR11GDG)(PORT=1521))) 80Services Summary... 81Service "LHR11GDG" has 2 instance(s). 82 Instance "LHR11GDG", status UNKNOWN, has 1 handler(s) for this service... 83 Instance "LHR11GDG", status READY, has 1 handler(s) for this service... 84Service "LHR11GDG_DGB" has 1 instance(s). 85 Instance "LHR11GDG", status READY, has 1 handler(s) for this service... 86Service "LHR11GDG_dgmgrl" has 1 instance(s). 87 Instance "LHR11GDG", status UNKNOWN, has 1 handler(s) for this service... 88Service "LHR11GXDB" has 1 instance(s). 89 Instance "LHR11GDG", status READY, has 1 handler(s) for this service... 90The command completed successfully
三、测试DG的高可用功能
下面会分别测试DG环境的以下几个功能:
1、验证同步
2、switchover
3、failover
4、fsfo
5、故障切换
3.1 主备同步
主库查询DG情况:
1SYS@LHR11G> alter system switch logfile; 2 3System altered. 4 5SYS@LHR11G> alter system switch logfile; 6 7System altered. 8 9SYS@LHR11G> alter system switch logfile; 10 11System altered. 12 13SYS@LHR11G> @dg_info 14 15 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 16---------- ---------- -------------------- -------------------------------------------- ------------------------------ ------------------ ---------- ---------------------------------------------- --------------- --------------- ---------- ------------ ------------- ------------ ---------------- 17 1 1 LOG_ARCHIVE_DEST_1 LOCAL PRIMARY OPEN VALID IDLE LHR11G 12 11 0 18 1 2 LOG_ARCHIVE_DEST_2 PHYSICAL STANDBY OPEN_READ-ONLY VALID MANAGED REAL TIME APPLY LHR11GDG lhr11gdg NO GAP 12 11 10 1363798 19 20SYS@LHR11G> @dg_status 21 22 THREAD# NAME SEQUENCE# APPLIED FIRST_TIME 23---------- --------------- ---------- ------------------ ------------------- 24 1 lhr11gdg 7 YES 2020-10-28 09:45:48 25 1 lhr11gdg 8 YES 2020-10-28 09:45:51 26 1 lhr11gdg 9 YES 2020-10-28 09:46:48 27 1 lhr11gdg 10 YES 2020-10-28 09:55:02 28 1 lhr11gdg 11 NO 2020-10-28 09:55:06 29 30SYS@LHR11G> create table lhr.testdg as select * from scott.emp; 31 32Table created. 33 34SYS@LHR11G> select count(*) from lhr.testdg; 35 36 COUNT(*) 37---------- 38 14
备库查询日志应用情况:
1SYS@LHR11GDG> @dg_status 2 3 THREAD# NAME SEQUENCE# APPLIED FIRST_TIME 4---------- ---------------------------------------------------------------------------------------------------- ---------- ------------------ ------------------- 5 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 6 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 7 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 8 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 9SYS@LHR11GDG> select count(*) from lhr.testdg; 10 11 COUNT(*) 12---------- 13 14
可以看到,主备是实时同步的。
3.2 switchover
接下来使用dgmgrl来验证switchover功能。
1[oracle@lhr11g ~]$ dgmgrl sys/lhr@lhr11g 2DGMGRL for Linux: Version 11.2.0.4.0 - 64bit Production 3 4Copyright (c) 2000, 2009, Oracle. All rights reserved. 5 6Welcome to DGMGRL, type "help" for information. 7Connected. 8DGMGRL> show configuration 9 10Configuration - LHR11G 11 12 Protection Mode: MaxPerformance 13 Databases: 14 LHR11G - Primary database 15 LHR11GDG - Physical standby database 16 17Fast-Start Failover: DISABLED 18 19Configuration Status: 20SUCCESS 21DGMGRL> switchover to 'LHR11GDG' 22Performing switchover NOW, please wait... 23Operation requires a connection to instance "LHR11GDG" on database "LHR11GDG" 24Connecting to instance "LHR11GDG"... 25Connected. 26New primary database "LHR11GDG" is opening... 27Operation requires startup of instance "LHR11G" on database "LHR11G" 28Starting instance "LHR11G"... 29ORACLE instance started. 30Database mounted. 31Database opened. 32Switchover succeeded, new primary is "LHR11GDG" 33DGMGRL> show configuration 34 35Configuration - LHR11G 36 37 Protection Mode: MaxPerformance 38 Databases: 39 LHR11GDG - Primary database 40 LHR11G - Physical standby database 41 42Fast-Start Failover: DISABLED 43 44Configuration Status: 45SUCCESS 46
可以看到,主备角色已成功切换,接下来验证同步功能。
主库操作,注意此时主库为LHR11GDG:
1SYS@LHR11GDG> @dg_info 2 3 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 4---------- ---------- -------------------- -------------------------------------------- ------------------------------ ------------------ ---------- ---------------------------------------------- --------------- --------------- ---------- ------------ ------------- ------------ ---------------- 5 1 1 LOG_ARCHIVE_DEST_1 LOCAL PRIMARY OPEN VALID IDLE LHR11GDG 18 17 0 6 1 2 LOG_ARCHIVE_DEST_2 PHYSICAL STANDBY OPEN_READ-ONLY VALID MANAGED REAL TIME APPLY LHR11G lhr11g NO GAP 18 17 16 1384751 7 8SYS@LHR11GDG> @dg_status 9 10 THREAD# NAME SEQUENCE# APPLIED FIRST_TIME 11---------- ---------------------------------------------------------------------------------------------------- ---------- ------------------ ------------------- 12 1 lhr11g 13 YES 2020-10-28 10:00:22 13 1 lhr11g 14 YES 2020-10-28 10:00:27 14 1 lhr11g 15 YES 2020-10-28 10:00:29 15 1 lhr11g 16 YES 2020-10-28 10:00:32 16 1 lhr11g 17 NO 2020-10-28 10:00:41 17 18SYS@LHR11GDG> insert into lhr.testdg select * from lhr.testdg; 19 2014 rows created. 21 22SYS@LHR11GDG> commit; 23 24Commit complete. 25 26SYS@LHR11GDG> select count(*) from lhr.testdg; 27 28 COUNT(*) 29---------- 30 28
备库操作,注意此时备库为LHR11G:
1SYS@LHR11G> @dg_status 2 3 THREAD# NAME SEQUENCE# APPLIED FIRST_TIME 4---------- ---------------------------------------------------------------------------------------------------- ---------- ------------------ ------------------- 5 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 6 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 7 8SYS@LHR11G> select count(*) from lhr.testdg; 9 10 COUNT(*) 11---------- 12 28
可以看到,同步功能正常。
3.3 failover
接下来使用dgmgrl来验证failover功能。
1[oracle@lhr11g ~]$ dgmgrl sys/lhr@lhr11g 2DGMGRL for Linux: Version 11.2.0.4.0 - 64bit Production 3 4Copyright (c) 2000, 2009, Oracle. All rights reserved. 5 6Welcome to DGMGRL, type "help" for information. 7Connected. 8DGMGRL> show configuration 9 10Configuration - LHR11G 11 12 Protection Mode: MaxPerformance 13 Databases: 14 LHR11GDG - Primary database 15 LHR11G - Physical standby database 16 17Fast-Start Failover: DISABLED 18 19Configuration Status: 20SUCCESS 21 22DGMGRL> failover to 'LHR11G' 23Performing failover NOW, please wait... 24Failover succeeded, new primary is "LHR11G" 25DGMGRL> show configuration 26 27Configuration - LHR11G 28 29 Protection Mode: MaxPerformance 30 Databases: 31 LHR11G - Primary database 32 LHR11GDG - Physical standby database (disabled) 33 ORA-16661: the standby database needs to be reinstated 34 35Fast-Start Failover: DISABLED 36 37Configuration Status: 38SUCCESS 39
failover成功,主库变为LHR11G。
接下来需要修复LHR11GDG,重启LHR11GDG到MOUNT状态,再执行reinstate即可。
1-- 启动到mount状态 2SYS@LHR11GDG> startup force mount 3ORACLE instance started. 4 5Total System Global Area 346562560 bytes 6Fixed Size 2253144 bytes 7Variable Size 209718952 bytes 8Database Buffers 130023424 bytes 9Redo Buffers 4567040 bytes 10Database mounted. 11SYS@LHR11GDG> 12 13-- 修复failover后的备库 14 15DGMGRL> show configuration 16 17Configuration - LHR11G 18 19 Protection Mode: MaxPerformance 20 Databases: 21 LHR11G - Primary database 22 LHR11GDG - Physical standby database (disabled) 23 ORA-16661: the standby database needs to be reinstated 24 25Fast-Start Failover: DISABLED 26 27Configuration Status: 28SUCCESS 29 30DGMGRL> REINSTATE DATABASE 'LHR11GDG' 31Reinstating database "LHR11GDG", please wait... 32Operation requires shutdown of instance "LHR11GDG" on database "LHR11GDG" 33Shutting down instance "LHR11GDG"... 34ORA-01109: database not open 35 36Database dismounted. 37ORACLE instance shut down. 38Operation requires startup of instance "LHR11GDG" on database "LHR11GDG" 39Starting instance "LHR11GDG"... 40ORACLE instance started. 41Database mounted. 42Continuing to reinstate database "LHR11GDG" ... 43Reinstatement of database "LHR11GDG" succeeded 44DGMGRL> show configuration 45 46Configuration - LHR11G 47 48 Protection Mode: MaxPerformance 49 Databases: 50 LHR11G - Primary database 51 LHR11GDG - Physical standby database 52 53Fast-Start Failover: DISABLED 54 55Configuration Status: 56SUCCESS
修复成功,主库为LHR11G,备库为LHR11GDG。
3.4 FSFO(Fast-Start Failover)
首先启用Fast-Start Failover:
1DGMGRL> show configuration 2 3Configuration - LHR11G 4 5 Protection Mode: MaxPerformance 6 Databases: 7 LHR11G - Primary database 8 LHR11GDG - Physical standby database 9 10Fast-Start Failover: DISABLED 11 12Configuration Status: 13SUCCESS 14 15DGMGRL> ENABLE FAST_START FAILOVER 16Enabled. 17DGMGRL> show configuration 18 19Configuration - LHR11G 20 21 Protection Mode: MaxPerformance 22 Databases: 23 LHR11G - Primary database 24 LHR11GDG - (*) Physical standby database 25 26Fast-Start Failover: ENABLED 27 28Configuration Status: 29SUCCESS 30 31-- 启动观察进程 32DGMGRL> stop Observer 33Done. 34[oracle@lhr11g trace]$ nohup dgmgrl -logfile '/tmp/observer_LHR11G.log' sys/lhr@LHR11GDG "start observer" & 35[1] 3753 36[oracle@lhr11g trace]$ nohup: ignoring input and appending output to 'nohup.out' 37 38[oracle@lhr11g trace]$ 39[oracle@lhr11g trace]$ 40[oracle@lhr11g trace]$ tailf /tmp/observer_LHR11G.log 41Observer stopped 42Observer started 43[W000 10/28 11:13:52.28] Observer started. 44 45 46 47DGMGRL> SHOW FAST_START FAILOVER; 48 49Fast-Start Failover: ENABLED 50 51 Threshold: 10 seconds 52 Target: LHR11GDG 53 Observer: lhr11gdg 54 Lag Limit: 30 seconds 55 Shutdown Primary: TRUE 56 Auto-reinstate: TRUE 57 Observer Reconnect: (none) 58 Observer Override: FALSE 59 60Configurable Failover Conditions 61 Health Conditions: 62 Corrupted Controlfile YES 63 Corrupted Dictionary YES 64 Inaccessible Logfile NO 65 Stuck Archiver NO 66 Datafile Offline YES 67 68 Oracle Error Conditions: 69 (none)
接下来,我们shutdown abort掉主库LHR11G,等待10秒后,会发现主备自动切换:
1SYS@LHR11G> select sysdate from dual; 2 3SYSDATE 4------------------- 52020-10-28 11:16:56 6 7 8SYS@LHR11G> shutdown abort 9ORACLE instance shut down.
从观察者进程的日志查看(/tmp/observer_LHR11G.log):
111:17:11.77 Wednesday, October 28, 2020 2Initiating Fast-Start Failover to database "LHR11GDG"... 3Performing failover NOW, please wait... 4Failover succeeded, new primary is "LHR11GDG" 511:17:16.91 Wednesday, October 28, 2020
查询切换后的DG状态:
1[oracle@lhr11g ~]$ dgmgrl sys/lhr@lhr11gdg 2DGMGRL for Linux: Version 11.2.0.4.0 - 64bit Production 3 4Copyright (c) 2000, 2009, Oracle. All rights reserved. 5 6Welcome to DGMGRL, type "help" for information. 7Connected. 8DGMGRL> show configuration 9 10Configuration - LHR11G 11 12 Protection Mode: MaxPerformance 13 Databases: 14 LHR11GDG - Primary database 15 Warning: ORA-16829: fast-start failover configuration is lagging 16 17 LHR11G - (*) Physical standby database (disabled) 18 ORA-16661: the standby database needs to be reinstated 19 20Fast-Start Failover: ENABLED 21 22Configuration Status: 23WARNING 24
FSFO后,在重启LHR11G后,dgmgrl会自动修复(/tmp/observer_LHR11G.log):
1[oracle@lhr11g ~]$ sas 2 3SQL*Plus: Release 11.2.0.4.0 Production on Wed Oct 28 11:20:09 2020 4 5Copyright (c) 1982, 2013, Oracle. All rights reserved. 6 7Connected to an idle instance. 8 9SYS@LHR11G> startup mount 10ORACLE instance started. 11 12Total System Global Area 325685248 bytes 13Fixed Size 2252944 bytes 14Variable Size 188747632 bytes 15Database Buffers 130023424 bytes 16Redo Buffers 4661248 bytes 17Database mounted. 18SYS@LHR11G> exit 19Disconnected from Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit Production 20With the Partitioning, OLAP, Data Mining and Real Application Testing options 21[oracle@lhr11g ~]$ dgmgrl sys/lhr@lhr11gdg 22DGMGRL for Linux: Version 11.2.0.4.0 - 64bit Production 23 24Copyright (c) 2000, 2009, Oracle. All rights reserved. 25 26Welcome to DGMGRL, type "help" for information. 27Connected. 28DGMGRL> show configuration 29 30Configuration - LHR11G 31 32 Protection Mode: MaxPerformance 33 Databases: 34 LHR11GDG - Primary database 35 LHR11G - (*) Physical standby database 36 37Fast-Start Failover: ENABLED 38 39Configuration Status: 40ORA-16610: command "REINSTATE DATABASE LHR11G" in progress 41DGM-17017: unable to determine configuration status 42 43-- 等待几分钟后自动恢复 44DGMGRL> show configuration 45 46Configuration - LHR11G 47 48 Protection Mode: MaxPerformance 49 Databases: 50 LHR11GDG - Primary database 51 LHR11G - (*) Physical standby database 52 53Fast-Start Failover: ENABLED 54 55Configuration Status: 56SUCCESS
等待几分钟后,DG环境恢复正常,观察者进程的日志输出:
111:20:35.27 Wednesday, October 28, 2020 2Initiating reinstatement for database "LHR11G"... 3Reinstating database "LHR11G", please wait... 4Operation requires shutdown of instance "LHR11G" on database "LHR11G" 5Shutting down instance "LHR11G"... 6ORA-01109: database not open 7 8Database dismounted. 9ORACLE instance shut down. 10Operation requires startup of instance "LHR11G" on database "LHR11G" 11Starting instance "LHR11G"... 12ORACLE instance started. 13Database mounted. 14Continuing to reinstate database "LHR11G" ... 15Reinstatement of database "LHR11G" succeeded 1611:21:35.85 Wednesday, October 28, 2020
3.5 故障切换
本文最后一个内容,测试一下DG环境中的自动切换功能。
我们在Windows客户端配置tns如下,包含了TAF透明故障转移:
1dg_taf = 2 (DESCRIPTION = 3 (ADDRESS = (PROTOCOL = tcp)(HOST = 192.168.68.68)(PORT = 1521)) 4 (ADDRESS = (PROTOCOL = tcp)(HOST = 192.168.68.69)(PORT = 1521)) 5 (LOAD_BALANCE = yes) 6 (CONNECT_DATA = 7 (SERVER = DEDICATED) 8 (SERVICE_NAME = dg_taf_lhr) 9 (FAILOVER_MODE = 10 (TYPE = session) 11 (METHOD = basic) 12 (RETRIES = 180) 13 (DELAY = 5) 14 ) 15 ) 16 )
使用客户端连接:
1C:\Users\lhrxxt>sqlplus system/lhr@dg_taf 2 3SQL*Plus: Release 12.1.0.2.0 Production on Wed Oct 28 11:31:50 2020 4 5Copyright (c) 1982, 2014, Oracle. All rights reserved. 6 7 8Connected to: 9Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit Production 10With the Partitioning, OLAP, Data Mining and Real Application Testing options 11 12SYSTEM@dg_taf> show parameter name 13 14NAME TYPE VALUE 15------------------------------------ ---------------------- ------------------------------ 16cell_offloadgroup_name string 17db_file_name_convert string LHR11G, LHR11GDG 18db_name string LHR11G 19db_unique_name string LHR11GDG 20global_names boolean FALSE 21instance_name string LHR11GDG 22lock_name_space string 23log_file_name_convert string LHR11G, LHR11GDG 24processor_group_name string 25service_names string dg_taf_lhr 26SYSTEM@dg_taf>
可见,当前连接到的是LHR11GDG库。
接下来,我们shutdown abort掉LHR11GDG库,后台DG自动进行主备切换,而客户端连接不用改变就可以执行查询,若是SELECT操作一半,那么对客户来说只是中间卡顿,而不会断开操作,如下:
我们重启LHR11GDG库,等待几分钟后,DG环境恢复正常:
1DGMGRL> show configuration 2 3Configuration - LHR11G 4 5 Protection Mode: MaxPerformance 6 Databases: 7 LHR11G - Primary database 8 LHR11GDG - (*) Physical standby database 9 10Fast-Start Failover: ENABLED 11 12Configuration Status: 13SUCCESS
四、重建DG
如果由于特殊原因导致备库不可用,必须进行重建,那么可以使用如下过程直接进行重建DG。
1startup force nomount 2 3rman target sys/lhr@LHR11G auxiliary sys/lhr@LHR11GDG 4 5duplicate target database 6for standby nofilenamecheck 7from active database 8DORECOVER 9; 10 11 12alter database flashback on;
若想学习DG其他更详细的内容,请咨询麦老师。
本文结束。
这篇关于【DB宝30】使用Docker测试Oracle 11g高可用DG功能的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!
- 2024-11-19Docker-Compose容器集群化项目实战:新手入门指南
- 2024-11-19Docker镜像仓库项目实战:新手入门教程
- 2024-11-19Docker容器化部署项目实战:新手入门教程
- 2024-11-19Docker-Compose容器集群化资料入门教程
- 2024-11-19Docker镜像仓库资料详解:新手入门教程
- 2024-11-19Docker容器化部署资料:新手入门指南
- 2024-11-19Docker-Compose容器集群化教程:从入门到实践
- 2024-11-19Docker镜像仓库教程:新手入门指南
- 2024-11-19Docker容器化部署教程:初学者指南
- 2024-11-18Docker-Compose容器集群化入门教程