m6米乐安卓版下载-米乐app官网下载
暂无图片
5

rman增量恢复dataguard备库 -m6米乐安卓版下载

原创 孙莹 2023-12-24
632

前言

在生产环境中有时候会出现由于网络或者人为删除等原因,导致主库的archivelog文件还没有传到备库,产生gaps。那么我们有没有办法不重建备库来恢复dataguard环境那?答案是当然的,oraclem6米乐安卓版下载官网的oracle data guard concepts and administration文档中记录着在这种情况下,您可以使用rman的增量备份前滚物理备用数据库。下面我们就来演练一下
dataguard.png

环境准备

准备两台已经配置好dataguard环境的虚拟机

主机名 ip地址 操作系统 数据库版本 sid
11g-primary 192.168.17.91 centos 7.9 oracle 11.2.0.4 orcl
11g-standby 192.168.17.92 centos 7.9 oracle 11.2.0.4 orcldg

主库

[oracle@11g-primary ~]$ sqlplus / as sysdba sql*plus: release 11.2.0.4.0 production on sat dec 23 22:56:11 2023 米乐app官网下载 copyright (c) 1982, 2013, 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 sql> archive log list database log mode archive mode automatic archival enabled archive destination /arch/ oldest online log sequence 85 next log sequence to archive 87 current log sequence 87 sql> select database_role,protection_mode,open_mode from v$database; database_role protection_mode open_mode ---------------- -------------------- -------------------- primary maximum performance read write sql> select count(1) from sunying.t; count(1) ---------- 1280000 sql>

备库

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@11g-standby ~]$ sqlplus / as sysdba sql*plus: release 11.2.0.4.0 production on sat dec 23 22:57:06 2023 米乐app官网下载 copyright (c) 1982, 2013, 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 sql> archive log list database log mode archive mode automatic archival enabled archive destination /arch/ oldest online log sequence 85 next log sequence to archive 0 current log sequence 87 sql> select database_role,protection_mode,open_mode from v$database; database_role protection_mode open_mode ---------------- -------------------- -------------------- physical standby maximum performance read only with apply sql> select count(1) from sunying.t; count(1) ---------- 1280000 sql>

模拟主库丢失归档的情况

