【DB宝32】Oracle DG环境中主库做闪回操作后,备库如何修复继续同步
2021/4/15 2:30:58
本文主要是介绍【DB宝32】Oracle DG环境中主库做闪回操作后,备库如何修复继续同步,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!
目录
一、下载镜像二、DG环境初始化三、主库做闪回数据库操作四、备库做闪回操作五、查询主备库是否实时同步六、总结
本文介绍一下,在DG环境中,若主库做了闪回数据库的操作后,备库如何通过flashback操作,继续和主库保持同步,而不用重新搭建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 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环境初始化
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 5-- 分别初始化主库和备库 6docker 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 13docker 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 -- 添加网卡 21docker network connect bridge LHR11G 22docker network connect bridge LHR11GDG 25-- 进入容器 26docker exec -it LHR11G bash 27docker exec -it LHR11GDG bash 29-- 分别启动主库、备库和监听 30su - oracle 31lsnrctl start 32sas 33startup
查询目前DG的同步情况:
1-- 查询目前DG部署 2DGMGRL> show configuration 4Configuration - LHR11G Protection Mode: MaxPerformance Databases: LHR11G - Primary database LHR11GDG - Physical standby database 11Fast-Start Failover: DISABLED 13Configuration Status: 14SUCCESS 16-- 主库 17SYS@LHR11G> select flashback_on,db_unique_name,database_role from v$database; 19FLASHBACK_ON DB_UNIQUE_NAME DATABASE_ROLE 20------------------------------------ ------------------------------------------------------------ -------------------------------- 21YES LHR11G PRIMARY 23SYS@LHR11G> alter system switch logfile ; 25System altered. 27SYS@LHR11G> create table lhr.emp1 as select * from scott.emp; 29Table created. 31SYS@LHR11G> select count(*) from lhr.emp1; COUNT(*) 34---------- 37SYS@LHR11G> select current_scn from v$database; 39CURRENT_SCN 40----------- 43-- 备库 45SYS@LHR11GDG> select flashback_on,db_unique_name,database_role from v$database; 47FLASHBACK_ON DB_UNIQUE_NAME DATABASE_ROLE 48------------------------------------ ------------------------------------------------------------ -------------------------------- 49YES LHR11GDG PHYSICAL STANDBY 52SYS@LHR11GDG> select count(*) from lhr.emp1; COUNT(*) 55---------- 58SYS@LHR11GDG> select current_scn from v$database; 60CURRENT_SCN 61-----------
三、主库做闪回数据库操作
1SYS@LHR11G> select current_scn from v$database; 3CURRENT_SCN 4----------- 7SYS@LHR11G> create table lhr.emp2 as select * from scott.emp; 9Table created. 11SYS@LHR11G> startup force mount 12ORACLE instance started. 14Total System Global Area 325685248 bytes 15Fixed Size 2252944 bytes 16Variable Size 188747632 bytes 17Database Buffers 130023424 bytes 18Redo Buffers 4661248 bytes 19Database mounted. 20SYS@LHR11G> flashback database to scn 1363438; 22Flashback complete. 24SYS@LHR11G> alter database open resetlogs; 26Database altered. 28SYS@LHR11G> create table lhr.emp3 as select * from scott.emp; 30Table created.
四、备库做闪回操作
1SYS@LHR11GDG> select count(*) from lhr.emp3; 2select count(*) from lhr.emp3 * 4ERROR at line 1: 5ORA-00942: table or view does not exist 8SYS@LHR11GDG> select count(*) from lhr.emp2; COUNT(*) 11---------- 14SYS@LHR11GDG> select current_scn from v$database; 16CURRENT_SCN 17----------- 20SYS@LHR11GDG> select current_scn from v$database; 22CURRENT_SCN 23-----------
可见,主备关系已经断掉。接下来,对备库进行闪回。
1SYS@LHR11GDG> startup force mount 2ORACLE instance started. 4Total System Global Area 346562560 bytes 5Fixed Size 2253144 bytes 6Variable Size 209718952 bytes 7Database Buffers 130023424 bytes 8Redo Buffers 4567040 bytes 9Database mounted. 10SYS@LHR11GDG> flashback database to scn 1363438; 11flashback database to scn 1363438 12* 13ERROR at line 1: 14ORA-38754: FLASHBACK DATABASE not started; required redo log is not available 15ORA-38762: redo logs needed for SCN 1363064 to SCN 1363438 16ORA-38761: redo log sequence 9 in thread 1, incarnation 7 could not be accessed 18SYS@LHR11GDG> select * from v$flashback_database_log; 20OLDEST_FLASHBACK_SCN OLDEST_FLASHBACK_TI RETENTION_TARGET FLASHBACK_SIZE ESTIMATED_FLASHBACK_SIZE 21-------------------- ------------------- ---------------- -------------- ------------------------ 2020-10-27 16:21:36 1440 104857600 0 24SYS@LHR11GDG> flashback database to scn 1361000; 26Flashback complete. 28SYS@LHR11GDG> alter database open; 30Database altered. 32SYS@LHR11GDG> alter database recover managed standby database using current logfile disconnect from session; 34Database altered. 36SYS@LHR11GDG> select count(*) from lhr.emp3; COUNT(*) 39---------- 42SYS@LHR11GDG> select count(*) from lhr.emp2; 43select count(*) from lhr.emp2 * 45ERROR at line 1: 46ORA-00942: table or view does not exist 49SYS@LHR11GDG> select current_scn from v$database; 51CURRENT_SCN 52-----------
五、查询主备库是否实时同步
1[oracle@lhr11g ~]$ dgmgrl / 2DGMGRL for Linux: Version 11.2.0.4.0 - 64bit Production 4Copyright (c) 2000, 2009, Oracle. All rights reserved. 6Welcome to DGMGRL, type "help" for information. 7Connected. 8DGMGRL> show configuration 10Configuration - LHR11G Protection Mode: MaxPerformance Databases: LHR11G - Primary database LHR11GDG - Physical standby database 17Fast-Start Failover: DISABLED 19Configuration Status: 20SUCCESS 23-- 主库建表 24SYS@LHR11G> create table lhr.emp4 as select * from scott.emp; 26Table created. 28-- 备库查询 29SYS@LHR11GDG> select count(*) from lhr.emp4; COUNT(*) 32----------
DG环境恢复正常。
六、总结
1、在DG环境中,建议对主库和备库都开启闪回数据库的特性,并且设置比较大的闪回恢复区(db_recovery_file_dest_size)。
2、在DG环境中,若主库做了闪回数据库的操作,那么备库必须做相关的闪回操作才能恢复DG的同步关系。
本文结束。
• 微信公众号:DB宝,作者:小麦苗
• 作者博客地址:http://blog.itpub.net/26736162/
• 作者微信:db_bao• 作者QQ:646634621,QQ群:230161599、618766405
• 提供Oracle OCP、OCM、高可用(rac+dg+ogg)和MySQL DBA培训
• 版权所有,欢迎分享本文,转载请保留出处• 若有侵权请联系小麦苗删除
★DB宝分享的IT资料:https://mp.weixin.qq.com/s/Iwsy-zkzwgs8nYkcMz29ag★DB宝笔试面试详解:https://mp.weixin.qq.com/s/Vm5PqNcDcITkOr9cQg6T7w
长按下图识别二维码,关注小麦苗的微信公众号:DB宝,学习最实用的数据库技术。
本文分享自微信公众号 - DB宝(lhrdba)。
如有侵权,请联系 support@oschina.cn 删除。
本文参与“OSC源创计划”,欢迎正在阅读的你也加入,一起分享。
这篇关于【DB宝32】Oracle DG环境中主库做闪回操作后,备库如何修复继续同步的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!
- 2024-11-23增量更新怎么做?-icode9专业技术文章分享
- 2024-11-23压缩包加密方案有哪些?-icode9专业技术文章分享
- 2024-11-23用shell怎么写一个开机时自动同步远程仓库的代码?-icode9专业技术文章分享
- 2024-11-23webman可以同步自己的仓库吗?-icode9专业技术文章分享
- 2024-11-23在 Webman 中怎么判断是否有某命令进程正在运行?-icode9专业技术文章分享
- 2024-11-23如何重置new Swiper?-icode9专业技术文章分享
- 2024-11-23oss直传有什么好处?-icode9专业技术文章分享
- 2024-11-23如何将oss直传封装成一个组件在其他页面调用时都可以使用?-icode9专业技术文章分享
- 2024-11-23怎么使用laravel 11在代码里获取路由列表?-icode9专业技术文章分享
- 2024-11-22怎么实现ansible playbook 备份代码中命名包含时间戳功能?-icode9专业技术文章分享