欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

数据库ORA-01196故障-归档日志丢失恢复详解

程序员文章站 2022-03-16 20:08:28
问题: 由于机房停电,其中一dg备库无法open,启动时报错 启动数据库时报下面的错误 sql> alter database open; a...

问题:

由于机房停电,其中一dg备库无法open,启动时报错

启动数据库时报下面的错误

sql> alter database open;
alter database open
*

第 1 行出现错误:

ora-10458: standby database requiresrecovery
ora-01196: 文件 1 由于介质恢复会话失败而不一致
ora-01110: 数据文件 1:'+data/htdb7/datafile/system.313.884996245'

查看归档日志应用情况,发现一部分日志没应用

sql> select name,sequence#,applied,completion_time from v$archived_log order by sequence# desc;
name,                                                               sequence# applied completion_time
+fra/htdb7/archivelog/2017_03_25/thread_1_seq_328776.705.939567729   328776   yes  no  2017/3/2515:02
+fra/htdb7/archivelog/2017_03_25/thread_1_seq_328775.713.939567727   328775   yes  no  2017/3/2515:02
+fra/htdb7/archivelog/2017_03_25/thread_1_seq_328774.777.939567727   328774   yes  no  2017/3/2515:02
+fra/htdb7/archivelog/2017_03_25/thread_1_seq_328773.771.939567725   328773   yes  no  2017/3/2515:02
+fra/htdb7/archivelog/2017_03_25/thread_1_seq_328772.422.939567721   328772   yes  no  2017/3/2515:02
+fra/htdb7/archivelog/2017_03_25/thread_1_seq_328771.482.939567721   328771   yes  no  2017/3/2515:02
+fra/htdb7/archivelog/2017_03_25/thread_1_seq_328770.755.939567721   328770   yes  no  2017/3/2515:02
+fra/htdb7/archivelog/2017_03_24/thread_1_seq_328757.1255.939481573  328757   yes  no  2017/3/2415:06
+fra/htdb7/archivelog/2017_03_24/thread_1_seq_328756.795.939480431   328756   yes  yes  2017/3/2414:47
+fra/htdb7/archivelog/2017_03_24/thread_1_seq_328755.543.939479395   328755   yes  yes  2017/3/2414:29
+fra/htdb7/archivelog/2017_03_24/thread_1_seq_328754.390.939478683   328754   yes  yes  2017/3/2414:18
+fra/htdb7/archivelog/2017_03_24/thread_1_seq_328753.1845.939477943  328753   yes  yes  2017/3/2414:05
 
--再和其它备库或主库的归档日志做对比,很明显发现这个备库没有同步并应用主库的日志
--此备库:
[oracle@hotel07 ~]$ asmcmd -p
asmcmd [+fra/htdb7/archivelog] > cd 2017_03_24/
asmcmd [+fra/htdb7/archivelog/2017_03_24]> ls
......
thread_1_seq_328754.390.939478683
thread_1_seq_328755.543.939479395
thread_1_seq_328756.795.939480431
thread_1_seq_328757.1255.939481573
 
--其它正常的备库
[oracle@hotel05 ~]$ asmcmd -p
asmcmd [+fra/htdb5/archivelog/2017_03_24]> ls
thread_1_seq_328754.4124.939478683
thread_1_seq_328755.349.939479395
thread_1_seq_328756.852.939480431
thread_1_seq_328757.1420.939481575
thread_1_seq_328758.3356.939510647
thread_1_seq_328759.4592.939510649
thread_1_seq_328760.3205.939510647
thread_1_seq_328761.5308.939510649
thread_1_seq_328762.5227.939510653
.....

解决办法:

需要从其它备库或主库上面把此备库缺失的归档日志手动传输过来,然后再进行open操作

步骤如下:

1. 在另一正常的备库用rman备份缺失的归档日志

[oracle@hotel05 ~]$ rman target /
rman> copy archivelog'+fra/htdb5/archivelog/2017_03_24/thread_1_seq_328759.4592.939510649' to'/home/oracle/arcbak/thread_1_seq_328759.4592.939510649';

启动 backup 于 25-3月 -17

使用通道 ora_disk_1

通道 ora_disk_1: 正在开始复制归档日志

输入归档日志线程=1 序列=328759 recid=328754 stamp=939510652

输出文件名=/home/oracle/arcbak/thread_1_seq_328759.4592.939510649 recid=328794stamp=939571923

通道 ora_disk_1: 归档日志复制完成, 经过时间: 00:00:03

完成 backup 于 25-3月 -17
......

. 备份完成后,把归档传输到丢失归档的备库
[oracle@hotel05 arcbak]$ scp * hotel07:/home/oracle/arcbak/

3. 然后在此备库上进行恢复操作

-- 编制归档文件目录
[oracle@hotel07 ~]$ rman target /

恢复管理器: release 11.2.0.2.0 - production on 星期六 3月 25 15:42:112017
copyright (c) 1982, 2009, oracle and/or itsaffiliates.  all rights reserved.
已连接到目标数据库: htdb4 (dbid=1083719948, 未打开)

rman> catalog start with '/home/oracle/arcbak';

搜索与样式 /home/oracle/arcbak 匹配的所有文件