--在主库操作 sql> set linesize 200 sql> select * from v$log; group# thread# sequence# bytes blocksize members arc status first_change# first_time next_change# next_time ---------- ---------- ---------- ---------- ---------- ---------- --- ---------------- ------------- ------------------- ------------ ------------------- 1 1 85 52428800 512 1 yes inactive 907056 2023-12-23 22:54:47 907128 2023-12-23 22:54:50 2 1 86 52428800 512 1 yes inactive 907128 2023-12-23 22:54:50 907209 2023-12-23 22:54:53 3 1 87 52428800 512 1 no current 907209 2023-12-23 22:54:53 2.8147e 14 sql> alter system set log_archive_dest_state_2 = 'defer'; system altered. sql> insert into sunying.t select * from sunying.t; 1280000 rows created. sql> commit; commit complete. sql> select count(1) from sunying.t; count(1) ---------- 2560000 sql> alter system switch logfile; system altered. sql> / system altered. sql> / system altered. sql> ! [oracle@11g-primary ~]$ cd /arch [oracle@11g-primary arch]$ ll total 1008684 -rw-r----- 1 oracle oinstall 45707264 dec 23 20:18 1_71_1156360815.dbf -rw-r----- 1 oracle oinstall 40260608 dec 23 20:21 1_72_1156360815.dbf -rw-r----- 1 oracle oinstall 43447296 dec 23 20:23 1_73_1156360815.dbf -rw-r----- 1 oracle oinstall 40251392 dec 23 20:24 1_74_1156360815.dbf -rw-r----- 1 oracle oinstall 41733120 dec 23 20:25 1_75_1156360815.dbf -rw-r----- 1 oracle oinstall 22571520 dec 23 20:56 1_76_1156360815.dbf -rw-r----- 1 oracle oinstall 1024 dec 23 20:58 1_77_1156360815.dbf -rw-r----- 1 oracle oinstall 1536 dec 23 20:58 1_78_1156360815.dbf -rw-r----- 1 oracle oinstall 46794240 dec 23 22:54 1_79_1156360815.dbf -rw-r----- 1 oracle oinstall 46794240 dec 23 22:54 1_80_1156360815.dbf -rw-r----- 1 oracle oinstall 46794240 dec 23 22:54 1_81_1156360815.dbf -rw-r----- 1 oracle oinstall 49025536 dec 23 22:54 1_82_1156360815.dbf -rw-r----- 1 oracle oinstall 46794240 dec 23 22:54 1_83_1156360815.dbf -rw-r----- 1 oracle oinstall 46798848 dec 23 22:54 1_84_1156360815.dbf -rw-r----- 1 oracle oinstall 46794240 dec 23 22:54 1_85_1156360815.dbf -rw-r----- 1 oracle oinstall 46794240 dec 23 22:54 1_86_1156360815.dbf -rw-r----- 1 oracle oinstall 46794240 dec 23 23:03 1_87_1156360815.dbf -rw-r----- 1 oracle oinstall 46794240 dec 23 23:03 1_88_1156360815.dbf -rw-r----- 1 oracle oinstall 48705536 dec 23 23:03 1_89_1156360815.dbf -rw-r----- 1 oracle oinstall 46833664 dec 23 23:03 1_90_1156360815.dbf -rw-r----- 1 oracle oinstall 46794240 dec 23 23:03 1_91_1156360815.dbf -rw-r----- 1 oracle oinstall 46794240 dec 23 23:03 1_92_1156360815.dbf -rw-r----- 1 oracle oinstall 46833664 dec 23 23:03 1_93_1156360815.dbf -rw-r----- 1 oracle oinstall 47984128 dec 23 23:03 1_94_1156360815.dbf -rw-r----- 1 oracle oinstall 44584960 dec 23 23:03 1_95_1156360815.dbf -rw-r----- 1 oracle oinstall 116736 dec 23 23:04 1_96_1156360815.dbf -rw-r----- 1 oracle oinstall 38400 dec 23 23:04 1_97_1156360815.dbf -rw-r----- 1 oracle oinstall 2560 dec 23 23:04 1_98_1156360815.dbf [oracle@11g-primary arch]$ rm 1_9*.dbf [oracle@11g-primary arch]$ exit exit sql> delete from sunying.t where rownum<10000; 9999 rows deleted. sql> commit; commit complete. sql> alter system switch logfile; system altered. sql> alter system set log_archive_dest_state_2 = 'enable'; system altered. sql> --备库操作 [oracle@11g-standby ~]$ cd /u01/app/oracle/diag/rdbms/orcldg/orcldg/trace/ [oracle@11g-standby trace]$ tail -f alert_orcldg.log mem# 0: /u01/app/oracle/oradata/orcldg/standby02.log rfs[2]: selected log 4 for thread 1 sequence 87 dbid 1684141551 branch 1156360815 archived log entry 11 added for thread 1 sequence 86 id 0x6461b6ef dest 1: media recovery waiting for thread 1 sequence 87 (in transit) recovery of online redo log: thread 1 group 4 seq 87 reading mem 0 mem# 0: /u01/app/oracle/oradata/orcldg/standby01.log sat dec 23 23:03:14 2023 archived log entry 12 added for thread 1 sequence 87 id 0x6461b6ef dest 1: sat dec 23 23:03:14 2023 media recovery waiting for thread 1 sequence 88 sat dec 23 23:10:16 2023 fetching gap sequence in thread 1, gap sequence 88-88 fal[client]: error fetching gap sequence, no fal server specified sat dec 23 23:10:16 2023 rfs[4]: assigned to rfs process 82281 rfs[4]: opened log for thread 1 sequence 99 dbid 1684141551 branch 1156360815 sat dec 23 23:10:16 2023 rfs[5]: assigned to rfs process 82285 rfs[5]: opened log for thread 1 sequence 88 dbid 1684141551 branch 1156360815 sat dec 23 23:10:16 2023 rfs[6]: assigned to rfs process 82287 rfs[6]: opened log for thread 1 sequence 89 dbid 1684141551 branch 1156360815 archived log entry 13 added for thread 1 sequence 99 rlc 1156360815 id 0x6461b6ef dest 2: archived log entry 14 added for thread 1 sequence 88 rlc 1156360815 id 0x6461b6ef dest 2: archived log entry 15 added for thread 1 sequence 89 rlc 1156360815 id 0x6461b6ef dest 2: media recovery log /arch/1_88_1156360815.dbf media recovery log /arch/1_89_1156360815.dbf media recovery waiting for thread 1 sequence 90 fetching gap sequence in thread 1, gap sequence 90-98 fal[client]: error fetching gap sequence, no fal server specified rfs[6]: selected log 4 for thread 1 sequence 100 dbid 1684141551 branch 1156360815 sat dec 23 23:10:18 2023 archived log entry 16 added for thread 1 sequence 100 id 0x6461b6ef dest 1: sat dec 23 23:10:18 2023 primary database is in maximum performance mode rfs[7]: assigned to rfs process 82295 rfs[7]: selected log 4 for thread 1 sequence 101 dbid 1684141551 branch 1156360815 fal[client]: error fetching gap sequence, no fal server specified sat dec 23 23:10:29 2023 fal[client]: error fetching gap sequence, no fal server specified sat dec 23 23:10:39 2023 fal[client]: error fetching gap sequence, no fal server specified sat dec 23 23:10:49 2023 fal[client]: error fetching gap sequence, no fal server specified sat dec 23 23:10:59 2023 fal[client]: error fetching gap sequence, no fal server specified sat dec 23 23:11:09 2023 fal[client]: error fetching gap sequence, no fal server specified sat dec 23 23:11:19 2023 fal[client]: error fetching gap sequence, no fal server specified sat dec 23 23:11:29 2023 fal[client]: error fetching gap sequence, no fal server specified sat dec 23 23:11:39 2023 fal[client]: error fetching gap sequence, no fal server specified sat dec 23 23:11:49 2023 fal[client]: error fetching gap sequence, no fal server specified sat dec 23 23:11:59 2023 fal[client]: failed to request gap sequence gap - thread 1 sequence 90-98 dbid 1684141551 branch 1156360815 fal[client]: all defined fal servers have been attempted. ------------------------------------------------------------ check that the control_file_record_keep_time initialization parameter is defined to a value that's sufficiently large enough to maintain adequate log switch information to resolve archivelog gaps. ------------------------------------------------------------ ^c [oracle@11g-standby trace]$ sqlplus / as sysdba sql*plus: release 11.2.0.4.0 production on sat dec 23 23:13:26 2023 米乐app官网下载 copyright (c) 1982, 2013, 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 sql> select * from v$archive_gap; thread# low_sequence# high_sequence# ---------- ------------- -------------- 1 90 98 sql>

