利用oracle9i blockrecover 修復ORA-01578壞塊問題

paulyibinyi發表於2009-09-08

ORA-01578壞塊處理
應用在做報表查詢時報ORA-01578錯誤,導致做報表不成功。

4 處理過程
4.1 檢查後臺資料庫日誌
檢查資料庫例項日誌$ORACL_BASE/admin/stjj/bdump/alert_stjj.log,從8月23日零晨4點開始就出現ORA-01578錯誤
Sun Aug 23 04:18:59 2009
ARC0: Evaluating archive   log 4 thread 1 sequence 4924
ARC0: Beginning to archive log 4 thread 1 sequence 4924
Creating archive destination LOG_ARCHIVE_DEST_1: '/oraarch/arch/1_4924.dbf'
ARC0: Completed archiving  log 4 thread 1 sequence 4924
...skipping...
ORA-12012: error on auto execute of job 183
ORA-01578: ORACLE data block corrupted (file # 13, block # 222840)
ORA-01110: data file 13: '/ora9idata01/oradata/stjj/VIO_DATA_02.dbf'
ORA-06512: at "admin.PRO_GX_CZDZ", line 8
ORA-06512: at line 1
4.2 檢查壞塊所對應的物件
SQL> select segment_type,owner||'.'||segment_name from dba_extents where file_id=13 and 222840 between block_id and block_id+blocks-1;

SEGMENT_TYPE
------------------
OWNER||'.'||SEGMENT_NAME
--------------------------------------------------------------------
TABLE
admin.B_JTWF_WFSS
file_id和block 號為上面錯誤日誌中出現的具體值
從上面結果可以看出壞快物件為table,表名為admin下的B_JTWF_WFSS表
SQL> select count(*) from admin.B_JTWF_WFSS;
select count(*) from admin.B_JTWF_WFSS
ERROR at line 1:
ORA-01578: ORACLE data block corrupted (file # 13, block # 222840)
ORA-01110: data file 13: '/ora9idata01/oradata/stjj/VIO_DATA_02.dbf'
透過查詢,對錶B_JTWF_WFSS做dml操作都不成功。
4.3 檢查最近幾天的邏輯備份
22號正常
 exporting table   B_JTWF_WFSS    3148490 rows exported
23號開始B_JTWF_WFSS表匯出就報ORA-01578錯誤
exporting table                    B_JTWF_WFSS
EXP-00056: ORACLE error 1578 encountered
ORA-01578: ORACLE data block corrupted (file # 13, block # 222840)
ORA-01110: data file 13: '/ora9idata01/oradata/stjj/VIO_DATA_02.dbf'
4.4 檢查最近的物理備份和歸檔日誌備份
透過檢視備份日誌和歸檔日誌,上週六的全備成功,每天的歸檔日誌備份成功。
4.5 用rman檢查對應資料檔案的壞塊
[oracle@p550:/oracle/app/oracle/]$rman target /
Recovery Manager: Release 9.2.0.8.0 - 64bit Production
Copyright (c) 1995, 2002, Oracle Corporation.  All rights reserved.
connected to target database: STJJ (DBID=433032791)
RMAN> backup validate datafile 13;
Starting backup at 2009-08-26:20:09:03
using target database controlfile instead of recovery catalog
allocated channel: ORA_DISK_1
channel ORA_DISK_1: sid=20 devtype=DISK
channel ORA_DISK_1: starting full datafile backupset
channel ORA_DISK_1: specifying datafile(s) in backupset
input datafile fno=00013 name=/ora9idata01/oradata/stjj/VIO_DATA_02.dbf
channel ORA_DISK_1: backup set complete, elapsed time: 00:02:55
Finished backup at 2009-08-26:20:11:58
SQL> select * from v$database_block_corruption where file#=13;
     FILE#     BLOCK#     BLOCKS CORRUPTION_CHANGE# CORRUPTIO
---------- ---------- ---------- ------------------ ---------
        13     222840          1                  0 FRACTURED
透過上面的檢查,用邏輯備份來恢復是不可取的,會丟失8.23到現在的資料,
只能採取物理備份+9i新特性blockrecover來恢復。
4.6 恢復8.22到8.26號的全部歸檔日誌  
RMAN> restore archivelog time between "to_date('2009-08-22 00:00:00','yyyy-mm-dd hh24:mi:ss')"
2> and "to_date('2009-08-26 23:59:59','yyyy-mm-dd hh24:mi:ss')" ;
Starting restore at 2009-08-26:20:21:26
using channel ORA_DISK_1
archive log thread 1 sequence 5071 is already on disk as file /oraarch/arch/1_5071.dbf
archive log thread 1 sequence 5072 is already on disk as file /oraarch/arch/1_5072.dbf
archive log thread 1 sequence 5073 is already on disk as file /oraarch/arch/1_5073.dbf
archive log thread 1 sequence 5074 is already on disk as file /oraarch/arch/1_5074.dbf
channel ORA_DISK_1: starting archive log restore to default destination
channel ORA_DISK_1: restoring archive log
archive log thread=1 sequence=4892
channel ORA_DISK_1: restoring archive log
archive log thread=1 sequence=4893
channel ORA_DISK_1: restored backup piece 1
piece handle=/orarman/arch/al_114_1_695520004 tag=TAG20090822T000003 params=NULL
channel ORA_DISK_1: restore complete
channel ORA_DISK_1: starting archive log restore to default destination
channel ORA_DISK_1: restoring archive log
archive log thread=1 sequence=4894
channel ORA_DISK_1: restoring archive log
archive log thread=1 sequence=4895
channel ORA_DISK_1: restoring archive log
archive log thread=1 sequence=4896
channel ORA_DISK_1: restoring archive log
archive log thread=1 sequence=4897
channel ORA_DISK_1: restoring archive log
archive log thread=1 sequence=4898
channel ORA_DISK_1: restoring archive log
archive log thread=1 sequence=4899
channel ORA_DISK_1: restoring archive log
archive log thread=1 sequence=4900
channel ORA_DISK_1: restoring archive log
archive log thread=1 sequence=4901
channel ORA_DISK_1: restoring archive log
archive log thread=1 sequence=4902
channel ORA_DISK_1: restoring archive log
archive log thread=1 sequence=4903
channel ORA_DISK_1: restoring archive log
archive log thread=1 sequence=4904
channel ORA_DISK_1: restoring archive log
archive log thread=1 sequence=4905
channel ORA_DISK_1: restoring archive log
archive log thread=1 sequence=4906
channel ORA_DISK_1: restoring archive log
archive log thread=1 sequence=4907
channel ORA_DISK_1: restoring archive log
archive log thread=1 sequence=4908
channel ORA_DISK_1: restoring archive log
archive log thread=1 sequence=4909
channel ORA_DISK_1: restoring archive log
archive log thread=1 sequence=4910
channel ORA_DISK_1: restoring archive log
archive log thread=1 sequence=4911
channel ORA_DISK_1: restored backup piece 1
piece handle=/orarman/arch/al_116_1_695606407 tag=TAG20090823T000007 params=NULL
channel ORA_DISK_1: restore complete
channel ORA_DISK_1: starting archive log restore to default destination
channel ORA_DISK_1: restoring archive log
archive log thread=1 sequence=4912
channel ORA_DISK_1: restoring archive log
archive log thread=1 sequence=4913
channel ORA_DISK_1: restoring archive log
archive log thread=1 sequence=4914
channel ORA_DISK_1: restoring archive log
archive log thread=1 sequence=4915
channel ORA_DISK_1: restoring archive log
archive log thread=1 sequence=4916
channel ORA_DISK_1: restoring archive log
archive log thread=1 sequence=4917
channel ORA_DISK_1: restoring archive log
archive log thread=1 sequence=4918
channel ORA_DISK_1: restoring archive log
archive log thread=1 sequence=4919
channel ORA_DISK_1: restoring archive log
archive log thread=1 sequence=4920
channel ORA_DISK_1: restoring archive log
archive log thread=1 sequence=4921
channel ORA_DISK_1: restoring archive log
archive log thread=1 sequence=4922
channel ORA_DISK_1: restoring archive log
archive log thread=1 sequence=4923
channel ORA_DISK_1: restoring archive log
archive log thread=1 sequence=4924
channel ORA_DISK_1: restoring archive log
archive log thread=1 sequence=4925
channel ORA_DISK_1: restoring archive log
archive log thread=1 sequence=4926
channel ORA_DISK_1: restoring archive log
archive log thread=1 sequence=4927
channel ORA_DISK_1: restoring archive log
archive log thread=1 sequence=4928
channel ORA_DISK_1: restoring archive log
archive log thread=1 sequence=4929
channel ORA_DISK_1: restoring archive log
archive log thread=1 sequence=4930
channel ORA_DISK_1: restoring archive log
archive log thread=1 sequence=4931
channel ORA_DISK_1: restoring archive log
archive log thread=1 sequence=4932
channel ORA_DISK_1: restoring archive log
archive log thread=1 sequence=4933
channel ORA_DISK_1: restoring archive log
archive log thread=1 sequence=4934
channel ORA_DISK_1: restoring archive log
archive log thread=1 sequence=4935
channel ORA_DISK_1: restoring archive log
archive log thread=1 sequence=4936
channel ORA_DISK_1: restoring archive log
archive log thread=1 sequence=4937
channel ORA_DISK_1: restoring archive log
archive log thread=1 sequence=4938
channel ORA_DISK_1: restoring archive log
archive log thread=1 sequence=4939
channel ORA_DISK_1: restoring archive log
archive log thread=1 sequence=4940
channel ORA_DISK_1: restoring archive log
archive log thread=1 sequence=4941
channel ORA_DISK_1: restoring archive log
archive log thread=1 sequence=4942
channel ORA_DISK_1: restoring archive log
archive log thread=1 sequence=4943
channel ORA_DISK_1: restoring archive log
archive log thread=1 sequence=4944
channel ORA_DISK_1: restoring archive log
archive log thread=1 sequence=4945
channel ORA_DISK_1: restoring archive log
archive log thread=1 sequence=4946
channel ORA_DISK_1: restoring archive log
archive log thread=1 sequence=4947
channel ORA_DISK_1: restoring archive log
archive log thread=1 sequence=4948
channel ORA_DISK_1: restoring archive log
archive log thread=1 sequence=4949
channel ORA_DISK_1: restoring archive log
archive log thread=1 sequence=4950
channel ORA_DISK_1: restoring archive log
archive log thread=1 sequence=4951
channel ORA_DISK_1: restoring archive log
archive log thread=1 sequence=4952
channel ORA_DISK_1: restoring archive log
archive log thread=1 sequence=4953
channel ORA_DISK_1: restoring archive log
archive log thread=1 sequence=4954
channel ORA_DISK_1: restoring archive log
archive log thread=1 sequence=4955
channel ORA_DISK_1: restoring archive log
archive log thread=1 sequence=4956
channel ORA_DISK_1: restoring archive log
archive log thread=1 sequence=4957
channel ORA_DISK_1: restoring archive log
archive log thread=1 sequence=4958
channel ORA_DISK_1: restoring archive log
archive log thread=1 sequence=4959
channel ORA_DISK_1: restoring archive log
archive log thread=1 sequence=4960
channel ORA_DISK_1: restoring archive log
archive log thread=1 sequence=4961
channel ORA_DISK_1: restoring archive log
archive log thread=1 sequence=4962
channel ORA_DISK_1: restoring archive log
archive log thread=1 sequence=4963
channel ORA_DISK_1: restoring archive log
archive log thread=1 sequence=4964
channel ORA_DISK_1: restoring archive log
archive log thread=1 sequence=4965
channel ORA_DISK_1: restoring archive log
archive log thread=1 sequence=4966
channel ORA_DISK_1: restored backup piece 1
piece handle=/orarman/arch/al_117_1_695692809 tag=TAG20090824T000008 params=NULL
channel ORA_DISK_1: restore complete
channel ORA_DISK_1: starting archive log restore to default destination
channel ORA_DISK_1: restoring archive log
archive log thread=1 sequence=4967
channel ORA_DISK_1: restoring archive log
archive log thread=1 sequence=4968
channel ORA_DISK_1: restoring archive log
archive log thread=1 sequence=4969
channel ORA_DISK_1: restoring archive log
archive log thread=1 sequence=4970
channel ORA_DISK_1: restoring archive log
archive log thread=1 sequence=4971
channel ORA_DISK_1: restoring archive log
archive log thread=1 sequence=4972
channel ORA_DISK_1: restoring archive log
archive log thread=1 sequence=4973
channel ORA_DISK_1: restoring archive log
archive log thread=1 sequence=4974
channel ORA_DISK_1: restoring archive log
archive log thread=1 sequence=4975
channel ORA_DISK_1: restoring archive log
archive log thread=1 sequence=4976
channel ORA_DISK_1: restoring archive log
archive log thread=1 sequence=4977
channel ORA_DISK_1: restoring archive log
archive log thread=1 sequence=4978
channel ORA_DISK_1: restoring archive log
archive log thread=1 sequence=4979
channel ORA_DISK_1: restoring archive log
archive log thread=1 sequence=4980
channel ORA_DISK_1: restoring archive log
archive log thread=1 sequence=4981
channel ORA_DISK_1: restoring archive log
archive log thread=1 sequence=4982
channel ORA_DISK_1: restoring archive log
archive log thread=1 sequence=4983
channel ORA_DISK_1: restoring archive log
archive log thread=1 sequence=4984
channel ORA_DISK_1: restoring archive log
archive log thread=1 sequence=4985
channel ORA_DISK_1: restoring archive log
archive log thread=1 sequence=4986
channel ORA_DISK_1: restoring archive log
archive log thread=1 sequence=4987
channel ORA_DISK_1: restoring archive log
archive log thread=1 sequence=4988
channel ORA_DISK_1: restoring archive log
archive log thread=1 sequence=4989
channel ORA_DISK_1: restoring archive log
archive log thread=1 sequence=4990
channel ORA_DISK_1: restoring archive log
archive log thread=1 sequence=4991
channel ORA_DISK_1: restoring archive log
archive log thread=1 sequence=4992
channel ORA_DISK_1: restoring archive log
archive log thread=1 sequence=4993
channel ORA_DISK_1: restoring archive log
archive log thread=1 sequence=4994
channel ORA_DISK_1: restoring archive log
archive log thread=1 sequence=4995
channel ORA_DISK_1: restoring archive log
archive log thread=1 sequence=4996
channel ORA_DISK_1: restoring archive log
archive log thread=1 sequence=4997
channel ORA_DISK_1: restoring archive log
archive log thread=1 sequence=4998
channel ORA_DISK_1: restoring archive log
archive log thread=1 sequence=4999
channel ORA_DISK_1: restoring archive log
archive log thread=1 sequence=5000
channel ORA_DISK_1: restoring archive log
archive log thread=1 sequence=5001
channel ORA_DISK_1: restoring archive log
archive log thread=1 sequence=5002
channel ORA_DISK_1: restoring archive log
archive log thread=1 sequence=5003
channel ORA_DISK_1: restoring archive log
archive log thread=1 sequence=5004
channel ORA_DISK_1: restoring archive log
archive log thread=1 sequence=5005
channel ORA_DISK_1: restoring archive log
archive log thread=1 sequence=5006
channel ORA_DISK_1: restoring archive log
archive log thread=1 sequence=5007
channel ORA_DISK_1: restoring archive log
archive log thread=1 sequence=5008
channel ORA_DISK_1: restoring archive log
archive log thread=1 sequence=5009
channel ORA_DISK_1: restoring archive log
archive log thread=1 sequence=5010
channel ORA_DISK_1: restoring archive log
archive log thread=1 sequence=5011
channel ORA_DISK_1: restoring archive log
archive log thread=1 sequence=5012
channel ORA_DISK_1: restoring archive log
archive log thread=1 sequence=5013
channel ORA_DISK_1: restoring archive log
archive log thread=1 sequence=5014
channel ORA_DISK_1: restoring archive log
archive log thread=1 sequence=5015
channel ORA_DISK_1: restoring archive log
archive log thread=1 sequence=5016
channel ORA_DISK_1: restoring archive log
archive log thread=1 sequence=5017
channel ORA_DISK_1: restoring archive log
archive log thread=1 sequence=5018
channel ORA_DISK_1: restoring archive log
archive log thread=1 sequence=5019
channel ORA_DISK_1: restoring archive log
archive log thread=1 sequence=5020
channel ORA_DISK_1: restoring archive log
archive log thread=1 sequence=5021
channel ORA_DISK_1: restoring archive log
archive log thread=1 sequence=5022
channel ORA_DISK_1: restored backup piece 1
piece handle=/orarman/arch/al_118_1_695693046 tag=TAG20090824T000008 params=NULL
channel ORA_DISK_1: restore complete
channel ORA_DISK_1: starting archive log restore to default destination
channel ORA_DISK_1: restoring archive log
archive log thread=1 sequence=5023
channel ORA_DISK_1: restoring archive log
archive log thread=1 sequence=5024
channel ORA_DISK_1: restoring archive log
archive log thread=1 sequence=5025
channel ORA_DISK_1: restoring archive log
archive log thread=1 sequence=5026
channel ORA_DISK_1: restoring archive log
archive log thread=1 sequence=5027
channel ORA_DISK_1: restoring archive log
archive log thread=1 sequence=5028
channel ORA_DISK_1: restoring archive log
archive log thread=1 sequence=5029
channel ORA_DISK_1: restoring archive log
archive log thread=1 sequence=5030
channel ORA_DISK_1: restoring archive log
archive log thread=1 sequence=5031
channel ORA_DISK_1: restoring archive log
archive log thread=1 sequence=5032
channel ORA_DISK_1: restoring archive log
archive log thread=1 sequence=5033
channel ORA_DISK_1: restoring archive log
archive log thread=1 sequence=5034
channel ORA_DISK_1: restoring archive log
archive log thread=1 sequence=5035
channel ORA_DISK_1: restoring archive log
archive log thread=1 sequence=5036
channel ORA_DISK_1: restoring archive log
archive log thread=1 sequence=5037
channel ORA_DISK_1: restoring archive log
archive log thread=1 sequence=5038
channel ORA_DISK_1: restoring archive log
archive log thread=1 sequence=5039
channel ORA_DISK_1: restoring archive log
archive log thread=1 sequence=5040
channel ORA_DISK_1: restoring archive log
archive log thread=1 sequence=5041
channel ORA_DISK_1: restoring archive log
archive log thread=1 sequence=5042
channel ORA_DISK_1: restoring archive log
archive log thread=1 sequence=5043
channel ORA_DISK_1: restoring archive log
archive log thread=1 sequence=5044
channel ORA_DISK_1: restoring archive log
archive log thread=1 sequence=5045
channel ORA_DISK_1: restoring archive log
archive log thread=1 sequence=5046
channel ORA_DISK_1: restoring archive log
archive log thread=1 sequence=5047
channel ORA_DISK_1: restoring archive log
archive log thread=1 sequence=5048
channel ORA_DISK_1: restoring archive log
archive log thread=1 sequence=5049
channel ORA_DISK_1: restoring archive log
archive log thread=1 sequence=5050
channel ORA_DISK_1: restoring archive log
archive log thread=1 sequence=5051
channel ORA_DISK_1: restoring archive log
archive log thread=1 sequence=5052
channel ORA_DISK_1: restored backup piece 1
piece handle=/orarman/arch/al_119_1_695779208 tag=TAG20090825T000007 params=NULL
channel ORA_DISK_1: restore complete
channel ORA_DISK_1: starting archive log restore to default destination
channel ORA_DISK_1: restoring archive log
archive log thread=1 sequence=5053
channel ORA_DISK_1: restoring archive log
archive log thread=1 sequence=5054
channel ORA_DISK_1: restoring archive log
archive log thread=1 sequence=5055
channel ORA_DISK_1: restoring archive log
archive log thread=1 sequence=5056
channel ORA_DISK_1: restoring archive log
archive log thread=1 sequence=5057
channel ORA_DISK_1: restoring archive log
archive log thread=1 sequence=5058
channel ORA_DISK_1: restoring archive log
archive log thread=1 sequence=5059
channel ORA_DISK_1: restoring archive log
archive log thread=1 sequence=5060
channel ORA_DISK_1: restoring archive log
archive log thread=1 sequence=5061
channel ORA_DISK_1: restoring archive log
archive log thread=1 sequence=5062
channel ORA_DISK_1: restoring archive log
archive log thread=1 sequence=5063
channel ORA_DISK_1: restoring archive log
archive log thread=1 sequence=5064
channel ORA_DISK_1: restoring archive log
archive log thread=1 sequence=5065
channel ORA_DISK_1: restoring archive log
archive log thread=1 sequence=5066
channel ORA_DISK_1: restoring archive log
archive log thread=1 sequence=5067
channel ORA_DISK_1: restoring archive log
archive log thread=1 sequence=5068
channel ORA_DISK_1: restoring archive log
archive log thread=1 sequence=5069
channel ORA_DISK_1: restoring archive log
archive log thread=1 sequence=5070
channel ORA_DISK_1: restored backup piece 1
piece handle=/orarman/arch/al_120_1_695865609 tag=TAG20090826T000008 params=NULL
channel ORA_DISK_1: restore complete
Finished restore at 2009-08-26:20:32:20  
4.7 啟動資料庫到mount狀態,做blockrecover恢復
RMAN> shutdown immediate;
database closed
database dismounted
Oracle instance shut down
RMAN> startup mount;
RMAN> blockrecover datafile 13 block 222840 from backupset;
Starting blockrecover at 2009-08-26:20:34:35
allocated channel: ORA_DISK_1
channel ORA_DISK_1: sid=12 devtype=DISK
channel ORA_DISK_1: restoring block(s)
channel ORA_DISK_1: specifying block(s) to restore from backup set
restoring blocks of datafile 00013
channel ORA_DISK_1: restored block(s) from backup piece 1
piece handle=/orarman/rman/full_115_1_695534417 tag=TAG20090822T040017 params=NULL
channel ORA_DISK_1: block restore complete
starting media recovery
media recovery complete
Finished blockrecover at 2009-08-26:20:58:17

恢復成功,整個過程用了一小時左右。

4.8 檢查資料和驗證壞塊是否消失
SQL> select count(*) from admin.B_JTWF_WFSS;
COUNT(*)
----------
3160945
     RMAN> backup validate datafile 13;
Starting backup at 2009-08-26:21:01:18
using target database controlfile instead of recovery catalog
allocated channel: ORA_DISK_1
channel ORA_DISK_1: sid=18 devtype=DISK
channel ORA_DISK_1: starting full datafile backupset
channel ORA_DISK_1: specifying datafile(s) in backupset
input datafile fno=00013 name=/ora9idata01/oradata/stjj/VIO_DATA_02.dbf
channel ORA_DISK_1: backup set complete, elapsed time: 00:03:35
Finished backup at 2009-08-26:21:04:53
SQL> select * from v$database_block_corruption where file#=13;
no rows selected
對這個表的操作能正常執行,壞記錄已經不存在,透過對比8.22號的匯出記錄到現在增加了12455條記錄,如果用exp恢復的話,要丟失12455條記錄,那後果不可想象。
最後,對資料庫再手工做次物理全備。


5.2 恢復成功總結和心得
這次能成功恢復主要是有rman物理備份和歸檔備份,和9i新特性使用blockrecover來修復資料庫中的壞塊,減少恢復時間。前提必須有成功的rman物理備份。
所以制定一個良好的備份策略是非常重要的,儘量有可能的幫客戶搭建物理備份和邏輯備份,搭建好後,還要盡力去檢查備份日誌是否成功,使損失降低到最低點。

來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/7199859/viewspace-614139/,如需轉載,請註明出處,否則將追究法律責任。

相關文章