EBS R12.1.3
RDBMS 11.1.0.7
參考文檔 如何格式化不屬於任何段的損壞塊 (Doc ID 1526163.1)
-- 在RMAN進行備份的時候,提示RMAN-03009和ORA-19566錯誤
RMAN-03009: failure of backup command on ORA_DISK_1 channel at 04/09/2020 11:14:59
ORA-19566: exceeded limit of 0 corrupt blocks for file /d01/oracle/PROD/db/apps_st/data/system09.dbf
continuing other job steps, job failed will not be re-run
-- 查看該錯誤號
[oraprod@ebsr121 ~]$ oerr ora 19566
19566, 00000, "exceeded limit of %s corrupt blocks for file %s"
// *Cause: The user specified limit of allowable corrupt blocks was exceeded
// while reading the specified datafile for a datafile copy or
// backup.
// *Action: None. The copy or backup operation fails.
// The session trace file contains detailed information
// about which blocks were corrupt.
[oraprod@ebsr121 ~]$
-- alert log中的日誌,發現有壞塊
Thu Apr 09 10:13:02 2020
Hex dump of (file 352, block 165656) in trace file /d01/oracle/PROD/db/tech_st/11.1.0/admin/TEST_ebsr121/diag/rdbms/test/TEST/trace/TEST_ora_4769.trc
Corrupt block relative dba: 0x58028718 (file 352, block 165656)
Completely zero block found during backing up datafile
Reread of blocknum=165656, file=/d01/oracle/PROD/db/apps_st/data/system09.dbf. found same corrupt data
Reread of blocknum=165656, file=/d01/oracle/PROD/db/apps_st/data/system09.dbf. found same corrupt data
Reread of blocknum=165656, file=/d01/oracle/PROD/db/apps_st/data/system09.dbf. found same corrupt data
Reread of blocknum=165656, file=/d01/oracle/PROD/db/apps_st/data/system09.dbf. found same corrupt data
Reread of blocknum=165656, file=/d01/oracle/PROD/db/apps_st/data/system09.dbf. found same corrupt data
Thu Apr 09 10:13:15 2020
Hex dump of (file 352, block 165657) in trace file /d01/oracle/PROD/db/tech_st/11.1.0/admin/TEST_ebsr121/diag/rdbms/test/TEST/trace/TEST_ora_4769.trc
Corrupt block relative dba: 0x58028719 (file 352, block 165657)
Completely zero block found during backing up datafile
Reread of blocknum=165657, file=/d01/oracle/PROD/db/apps_st/data/system09.dbf. found same corrupt data
Reread of blocknum=165657, file=/d01/oracle/PROD/db/apps_st/data/system09.dbf. found same corrupt data
Reread of blocknum=165657, file=/d01/oracle/PROD/db/apps_st/data/system09.dbf. found same corrupt data
Reread of blocknum=165657, file=/d01/oracle/PROD/db/apps_st/data/system09.dbf. found same corrupt data
Reread of blocknum=165657, file=/d01/oracle/PROD/db/apps_st/data/system09.dbf. found same corrupt data
Thu Apr 09 10:13:32 2020
-- sql語句查詢壞塊 。看官方文檔,當運行了rman後,會將壞塊情況記錄到該視圖中。所以看準確的壞塊還是通過RMAN或者DBV來查看。
SYS@TEST>select file#,block#,corruption_type from v$database_block_corruption;
FILE# BLOCK# CORRUPTIO
---------- ---------- ---------
352 165657 ALL ZERO
352 165656 CORRUPT
SYS@TEST>
-- 使用dbv來檢查system09.dbf文件 。沒有備份,沒有辦法使用rman進行恢復 ,並使用RMAN進行查看損壞的塊
[oraprod@ebsr121 ~]$ rman target /
Recovery Manager: Release 11.1.0.7.0 - Production on Thu Apr 9 17:23:35 2020
Copyright (c) 1982, 2007, Oracle. All rights reserved.
connected to target database: TEST (DBID=2335061898)
RMAN> backup validate check logical datafile 352;
Starting backup at 09-APR-20
using target database control file instead of recovery catalog
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=358 device type=DISK
allocated channel: ORA_DISK_2
channel ORA_DISK_2: SID=361 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=00352 name=/d01/oracle/PROD/db/apps_st/data/system09.dbf
channel ORA_DISK_1: backup set complete, elapsed time: 03:55:03
List of Datafiles
=================
File Status Marked Corrupt Empty Blocks Blocks Examined High SCN
---- ------ -------------- ------------ --------------- ----------
352 FAILED 0 1967 192128 5965138801470
File Name: /d01/oracle/PROD/db/apps_st/data/system09.dbf
Block Type Blocks Failing Blocks Processed
---------- -------------- ----------------
Data 0 131350
Index 0 30379
Other 26468 28432
validate found one or more corrupt blocks
See trace file /d01/oracle/PROD/db/tech_st/11.1.0/admin/TEST_ebsr121/diag/rdbms/test/TEST/trace/TEST_ora_4766.trc for details
Finished backup at 09-APR-20
RMAN>
-- 使用dbv查看 ,最大的壞塊是192128
[oraprod@ebsr121 ~]$ dbv file=/d01/oracle/PROD/db/apps_st/data/system09.dbf
........
Page 192125 is marked corrupt
Corrupt block relative dba: 0x5802ee7d (file 352, block 192125)
Completely zero block found during dbv:
Page 192126 is marked corrupt
Corrupt block relative dba: 0x5802ee7e (file 352, block 192126)
Completely zero block found during dbv:
Page 192127 is marked corrupt
Corrupt block relative dba: 0x5802ee7f (file 352, block 192127)
Completely zero block found during dbv:
Page 192128 is marked corrupt
Corrupt block relative dba: 0x5802ee80 (file 352, block 192128)
Completely zero block found during dbv:
DBVERIFY - Verification complete
Total Pages Examined : 192128
Total Pages Processed (Data) : 66285
Total Pages Failing (Data) : 0
Total Pages Processed (Index): 30379
Total Pages Failing (Index): 0
Total Pages Processed (Other): 1964
Total Pages Processed (Seg) : 0
Total Pages Failing (Seg) : 0
Total Pages Empty : 67027
Total Pages Marked Corrupt : 26473
Total Pages Influx : 0
Total Pages Encrypted : 0
Highest block SCN : 3723896841 (1388.3723896841)
[oraprod@ebsr121 ~]$
-- 再次查看v$database_block_corruption視圖
SYS@TEST>select * from v$database_block_corruption;
FILE# BLOCK# BLOCKS CORRUPTION_CHANGE# CORRUPTIO
---------- ---------- ---------- ------------------ ---------
352 165661 10051 0 ALL ZERO
352 175713 16416 0 ALL ZERO
352 175712 1 0 ALL ZERO
SYS@TEST>
-- 檢查塊是否是某個對象的一部分,-- 適用於損壞的塊號小的情況
SQL> select segment_name, segment_type, owner
from dba_extents
where file_id = <Absolute file number>
and <corrupted block number> between block_id
and block_id + blocks -1;
-- 如果塊不屬於任何對象,查詢dba_free_space確認塊是否屬於數據文件的可用空間
SQL> Select * from dba_free_space where file_id= <Absolute file number>
and <corrupted block number> between block_id and block_id + blocks -1;
-- 查找受影響的塊並驗證其是否屬於任何段的一種比較好的方法是使用RMAN,該方法好用又便捷
backup check logical validate database; -- 前面已經針對352號文件運行過
-- 運行以下SQL,確認塊是位於可用空間中還是已佔用空間中 ,查詢結果是free block
set lines 200 pages 10000
col segment_name format a30
SELECT e.owner, e.segment_type, e.segment_name, e.partition_name, c.file#
, greatest(e.block_id, c.block#) corr_start_block#
, least(e.block_id+e.blocks-1, c.block#+c.blocks-1) corr_end_block#
, least(e.block_id+e.blocks-1, c.block#+c.blocks-1)
- greatest(e.block_id, c.block#) + 1 blocks_corrupted
, null description
FROM dba_extents e, v$database_block_corruption c
WHERE e.file_id = c.file#
AND e.block_id <= c.block# + c.blocks - 1
AND e.block_id + e.blocks - 1 >= c.block#
UNION
SELECT s.owner, s.segment_type, s.segment_name, s.partition_name, c.file#
, header_block corr_start_block#
, header_block corr_end_block#
, 1 blocks_corrupted
, 'Segment Header' description
FROM dba_segments s, v$database_block_corruption c
WHERE s.header_file = c.file#
AND s.header_block between c.block# and c.block# + c.blocks - 1
UNION
SELECT null owner, null segment_type, null segment_name, null partition_name, c.file#
, greatest(f.block_id, c.block#) corr_start_block#
, least(f.block_id+f.blocks-1, c.block#+c.blocks-1) corr_end_block#
, least(f.block_id+f.blocks-1, c.block#+c.blocks-1)
- greatest(f.block_id, c.block#) + 1 blocks_corrupted
, 'Free Block' description
FROM dba_free_space f, v$database_block_corruption c
WHERE f.file_id = c.file#
AND f.block_id <= c.block# + c.blocks - 1
AND f.block_id + f.blocks - 1 >= c.block#
ORDER BY file#, corr_start_block#;
OWNER SEGMENT_TYPE SEGMENT_NAME PARTITION_NAME FILE# CORR_START_BLOCK# CORR_END_BLOCK# BLOCKS_CORRUPTED DESCRIPTION
------------------------------ ------------------ ------------------------------ ------------------------------ ---------- ----------------- --------------- ---------------- --------------
352 165656 165656 1 Free Block
352 165657 165657 1 Free Block
SQL>
-- 以非sys或system用戶的身份創建一個表 ,該表位於出現壞塊的表空間system中,使用nologging選項,避免生成redo
conn scott/tiger
create table s (n number,c varchar2(4000)) nologging tablespace system;
-- 驗證表是否創建在了正確的表空間
select segment_name,tablespace_name from user_segments where segment_name='S' ;
-- 在表上創建觸發器 , 根據dbv的結果,塊號 最高塊 192128 ,數據文件352
conn / as sysdba
CREATE OR REPLACE TRIGGER corrupt_trigger
AFTER INSERT ON scott.s
REFERENCING OLD AS p_old NEW AS new_p
FOR EACH ROW
DECLARE
corrupt EXCEPTION;
BEGIN
IF (dbms_rowid.rowid_block_number(:new_p.rowid)=&blocknumber)
and (dbms_rowid.rowid_relative_fno(:new_p.rowid)=&filenumber) THEN
RAISE corrupt;
END IF;
EXCEPTION
WHEN corrupt THEN
RAISE_APPLICATION_ERROR(-20000, 'Corrupt block has been formatted');
END;
/
-- 爲受影響的數據文件中的表分配空間,這裏計算下來是732264K 。官方文檔計算下來是64K
Select BYTES from dba_free_space where file_id=352 and 192128 between block_id and block_id + blocks -1;
SYS@TEST>Select BYTES from dba_free_space where file_id=352 and 192128 between block_id and block_id + blocks -1;
BYTES
----------
749838336
SYS@TEST>
-- 在本例子中,是732264K,按照以下方法分配extent
alter table scott.s allocate extent (DATAFILE '/d01/oracle/PROD/db/apps_st/data/system09.dbf' SIZE 732264K);
SYS@TEST>alter table scott.s allocate extent (DATAFILE '/d01/oracle/PROD/db/apps_st/data/system09.dbf' SIZE 732264K);
Table altered.
SYS@TEST>
-- 如果在這個數據文件中有多個空閒extent,則可能需要使用這個循環(本例子中沒有使用)
##BEGIN
##for i in 1..1000000 loop
##EXECUTE IMMEDIATE 'alter table scott.s allocate extent (DATAFILE '||'''/d01/oracle/PROD/db/apps_st/data/system09.dbf''' ||'SIZE 64K) ';
##end loop;
##end ;
##/
-- 繼續分配空間,直到壞塊稱爲scott.s的一部分 ,使用以下查詢進行檢查
select segment_name, segment_type, owner
from dba_extents
where file_id = 352
and 192128 between block_id
and block_id + blocks -1 ;
SYS@TEST>select segment_name, segment_type, owner
from dba_extents
where file_id = 352
and 192128 between block_id
and block_id + blocks -1 ; 2 3 4 5
SEGMENT_NAME
--------------------------------------------------------------------------------
SEGMENT_TYPE OWNER
------------------ ------------------------------
S
TABLE SCOTT
SYS@TEST>
-- 向表中插入數據格式化塊 。每向表中插入一行就會觸發觸發器,當向壞塊中插入第一行數據的時候,會產生ORA-2000異常 。
BEGIN
FOR i IN 1..1000000000 LOOP
INSERT /*+ APPEND */ INTO scott.s select i, lpad('REFORMAT',3092, 'R') from dual;
commit ;
END LOOP;
END;
SYS@TEST>BEGIN
FOR i IN 1..1000000000 LOOP
INSERT /*+ APPEND */ INTO scott.s select i, lpad('REFORMAT',3092, 'R') from dual;
commit ;
END LOOP;
END; 2 3 4 5 6
7 /
BEGIN
*
ERROR at line 1:
ORA-20000: Corrupt block has been formatted
ORA-06512: at "SYS.CORRUPT_TRIGGER", line 10
ORA-04088: error during execution of trigger 'SYS.CORRUPT_TRIGGER'
ORA-06512: at line 3
-- 再次通過dbv和rman來檢查壞塊情況 ,dbv檢查結果是0壞塊。rman 檢查結果是ok的 ,檢查視圖v$database_block_corruption,結果是0 。
[oraprod@ebsr121 ~]$ dbv file=/d01/oracle/PROD/db/apps_st/data/system09.dbf
DBVERIFY: Release 11.1.0.7.0 - Production on Fri Apr 10 10:03:44 2020
Copyright (c) 1982, 2007, Oracle. All rights reserved.
DBVERIFY - Verification starting : FILE = /d01/oracle/PROD/db/apps_st/data/system09.dbf
DBVERIFY - Verification complete
Total Pages Examined : 195984
Total Pages Processed (Data) : 157818
Total Pages Failing (Data) : 0
Total Pages Processed (Index): 30379
Total Pages Failing (Index): 0
Total Pages Processed (Other): 1964
Total Pages Processed (Seg) : 0
Total Pages Failing (Seg) : 0
Total Pages Empty : 5823
Total Pages Marked Corrupt : 0
Total Pages Influx : 0
Total Pages Encrypted : 0
Highest block SCN : 3724398416 (1388.3724398416)
[oraprod@ebsr121 ~]$
[oraprod@ebsr121 ~]$ rman target /
Recovery Manager: Release 11.1.0.7.0 - Production on Fri Apr 10 09:59:20 2020
Copyright (c) 1982, 2007, Oracle. All rights reserved.
connected to target database: TEST (DBID=2335061898)
RMAN> backup validate check logical datafile 352;
Starting backup at 10-APR-20
using target database control file instead of recovery catalog
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=354 device type=DISK
allocated channel: ORA_DISK_2
channel ORA_DISK_2: SID=353 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=00352 name=/d01/oracle/PROD/db/apps_st/data/system09.dbf
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:55
List of Datafiles
=================
File Status Marked Corrupt Empty Blocks Blocks Examined High SCN
---- ------ -------------- ------------ --------------- ----------
352 OK 0 5823 195984 5965139005264
File Name: /d01/oracle/PROD/db/apps_st/data/system09.dbf
Block Type Blocks Failing Blocks Processed
---------- -------------- ----------------
Data 0 157818
Index 0 30379
Other 0 1964
Finished backup at 10-APR-20
RMAN>
SYS@TEST>select * from v$database_block_corruption;
no rows selected
SYS@TEST>
-- 清理,drop 掉表,切換日誌和checkpoint後刪除觸發器 。
drop table scott.s;
alter system switch logfile;
alter system switch logfile;
alter system checkpoint;
DROP trigger corrupt_trigger ;
END