恢复dataguard

通过rman增量备份来恢复

停止redo应用备库

[oracle@11g-standby trace]$ sqlplus / as sysdba sql*plus: release 11.2.0.4.0 production on sat dec 23 23:18:55 2023 米乐app官网下载 copyright (c) 1982, 2013, 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 sql> alter database recover managed standby database cancel; database altered. sql>

查询备库当前scn

sql> select current_scn from v$database; current_scn ----------- 908139 sql>

rman增量备份

主库做rman的增量备份,注意scn号就是备库当前scn号

[oracle@11g-primary ~]$ rman target / recovery manager: release 11.2.0.4.0 - production on sat dec 23 23:26:42 2023 米乐app官网下载 copyright (c) 1982, 2011, oracle and/or its affiliates. all rights reserved. connected to target database: orcl (dbid=1684141551) rman> backup incremental from scn 908139 database format '/tmp/forstandby_%u' tag 'forstandby'; starting backup at 2023-12-23 23:30:01 using target database control file instead of recovery catalog allocated channel: ora_disk_1 channel ora_disk_1: sid=199 device type=disk channel ora_disk_1: starting full datafile backup set channel ora_disk_1: specifying datafile(s) in backup set input datafile file number=00003 name=/u01/app/oracle/oradata/orcl/undotbs01.dbf input datafile file number=00001 name=/u01/app/oracle/oradata/orcl/system01.dbf input datafile file number=00002 name=/u01/app/oracle/oradata/orcl/sysaux01.dbf input datafile file number=00004 name=/u01/app/oracle/oradata/orcl/users01.dbf channel ora_disk_1: starting piece 1 at 2023-12-23 23:30:01 channel ora_disk_1: finished piece 1 at 2023-12-23 23:30:04 piece handle=/tmp/forstandby_0c2epp7p_1_1 tag=forstandby comment=none channel ora_disk_1: backup set complete, elapsed time: 00:00:03 channel ora_disk_1: starting full datafile backup set channel ora_disk_1: specifying datafile(s) in backup set including current control file in backup set channel ora_disk_1: starting piece 1 at 2023-12-23 23:30:05 channel ora_disk_1: finished piece 1 at 2023-12-23 23:30:06 piece handle=/tmp/forstandby_0d2epp7s_1_1 tag=forstandby comment=none channel ora_disk_1: backup set complete, elapsed time: 00:00:01 finished backup at 2023-12-23 23:30:06 rman> exit recovery manager complete. [oracle@11g-primary ~]$