数据库未知文件的列表
=====================================
文件名: /home/oracle/arcbak/thread_1_seq_328763.4773.939510653
文件名: /home/oracle/arcbak/thread_1_seq_328767.2765.939511033
文件名: /home/oracle/arcbak/thread_1_seq_328766.5854.939511023
文件名: /home/oracle/arcbak/thread_1_seq_328759.4592.939510649
文件名: /home/oracle/arcbak/thread_1_seq_328758.3356.939510647
文件名: /home/oracle/arcbak/thread_1_seq_328760.3205.939510647
文件名: /home/oracle/arcbak/thread_1_seq_328762.5227.939510653
文件名: /home/oracle/arcbak/thread_1_seq_328761.5308.939510649
文件名: /home/oracle/arcbak/thread_1_seq_328757.1420.939481575
文件名: /home/oracle/arcbak/thread_1_seq_328764.5801.939510653
文件名: /home/oracle/arcbak/thread_1_seq_328765.3298.939510657

是否确实要将上述文件列入目录(输入 yes 或 no)? y

正在编制文件目录...

目录编制完毕

已列入目录的文件的列表
=======================
文件名: /home/oracle/arcbak/thread_1_seq_328763.4773.939510653
文件名: /home/oracle/arcbak/thread_1_seq_328767.2765.939511033
文件名: /home/oracle/arcbak/thread_1_seq_328766.5854.939511023
文件名: /home/oracle/arcbak/thread_1_seq_328759.4592.939510649
文件名: /home/oracle/arcbak/thread_1_seq_328758.3356.939510647
文件名: /home/oracle/arcbak/thread_1_seq_328760.3205.939510647
文件名: /home/oracle/arcbak/thread_1_seq_328762.5227.939510653
文件名: /home/oracle/arcbak/thread_1_seq_328761.5308.939510649
文件名: /home/oracle/arcbak/thread_1_seq_328757.1420.939481575
文件名: /home/oracle/arcbak/thread_1_seq_328764.5801.939510653
文件名: /home/oracle/arcbak/thread_1_seq_328765.3298.939510657
-- 恢复归档日志
rman> copy archivelog '/home/oracle/arcbak/thread_1_seq_328757.1420.939481575' to '+fra';

启动 backup 于 25-3月 -17

使用通道 ora_disk_1

通道 ora_disk_1: 正在开始复制归档日志

输入归档日志线程=1 序列=328760 recid=149368 stamp=939573701
输出文件名=+fra/htdb7/archivelog/2017_03_25/thread_1_seq_328760.474.939573739recid=149375 stamp=939573738

通道 ora_disk_1: 归档日志复制完成, 经过时间: 00:00:01

完成 backup 于 25-3月 -17
......

4. 最后就可以open数据库了

sql> alter database open;
sql> select open_mode from v$database;
 
open_mode
--------------------
read only with apply
 
-- 查看日志 ,归档日志正常进行应用
alter database open
data guard broker initializing...
data guard broker initialization complete
beginning standby crash recovery.
serial media recovery started
managed standby recovery starting real timeapply
media recovery log+fra/htdb7/archivelog/2017_03_25/thread_1_seq_328757.499.939573737
media recovery log/home/oracle/arcbak/thread_1_seq_328758.3356.939510647
sat mar 25 16:43:57 2017
incomplete recovery applied until change91347484119 time 03/24/2017 15:06:26
completed standby crash recovery.
sat mar 25 16:43:58 2017
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 readonly access.
completed: alter database open
sat mar 25 16:44:01 2017
alter database recover managed standbydatabase through all switchoverdisconnect using current logfile
attempt to start background managed standbyrecovery process (htdb7)
sat mar 25 16:44:01 2017
mrp0 started with pid=47, os id=9619
mrp0: background managed standby recoveryprocess started (htdb7)
 started logmerger process
sat mar 25 16:44:06 2017
managed standby recovery starting real timeapply
parallel media recovery started with 16slaves
waiting for all non-current orls to bearchived...
all non-current orls have been archived.
media recovery log /home/oracle/arcbak/thread_1_seq_328758.3356.939510647
media recovery log+fra/htdb7/archivelog/2017_03_25/thread_1_seq_328759.1574.939573739
completed: alter database recover managedstandby database through all switchoverdisconnect using current logfile
media recovery log+fra/htdb7/archivelog/2017_03_25/thread_1_seq_328760.922.939573741
media recovery log+fra/htdb7/archivelog/2017_03_25/thread_1_seq_328761.695.939573743
media recovery log+fra/htdb7/archivelog/2017_03_25/thread_1_seq_328762.1769.939573745
media recovery log+fra/htdb7/archivelog/2017_03_25/thread_1_seq_328763.1422.939573745

总结:

在由于停电和网络原因,造成主备数据不同步,日志丢失的情况,主要学会使用rman工具把归档文件在fs和asm之间传输。在数据库恢复时会经常用到。

另外,如果数据库开启了闪回功能 ,也可以使用闪回数据库的某个时点进行恢复。可以参考另一篇博文:oracle数据库ora-01196错误解决办法分享

希望对大家有所帮助,感谢阅读。