文档课题:模拟表存在坏块,索引对坏块对应rowid查询的影响.标签:12,------------------,--------------------,索引,rowid,坏块,id,block From: https://blog.51cto.com/u_12991611/6008541
数据库:oracle 19.12 多租户
测试结果:表存在坏块,若该表有索引,坏块对应的rowid可以查询;若没有索引便不能查询.
1、测试数据
说明:将用以下数据作为测试.
SQL> select rowid,EMPLOYEE_ID,DBMS_ROWID.ROWID_RELATIVE_FNO(ROWID) relative,DBMS_ROWID.ROWID_TO_ABSOLUTE_FNO(ROWID,'ORA1','EMP') absolute,DBMS_ROWID.ROWID_BLOCK_NUMBER(ROWID) blocknum from ORA1.emp;
ROWID EMPLOYEE_ID RELATIVE ABSOLUTE BLOCKNUM
------------------ -------------------- -------------------- -------------------- --------------------
AAASTMAAMAAAAPrAAA 101 12 12 1003
AAASTMAAMAAAAPrAAB 102 12 12 1003
AAASTMAAMAAAAPrAAC 103 12 12 1003
AAASTMAAMAAAAPrAAD 104 12 12 1003
AAASTMAAMAAAAPrAAE 107 12 12 1003
AAASTMAAMAAAAPrAAF 124 12 12 1003
AAASTMAAMAAAAPrAAG 141 12 12 1003
AAASTMAAMAAAAPrAAH 142 12 12 1003
AAASTMAAMAAAAPrAAI 143 12 12 1003
AAASTMAAMAAAAPrAAJ 144 12 12 1003
AAASTMAAMAAAAPrAAK 149 12 12 1003
ROWID EMPLOYEE_ID RELATIVE ABSOLUTE BLOCKNUM
------------------ -------------------- -------------------- -------------------- --------------------
AAASTMAAMAAAAPrAAL 174 12 12 1003
AAASTMAAMAAAAPrAAM 176 12 12 1003
AAASTMAAMAAAAPrAAN 178 12 12 1003
AAASTMAAMAAAAPrAAO 200 12 12 1003
AAASTMAAMAAAAPrAAP 201 12 12 1003
AAASTMAAMAAAAPrAAQ 202 12 12 1003
AAASTMAAMAAAAPrAAR 205 12 12 1003
AAASTMAAMAAAAPrAAS 206 12 12 1003
AAASTMAAMAAAAPrAAT 100 12 12 1003
AAASTMAAMAAAAPrAAU 101 12 12 1003
AAASTMAAMAAAAPrAAV 102 12 12 1003
ROWID EMPLOYEE_ID RELATIVE ABSOLUTE BLOCKNUM
------------------ -------------------- -------------------- -------------------- --------------------
AAASTMAAMAAAAPrAAW 103 12 12 1003
AAASTMAAMAAAAPrAAX 104 12 12 1003
AAASTMAAMAAAAPrAAY 107 12 12 1003
AAASTMAAMAAAAPrAAZ 124 12 12 1003
AAASTMAAMAAAAPrAAa 141 12 12 1003
AAASTMAAMAAAAPrAAb 142 12 12 1003
AAASTMAAMAAAAPrAAc 143 12 12 1003
AAASTMAAMAAAAPrAAd 144 12 12 1003
AAASTMAAMAAAAPrAAe 149 12 12 1003
AAASTMAAMAAAAPrAAf 174 12 12 1003
AAASTMAAMAAAAPrAAg 176 12 12 1003
ROWID EMPLOYEE_ID RELATIVE ABSOLUTE BLOCKNUM
------------------ -------------------- -------------------- -------------------- --------------------
AAASTMAAMAAAAPrAAh 178 12 12 1003
AAASTMAAMAAAAPrAAi 200 12 12 1003
AAASTMAAMAAAAPrAAj 201 12 12 1003
AAASTMAAMAAAAPrAAk 202 12 12 1003
AAASTMAAMAAAAPrAAl 205 12 12 1003
AAASTMAAMAAAAPrAAm 206 12 12 1003
AAASTMAAMAAAAPvAAA 100 12 12 1007
AAASTMAAMAAAAPvAAB 101 12 12 1007
AAASTMAAMAAAAPvAAC 102 12 12 1007
AAASTMAAMAAAAPvAAD 103 12 12 1007
AAASTMAAMAAAAPvAAE 104 12 12 1007
ROWID EMPLOYEE_ID RELATIVE ABSOLUTE BLOCKNUM
------------------ -------------------- -------------------- -------------------- --------------------
AAASTMAAMAAAAPvAAF 107 12 12 1007
AAASTMAAMAAAAPvAAG 124 12 12 1007
AAASTMAAMAAAAPvAAH 141 12 12 1007
AAASTMAAMAAAAPvAAI 142 12 12 1007
AAASTMAAMAAAAPvAAJ 143 12 12 1007
AAASTMAAMAAAAPvAAK 144 12 12 1007
AAASTMAAMAAAAPvAAL 149 12 12 1007
AAASTMAAMAAAAPvAAM 174 12 12 1007
AAASTMAAMAAAAPvAAN 176 12 12 1007
AAASTMAAMAAAAPvAAO 178 12 12 1007
AAASTMAAMAAAAPvAAP 200 12 12 1007
ROWID EMPLOYEE_ID RELATIVE ABSOLUTE BLOCKNUM
------------------ -------------------- -------------------- -------------------- --------------------
AAASTMAAMAAAAPvAAQ 201 12 12 1007
AAASTMAAMAAAAPvAAR 202 12 12 1007
AAASTMAAMAAAAPvAAS 205 12 12 1007
AAASTMAAMAAAAPvAAT 206 12 12 1007
AAASTMAAMAAAAPvAAU 100 12 12 1007
AAASTMAAMAAAAPvAAV 101 12 12 1007
AAASTMAAMAAAAPvAAW 102 12 12 1007
AAASTMAAMAAAAPvAAX 103 12 12 1007
AAASTMAAMAAAAPvAAY 104 12 12 1007
AAASTMAAMAAAAPvAAZ 107 12 12 1007
AAASTMAAMAAAAPvAAa 124 12 12 1007
ROWID EMPLOYEE_ID RELATIVE ABSOLUTE BLOCKNUM
------------------ -------------------- -------------------- -------------------- --------------------
AAASTMAAMAAAAPvAAb 141 12 12 1007
AAASTMAAMAAAAPvAAc 142 12 12 1007
AAASTMAAMAAAAPvAAd 143 12 12 1007
AAASTMAAMAAAAPvAAe 144 12 12 1007
AAASTMAAMAAAAPvAAf 149 12 12 1007
AAASTMAAMAAAAPvAAg 174 12 12 1007
AAASTMAAMAAAAPvAAh 176 12 12 1007
AAASTMAAMAAAAPvAAi 178 12 12 1007
AAASTMAAMAAAAPvAAj 200 12 12 1007
AAASTMAAMAAAAPvAAk 201 12 12 1007
AAASTMAAMAAAAPvAAl 202 12 12 1007
ROWID EMPLOYEE_ID RELATIVE ABSOLUTE BLOCKNUM
------------------ -------------------- -------------------- -------------------- --------------------
AAASTMAAMAAAAPvAAm 205 12 12 1007
AAASTMAAMAAAAPvAAn 206 12 12 1007
AAASTMAAMAAAAPvAAo 100 12 12 1007
AAASTMAAMAAAAPvAAp 101 12 12 1007
AAASTMAAMAAAAPvAAq 102 12 12 1007
AAASTMAAMAAAAPvAAr 103 12 12 1007
AAASTMAAMAAAAPvAAs 104 12 12 1007
AAASTMAAMAAAAPvAAt 107 12 12 1007
AAASTMAAMAAAAPvAAu 124 12 12 1007
AAASTMAAMAAAAPvAAv 141 12 12 1007
AAASTMAAMAAAAPvAAw 142 12 12 1007
ROWID EMPLOYEE_ID RELATIVE ABSOLUTE BLOCKNUM
------------------ -------------------- -------------------- -------------------- --------------------
AAASTMAAMAAAAPvAAx 143 12 12 1007
AAASTMAAMAAAAPvAAy 144 12 12 1007
AAASTMAAMAAAAPvAAz 149 12 12 1007
AAASTMAAMAAAAPvAA0 174 12 12 1007
AAASTMAAMAAAAPvAA1 176 12 12 1007
AAASTMAAMAAAAPvAA2 178 12 12 1007
AAASTMAAMAAAAPvAA3 200 12 12 1007
AAASTMAAMAAAAPvAA4 201 12 12 1007
AAASTMAAMAAAAPvAA5 202 12 12 1007
AAASTMAAMAAAAPvAA6 205 12 12 1007
AAASTMAAMAAAAPvAA7 206 12 12 1007
ROWID EMPLOYEE_ID RELATIVE ABSOLUTE BLOCKNUM
------------------ -------------------- -------------------- -------------------- --------------------
AAASTMAAMAAAAPvAA8 100 12 12 1007
AAASTMAAMAAAAPvAA9 101 12 12 1007
AAASTMAAMAAAAPvAA+ 102 12 12 1007
AAASTMAAMAAAAPvAA/ 103 12 12 1007
AAASTMAAMAAAAPvABA 104 12 12 1007
AAASTMAAMAAAAPvABB 107 12 12 1007
AAASTMAAMAAAAPvABC 124 12 12 1007
AAASTMAAMAAAAPvABD 141 12 12 1007
AAASTMAAMAAAAPvABE 142 12 12 1007
AAASTMAAMAAAAPvABF 143 12 12 1007
AAASTMAAMAAAAPvABG 144 12 12 1007
ROWID EMPLOYEE_ID RELATIVE ABSOLUTE BLOCKNUM
------------------ -------------------- -------------------- -------------------- --------------------
AAASTMAAMAAAAPvABH 149 12 12 1007
AAASTMAAMAAAAPvABI 174 12 12 1007
AAASTMAAMAAAAPvABJ 176 12 12 1007
AAASTMAAMAAAAPvABK 178 12 12 1007
AAASTMAAMAAAAPvABL 200 12 12 1007
AAASTMAAMAAAAPvABM 201 12 12 1007
AAASTMAAMAAAAPvABN 202 12 12 1007
AAASTMAAMAAAAPvABO 205 12 12 1007
AAASTMAAMAAAAPvABP 206 12 12 1007
AAASTMAAMAAAAPvABQ 100 12 12 1007
AAASTMAAMAAAAPvABR 101 12 12 1007
ROWID EMPLOYEE_ID RELATIVE ABSOLUTE BLOCKNUM
------------------ -------------------- -------------------- -------------------- --------------------
AAASTMAAMAAAAPvABS 102 12 12 1007
AAASTMAAMAAAAPvABT 103 12 12 1007
AAASTMAAMAAAAPvABU 104 12 12 1007
AAASTMAAMAAAAPvABV 107 12 12 1007
AAASTMAAMAAAAPvABW 124 12 12 1007
AAASTMAAMAAAAPvABX 141 12 12 1007
AAASTMAAMAAAAPvABY 142 12 12 1007
AAASTMAAMAAAAPvABZ 143 12 12 1007
AAASTMAAMAAAAPvABa 144 12 12 1007
AAASTMAAMAAAAPvABb 149 12 12 1007
AAASTMAAMAAAAPvABc 174 12 12 1007
ROWID EMPLOYEE_ID RELATIVE ABSOLUTE BLOCKNUM
------------------ -------------------- -------------------- -------------------- --------------------
AAASTMAAMAAAAPvABd 176 12 12 1007
AAASTMAAMAAAAPvABe 178 12 12 1007
AAASTMAAMAAAAPvABf 200 12 12 1007
AAASTMAAMAAAAPvABg 201 12 12 1007
AAASTMAAMAAAAPvABh 202 12 12 1007
AAASTMAAMAAAAPvABi 205 12 12 1007
AAASTMAAMAAAAPvABj 206 12 12 1007
AAASTMAAMAAAAPvABk 100 12 12 1007
140 rows selected.
2、测试查询rowid
2.1、无索引
说明:现测试无索引的情况下若存在坏块,是否能查询出坏块对应的rowid.
2.1.1、数据确认
--确认目前无索引。
SQL> select index_name,index_type,table_name,table_owner,table_type from user_indexes where table_name='EMP';
no rows selected
--确认块1003对应的表空间、对象类型、owner,对象名.
SQL> set line 200
SQL> r
1 SELECT tablespace_name, segment_type, owner, segment_name, partition_name
2 FROM dba_extents
3 WHERE file_id = &file_id
4 AND &block_id BETWEEN block_id AND block_id + blocks - 1
5*
Enter value for file_id: 12
old 3: WHERE file_id = &file_id
new 3: WHERE file_id = 12
Enter value for block_id: 1003
old 4: AND &block_id BETWEEN block_id AND block_id + blocks - 1
new 4: AND 1003 BETWEEN block_id AND block_id + blocks - 1
TABLESPACE_NAME SEGMENT_TYPE OWNER SEGMENT_NAME PARTITION_NAME
------------------ ------------------ --------------- --------------- ---------------
USERS TABLE ORA1 EMP
2.1.2、损坏块
说明:此前数据库做过全备.
RMAN> recover datafile 12 block 1003 clear;
Starting recover at 15-JAN-23
using target database control file instead of recovery catalog
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=27 device type=DISK
Finished recover at 15-JAN-23
2.1.3、查rowid
--查询坏块1003对应的rowid
SQL> select /*+ index(ORA1, i_test)?*/
2 rowid
3 from ORA1.EMP
4 where dbms_rowid.rowid_to_absolute_fno(rowid, 'ORA1', 'EMP') = 12
5 and dbms_rowid.rowid_block_number(rowid) = 1003;
and dbms_rowid.rowid_block_number(rowid) = 1003
*
ERROR at line 5:
ORA-01578: ORACLE data block corrupted (file # 12, block # 1003)
ORA-01110: data file 12: '+DATA/ORCLCDB/CBB47E352F7AAEA7E0537885A8C03007/DATAFILE/users.279.1082994667'
小结:如上所示,没有索引的情况下无法查询坏块对应的rowid。
2.2、有索引
2.2.1、恢复坏块
--运用备份恢复块1003.
RMAN> recover datafile 12 block 1003;
Starting recover at 15-JAN-23
using channel ORA_DISK_1
channel ORA_DISK_1: restoring block(s)
channel ORA_DISK_1: specifying block(s) to restore from backup set
restoring blocks of datafile 00012
channel ORA_DISK_1: reading from backup piece +DATA/ORCLCDB/CBB47E352F7AAEA7E0537885A8C03007/BACKUPSET/2023_01_14/nnndf0_tag20230114t180326_0.313.1126116417
channel ORA_DISK_1: piece handle=+DATA/ORCLCDB/CBB47E352F7AAEA7E0537885A8C03007/BACKUPSET/2023_01_14/nnndf0_tag20230114t180326_0.313.1126116417 tag=TAG20230114T180326
channel ORA_DISK_1: restored block(s) from backup piece 1
channel ORA_DISK_1: block restore complete, elapsed time: 00:00:03
starting media recovery
media recovery complete, elapsed time: 00:00:03
Finished recover at 15-JAN-23
2.2.2、创建索引
SQL> create index ind_emp_id on emp(employee_id);
Index created.
SQL> r
1* select index_name,index_type,table_name,table_owner,table_type from user_indexes where table_name='EMP'
INDEX_NAME INDEX_TYPE TABLE_NAME TABLE_OWNER TABLE_TYPE
--------------- --------------- --------------- --------------- -----------
IND_EMP_ID NORMAL EMP ORA1 TABLE
2.2.3、损坏块
RMAN> recover datafile 12 block 1003 clear;
Starting recover at 15-JAN-23
using channel ORA_DISK_1
Finished recover at 15-JAN-23
2.2.4、数据查询
SQL> alter system flush shared_pool;
System altered.
SQL> select count(*) from ora1.emp;
COUNT(*)
----------
140
SQL> select /*+ index(ORA1, i_test)?*/
2 rowid
3 from ORA1.EMP
4 where dbms_rowid.rowid_to_absolute_fno(rowid, 'ORA1', 'EMP') = 12
5 and dbms_rowid.rowid_block_number(rowid) = 1003;
ROWID
------------------
AAASTMAAMAAAAPrAAT
AAASTMAAMAAAAPrAAA
AAASTMAAMAAAAPrAAU
AAASTMAAMAAAAPrAAB
AAASTMAAMAAAAPrAAV
AAASTMAAMAAAAPrAAC
AAASTMAAMAAAAPrAAW
AAASTMAAMAAAAPrAAD
AAASTMAAMAAAAPrAAX
AAASTMAAMAAAAPrAAE
AAASTMAAMAAAAPrAAY
ROWID
------------------
AAASTMAAMAAAAPrAAF
AAASTMAAMAAAAPrAAZ
AAASTMAAMAAAAPrAAG
AAASTMAAMAAAAPrAAa
AAASTMAAMAAAAPrAAH
AAASTMAAMAAAAPrAAb
AAASTMAAMAAAAPrAAI
AAASTMAAMAAAAPrAAc
AAASTMAAMAAAAPrAAJ
AAASTMAAMAAAAPrAAd
AAASTMAAMAAAAPrAAK
ROWID
------------------
AAASTMAAMAAAAPrAAe
AAASTMAAMAAAAPrAAL
AAASTMAAMAAAAPrAAf
AAASTMAAMAAAAPrAAM
AAASTMAAMAAAAPrAAg
AAASTMAAMAAAAPrAAN
AAASTMAAMAAAAPrAAh
AAASTMAAMAAAAPrAAO
AAASTMAAMAAAAPrAAi
AAASTMAAMAAAAPrAAP
AAASTMAAMAAAAPrAAj
ROWID
------------------
AAASTMAAMAAAAPrAAQ
AAASTMAAMAAAAPrAAk
AAASTMAAMAAAAPrAAR
AAASTMAAMAAAAPrAAl
AAASTMAAMAAAAPrAAS
AAASTMAAMAAAAPrAAm
39 rows selected.
SQL> select * from ora1.emp;
select * from ora1.emp
*
ERROR at line 1:
ORA-01578: ORACLE data block corrupted (file # 12, block # 1003)
ORA-01110: data file 12: '+DATA/ORCLCDB/CBB47E352F7AAEA7E0537885A8C03007/DATAFILE/users.279.1082994667'
说明:如上所示,表有索引的情况下,即使存在坏块也能查出表记录数以及坏块对应的rowid,但无法查表内容.