复制备份文件到备库

[oracle@11g-primary ~]$ cd /tmp [oracle@11g-primary tmp]$ ll forstandby* -rw-r----- 1 oracle oinstall 133521408 dec 23 23:30 forstandby_0c2epp7p_1_1 -rw-r----- 1 oracle oinstall 10092544 dec 23 23:30 forstandby_0d2epp7s_1_1 [oracle@11g-primary tmp]$ scp forstandby* 192.168.17.92:/tmp oracle@192.168.17.92's password: forstandby_0c2epp7p_1_1 100% 127mb 165.7mb/s 00:00 forstandby_0d2epp7s_1_1 100% 9856kb 160.0mb/s 00:00 [oracle@11g-primary tmp]$

备库rman从增量恢复

[oracle@11g-standby trace]$ rman target / recovery manager: release 11.2.0.4.0 - production on sat dec 23 23:36:25 2023 米乐app官网下载 copyright (c) 1982, 2011, oracle and/or its affiliates. all rights reserved. connected to target database: orcl (dbid=1684141551) rman> startup force nomount; oracle instance started total system global area 1653518336 bytes fixed size 2253784 bytes variable size 1023413288 bytes database buffers 620756992 bytes redo buffers 7094272 bytes rman> restore standby controlfile from '/tmp/forstandby_0d2epp7s_1_1'; starting restore at 2023-12-23 23:44:14 allocated channel: ora_disk_1 channel ora_disk_1: sid=63 device type=disk channel ora_disk_1: restoring control file channel ora_disk_1: restore complete, elapsed time: 00:00:01 output file name=/u01/app/oracle/oradata/orcldg/control01.ctl output file name=/u01/app/oracle/fast_recovery_area/orcldg/control02.ctl finished restore at 2023-12-23 23:44:15 rman> alter database mount; database mounted released channel: ora_disk_1 rman> catalog start with '/tmp/forstandby'; starting implicit crosscheck backup at 2023-12-23 23:44:45 allocated channel: ora_disk_1 channel ora_disk_1: sid=8 device type=disk finished implicit crosscheck backup at 2023-12-23 23:44:46 starting implicit crosscheck copy at 2023-12-23 23:44:46 using channel ora_disk_1 finished implicit crosscheck copy at 2023-12-23 23:44:46 searching for all files in the recovery area cataloging files... no files cataloged searching for all files that match the pattern /tmp/forstandby list of files unknown to the database ===================================== file name: /tmp/forstandby_0c2epp7p_1_1 file name: /tmp/forstandby_0d2epp7s_1_1 do you really want to catalog the above files (enter yes or no)? yes cataloging files... cataloging done list of cataloged files ======================= file name: /tmp/forstandby_0c2epp7p_1_1 file name: /tmp/forstandby_0d2epp7s_1_1 rman> recover database noredo; starting recover at 2023-12-23 23:45:10 using channel ora_disk_1 channel ora_disk_1: starting incremental datafile backup set restore channel ora_disk_1: specifying datafile(s) to restore from backup set destination for restore of datafile 00001: /u01/app/oracle/oradata/orcldg/system01.dbf destination for restore of datafile 00002: /u01/app/oracle/oradata/orcldg/sysaux01.dbf destination for restore of datafile 00003: /u01/app/oracle/oradata/orcldg/undotbs01.dbf destination for restore of datafile 00004: /u01/app/oracle/oradata/orcldg/users01.dbf channel ora_disk_1: reading from backup piece /tmp/forstandby_0c2epp7p_1_1 channel ora_disk_1: piece handle=/tmp/forstandby_0c2epp7p_1_1 tag=forstandby channel ora_disk_1: restored backup piece 1 channel ora_disk_1: restore complete, elapsed time: 00:00:01 finished recover at 2023-12-23 23:45:12 rman> exit recovery manager complete. [oracle@11g-standby trace]$

启动mrp进程应用日志

[oracle@11g-standby trace]$ sqlplus / as sysdba sql*plus: release 11.2.0.4.0 production on sat dec 23 23:46:35 2023 米乐app官网下载 copyright (c) 1982, 2013, 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 sql> alter database recover managed standby database using current logfile disconnect from session; database altered. sql> alter database recover managed standby database cancel; database altered. sql> alter database open read only; database altered. sql> alter database recover managed standby database using current logfile disconnect from session; database altered. sql>

验证恢复正常

主库

查询操作后的表记录

[oracle@11g-primary tmp]$ sqlplus / as sysdba sql*plus: release 11.2.0.4.0 production on sat dec 23 23:48:58 2023 米乐app官网下载 copyright (c) 1982, 2013, 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 sql> select count(1) from sunying.t; count(1) ---------- 2550001 sql>

备库

查询对应主库表记录,和gaps记录

[oracle@11g-standby trace]$ sqlplus / as sysdba sql*plus: release 11.2.0.4.0 production on sun dec 24 00:02:04 2023 米乐app官网下载 copyright (c) 1982, 2013, 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 sql> select count(1) from sunying.t; count(1) ---------- 2550001 sql> select * from v$archive_gap; no rows selected sql>

查询备库告警文件,dataguard环境恢复正常

[oracle@11g-standby trace]$ tail -100f alert_orcldg.log sat dec 23 23:44:26 2023 arc1 started with pid=23, os id=85471 sat dec 23 23:44:26 2023 arc2 started with pid=24, os id=85475 sat dec 23 23:44:26 2023 arc3 started with pid=25, os id=85479 arc1: archival started arc2: archival started arc1: becoming the 'no fal' arch arc2: becoming the heartbeat arch arc2: becoming the active heartbeat arch completed: alter database mount arc3: archival started arc0: starting arch processes complete sat dec 23 23:44:45 2023 using standby_archive_dest parameter default value as /arch/ sat dec 23 23:44:45 2023 srl log 4 needs clearing because log has not been created srl log 5 needs clearing because log has not been created rfs[1]: assigned to rfs process 85526 rfs[1]: selected log 6 for thread 1 sequence 101 dbid 1684141551 branch 1156360815 sat dec 23 23:44:45 2023 archived log entry 1 added for thread 1 sequence 101 id 0x6461b6ef dest 1: sat dec 23 23:44:45 2023 primary database is in maximum performance mode srl log 4 needs clearing because log has not been created srl log 5 needs clearing because log has not been created rfs[2]: assigned to rfs process 85541 rfs[2]: selected log 6 for thread 1 sequence 102 dbid 1684141551 branch 1156360815 sat dec 23 23:45:11 2023 incremental restore complete of datafile 4 /u01/app/oracle/oradata/orcldg/users01.dbf checkpoint is 910448 incremental restore complete of datafile 2 /u01/app/oracle/oradata/orcldg/sysaux01.dbf checkpoint is 910448 incremental restore complete of datafile 1 /u01/app/oracle/oradata/orcldg/system01.dbf checkpoint is 910448 incremental restore complete of datafile 3 /u01/app/oracle/oradata/orcldg/undotbs01.dbf checkpoint is 910448 sat dec 23 23:46:52 2023 alter database recover managed standby database using current logfile disconnect from session attempt to start background managed standby recovery process (orcldg) sat dec 23 23:46:52 2023 mrp0 started with pid=20, os id=85721 mrp0: background managed standby recovery process started (orcldg) started logmerger process sat dec 23 23:46:57 2023 managed standby recovery starting real time apply parallel media recovery started with 4 slaves waiting for all non-current orls to be archived... all non-current orls have been archived. media recovery log /arch/1_101_1156360815.dbf media recovery waiting for thread 1 sequence 102 (in transit) recovery of online redo log: thread 1 group 6 seq 102 reading mem 0 mem# 0: /u01/app/oracle/oradata/orcldg/standby03.log completed: alter database recover managed standby database using current logfile disconnect from session sat dec 23 23:48:11 2023 alter database recover managed standby database cancel sat dec 23 23:48:11 2023 mrp0: background media recovery cancelled with status 16037 errors in file /u01/app/oracle/diag/rdbms/orcldg/orcldg/trace/orcldg_pr00_85731.trc: ora-16037: user requested cancel of managed recovery operation managed standby recovery not using real time apply recovery interrupted! recovered data files to a consistent state at change 911586 sat dec 23 23:48:11 2023 mrp0: background media recovery process shutdown (orcldg) managed standby recovery canceled (orcldg) completed: alter database recover managed standby database cancel alter database open read only audit_trail initialization parameter is changed to os, as db is not compatible for database opened with read-only access sat dec 23 23:48:18 2023 smon: enabling cache recovery dictionary check beginning dictionary check complete database characterset is zhs16gbk no resource manager plan active replication_dependency_tracking turned off (no async multimaster replication found) physical standby database opened for read only access. completed: alter database open read only sat dec 23 23:48:18 2023 db_recovery_file_dest_size of 20480 mb is 0.00% used. this is a user-specified limit on the amount of space that will be used by this database for recovery-related files, and does not reflect the amount of space available in the underlying filesystem or asm diskgroup. sat dec 23 23:48:23 2023 alter database recover managed standby database using current logfile disconnect from session attempt to start background managed standby recovery process (orcldg) sat dec 23 23:48:23 2023 mrp0 started with pid=20, os id=85867 mrp0: background managed standby recovery process started (orcldg) started logmerger process sat dec 23 23:48:28 2023 managed standby recovery starting real time apply parallel media recovery started with 4 slaves waiting for all non-current orls to be archived... all non-current orls have been archived. media recovery waiting for thread 1 sequence 102 (in transit) recovery of online redo log: thread 1 group 6 seq 102 reading mem 0 mem# 0: /u01/app/oracle/oradata/orcldg/standby03.log completed: alter database recover managed standby database using current logfile disconnect from session ^c [oracle@11g-standby trace]$

至此已经完成一个主库丢失archivelog文件使用rman增量恢复备库dataguard的全过程。希望给各位小伙伴们一点帮助😄

最后修改时间:2023-12-25 10:48:09
「喜欢这篇文章,您的关注和赞赏是给作者最好的鼓励」
关注作者
【米乐app官网下载的版权声明】本文为墨天轮用户原创内容,转载时必须标注文章的来源(墨天轮),文章链接,文章作者等基本信息,否则作者和墨天轮有权追究责任。如果您发现墨天轮中有涉嫌抄袭或者侵权的内容,欢迎发送邮件至:contact@modb.pro进行举报,并提供相关证据,一经查实,墨天轮将立刻删除相关内容。

评论

网站地图