文档课题:模拟备库单个索引坏块,主库进行rebuild后测试备库是否能正常备份.
数据库:oracle 11.2.0.4
环境:rac(2节点)+dg(2节点)
系统:rhel 7.9
应用场景:rac(2节点)且有2个备库,当其中一个备库出现异常,需要在另一个备库执行增量备份进行恢复时,发现其存在索引坏块导致备份失败.此文章将测试在主库进行rebuild后,备库是否能正常备份.
1、建测试数据
1.1、建表空间
SYS@orcl1> create tablespace tbs_tst_idx datafile '+data' size 10m autoextend on;
Tablespace created.
SYS@orcl1> select name,bytes/1024/1024 "size(M)" from v$datafile;
NAME size(M)
------------------------------------------------------------ ----------
+DATA/orcl/datafile/system.259.1132745549 1060
+DATA/orcl/datafile/sysaux.260.1132745551 600
+DATA/orcl/datafile/undotbs1.261.1132745553 840
+DATA/orcl/datafile/undotbs2.263.1132745567 200
+DATA/orcl/datafile/users.264.1132745567 5
+DATA/orcl/datafile/users.285.1133862437 50
+DATA/orcl/datafile/users.284.1133862457 50
+DATA/orcl/datafile/users.283.1133862473 50
+DATA/orcl/datafile/users.282.1133862489 50
+DATA/orcl/datafile/users.281.1133862509 50
+DATA/orcl/datafile/users.280.1133862525 50
NAME size(M)
------------------------------------------------------------ ----------
+DATA/orcl/datafile/users.279.1133862553 50
+DATA/orcl/datafile/users.278.1133862571 50
+DATA/orcl/datafile/users.277.1133862585 50
+DATA/orcl/datafile/users.276.1133862603 50
+DATA/orcl/datafile/users.275.1133862625 50
+DATA/orcl/datafile/users.274.1133862645 50
+DATA/orcl/datafile/tbs_tst_idx.286.1134752063 10
18 rows selected.
1.2、建测试用户
SYS@orcl1> create user leo identified by leo;
User created.
SYS@orcl1> grant select on dba_objects to leo;
Grant succeeded.
SYS@orcl1> grant connect,resource,unlimited tablespace to leo;
Grant succeeded.
SYS@orcl1> grant create any index to leo;
Grant succeeded.
1.3、建测试表
SYS@orcl1> conn leo/leo;
Connected.
LEO@orcl1> create table tb_obj tablespace users as select * from dba_objects;
Table created.
LEO@orcl1> insert into tb_obj select * from tb_obj;
86291 rows created.
LEO@orcl1> insert into tb_obj select * from tb_obj;
172582 rows created.
LEO@orcl1> insert into tb_obj select * from tb_obj;
345164 rows created.
LEO@orcl1> commit;
Commit complete.
LEO@orcl1> select count(*) from tb_obj;
COUNT(*)
----------
690328
--查表大小
SYS@orcl1> select blocks,bytes from dba_segments where owner='LEO' and segment_name='TB_OBJ';
BLOCKS BYTES
---------- ----------
10240 83886080
1.4、建测试索引
LEO@orcl1> create index IDX_OBJ_NAME on TB_OBJ(OBJECT_NAME) tablespace tbs_tst_idx;
Index created.
LEO@orcl1> col column_name for a15
LEO@orcl1> select index_name,table_name,column_name from user_ind_columns;
INDEX_NAME TABLE_NAME COLUMN_NAME
------------------------------ ------------------------------ ---------------
IDX_OBJ_NAME TB_OBJ OBJECT_NAME
LEO@orcl1> col index_name for a15
LEO@orcl1> col index_type for a15
LEO@orcl1> col table_owner for a15
LEO@orcl1> col table_name for a15
LEO@orcl1> select index_name,index_type,table_owner,table_name,table_type from user_indexes where table_name='TB_OBJ';
INDEX_NAME INDEX_TYPE TABLE_OWNER TABLE_NAME TABLE_TYPE
--------------- --------------- --------------- --------------- -----------
IDX_OBJ_NAME NORMAL LEO TB_OBJ TABLE
--查索引大小
SYS@orcl1> select blocks,bytes from dba_segments where owner='LEO' and segment_name='IDX_OBJ_NAME';
BLOCKS BYTES
---------- ----------
3584 29360128
1.5、表和索引相关信息
--如下查询可知有3449个叶子节点块.
LEO@orcl1> select table_name,index_name,blevel,leaf_blocks,num_rows,last_analyzed,degree,status from user_indexes where table_name='TB_OBJ';
TABLE_NAME INDEX_NAME BLEVEL LEAF_BLOCKS NUM_ROWS LAST_ANALYZED DEGREE STATUS
--------------- --------------- ---------- ----------- ---------- ------------------ ---------------------------------------- --------
TB_OBJ IDX_OBJ_NAME 2 3449 690328 21-APR-23 1 VALID
--查索引及表的object_id
LEO@orcl1> select object_id from user_objects where object_name='IDX_OBJ_NAME';
OBJECT_ID
----------
87191
SYS@orcl1> select object_id,object_name from dba_objects where owner='LEO';
OBJECT_ID OBJECT_NAME
---------- ---------------
87190 TB_OBJ
87191 IDX_OBJ_NAME
2、模拟索引坏块
2.1、查索引所在块
SYS@orcldg> select open_mode from v$database;
OPEN_MODE
--------------------
READ ONLY WITH APPLY
SYS@orcldg> col name for a60
SYS@orcldg> set line 200
SYS@orcldg> select file#,name,bytes/1024/1024 "size(M)" from v$datafile;
FILE# NAME size(M)
---------- ------------------------------------------------------------ ----------
1 /u01/app/oracle/oradata/system.259.1132745549 1060
2 /u01/app/oracle/oradata/sysaux.260.1132745551 600
3 /u01/app/oracle/oradata/undotbs1.261.1132745553 840
4 /u01/app/oracle/oradata/undotbs2.263.1132745567 200
5 /u01/app/oracle/oradata/users.264.1132745567 5
6 /u01/app/oracle/oradata/users.285.1133862437 50
7 /u01/app/oracle/oradata/users.284.1133862457 50
8 /u01/app/oracle/oradata/users.283.1133862473 50
9 /u01/app/oracle/oradata/users.282.1133862489 50
10 /u01/app/oracle/oradata/users.281.1133862509 50
11 /u01/app/oracle/oradata/users.280.1133862525 50
FILE# NAME size(M)
---------- ------------------------------------------------------------ ----------
12 /u01/app/oracle/oradata/users.279.1133862553 50
13 /u01/app/oracle/oradata/users.278.1133862571 50
14 /u01/app/oracle/oradata/users.277.1133862585 50
15 /u01/app/oracle/oradata/users.276.1133862603 50
16 /u01/app/oracle/oradata/users.275.1133862625 50
17 /u01/app/oracle/oradata/users.274.1133862645 50
18 /u01/app/oracle/oradata/tbs_tst_idx.286.1134752063 40
18 rows selected.
--以下查索引所在数据块
SYS@orcldg> select extent_id,file_id,block_id,blocks from dba_extents where owner='LEO' and segment_name='IDX_OBJ_NAME' order by 1;
EXTENT_ID FILE_ID BLOCK_ID BLOCKS
---------- ---------- ---------- ----------
0 18 3720 8
1 18 3728 8
2 18 3736 8
3 18 3744 8
4 18 3752 8
5 18 3760 8
6 18 3768 8
7 18 3776 8
8 18 3784 8
9 18 3792 8
10 18 3800 8
EXTENT_ID FILE_ID BLOCK_ID BLOCKS
---------- ---------- ---------- ----------
11 18 3808 8
12 18 3816 8
13 18 3824 8
14 18 3832 8
15 18 3840 8
16 18 3968 128
17 18 4096 128
18 18 4224 128
19 18 4352 128
20 18 4480 128
21 18 4608 128
EXTENT_ID FILE_ID BLOCK_ID BLOCKS
---------- ---------- ---------- ----------
22 18 4736 128
23 18 4864 128
24 18 4992 128
25 18 5120 128
26 18 5248 128
27 18 5376 128
28 18 5504 128
29 18 5632 128
30 18 5760 128
31 18 5888 128
32 18 6016 128
EXTENT_ID FILE_ID BLOCK_ID BLOCKS
---------- ---------- ---------- ----------
33 18 6144 128
34 18 6272 128
35 18 6400 128
36 18 6528 128
37 18 6656 128
38 18 6784 128
39 18 6912 128
40 18 7040 128
41 18 7168 128
42 18 7296 128
43 rows selected.
2.2、损坏索引块
--运用dd损坏索引块.
[oracle@hisdbdg backup]$ dd of=/u01/app/oracle/oradata/tbs_tst_idx.286.1134752063 bs=8192 conv=notrunc seek=3809 <<EOF
> Corrupted block!
> EOF
0+1 records in
0+1 records out
17 bytes (17 B) copied, 7.5222e-05 s, 226 kB/s
2.3、验证索引块损坏
[oracle@hisdbdg ~]$ rman target /
Recovery Manager: Release 11.2.0.4.0 - Production on Sun Apr 23 22:46:16 2023
Copyright (c) 1982, 2011, Oracle and/or its affiliates. All rights reserved.
connected to target database: ORCL (DBID=1660526279)
RMAN> backup check logical validate datafile 18;
Starting backup at 23-APR-23
using target database control file instead of recovery catalog
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=135 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=00018 name=/u01/app/oracle/oradata/tbs_tst_idx.286.1134752063
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:01
List of Datafiles
=================
File Status Marked Corrupt Empty Blocks Blocks Examined High SCN
---- ------ -------------- ------------ --------------- ----------
18 FAILED 0 115 7683 1346340
File Name: /u01/app/oracle/oradata/tbs_tst_idx.286.1134752063
Block Type Blocks Failing Blocks Processed
---------- -------------- ----------------
Data 0 0
Index 0 3466
Other 1 4099
validate found one or more corrupt blocks
See trace file /u01/app/oracle/diag/rdbms/orcldg/orcldg/trace/orcldg_ora_3566.trc for details
Finished backup at 23-APR-23
RMAN> exit
Recovery Manager complete.
[oracle@hisdbdg ~]$ sqlplus / as sysdba
SQL*Plus: Release 11.2.0.4.0 Production on Sun Apr 23 22:46:49 2023
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
SYS@orcldg> select * from v$database_block_corruption;
FILE# BLOCK# BLOCKS CORRUPTION_CHANGE# CORRUPTIO
---------- ---------- ---------- ------------------ ---------
18 3809 1 0 CORRUPT
SYS@orcldg> exit
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@hisdbdg ~]$ rman target /
Recovery Manager: Release 11.2.0.4.0 - Production on Sun Apr 23 22:48:27 2023
Copyright (c) 1982, 2011, Oracle and/or its affiliates. All rights reserved.
connected to target database: ORCL (DBID=1660526279)
RMAN> backup datafile 18;
Starting backup at 23-APR-23
using target database control file instead of recovery catalog
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=135 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=00018 name=/u01/app/oracle/oradata/tbs_tst_idx.286.1134752063
channel ORA_DISK_1: starting piece 1 at 23-APR-23
RMAN-00571: ===========================================================
RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============
RMAN-00571: ===========================================================
RMAN-03009: failure of backup command on ORA_DISK_1 channel at 04/23/2023 22:48:37
ORA-19566: exceeded limit of 0 corrupt blocks for file /u01/app/oracle/oradata/tbs_tst_idx.286.1134752063
说明:如上所示,成功模拟出生产环境备库索引块的损坏,导致备份失败.
3、主库rebuild
--主库进行rebuild索引.
[oracle@hisdb1 ~]$ sqlplus / as sysdba
SQL*Plus: Release 11.2.0.4.0 Production on Sun Apr 23 22:49:42 2023
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, Real Application Clusters, Automatic Storage Management, OLAP,
Data Mining and Real Application Testing options
SYS@orcl1> alter index leo.idx_obj_name rebuild online;
Index altered.
4、备份验证
备库进行备份验证.
[oracle@hisdbdg ~]$ rman target /
Recovery Manager: Release 11.2.0.4.0 - Production on Sun Apr 23 22:59:35 2023
Copyright (c) 1982, 2011, Oracle and/or its affiliates. All rights reserved.
connected to target database: ORCL (DBID=1660526279)
RMAN> backup datafile 18;
Starting backup at 23-APR-23
using target database control file instead of recovery catalog
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=135 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=00018 name=/u01/app/oracle/oradata/tbs_tst_idx.286.1134752063
channel ORA_DISK_1: starting piece 1 at 23-APR-23
channel ORA_DISK_1: finished piece 1 at 23-APR-23
piece handle=/u01/app/oracle/fast_recovery_area/ORCLDG/backupset/2023_04_23/o1_mf_nnndf_TAG20230423T225944_l4bkz0gg_.bkp tag=TAG20230423T225944 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:03
Finished backup at 23-APR-23
RMAN> backup check logical validate datafile 18;
Starting backup at 23-APR-23
using channel ORA_DISK_1
channel ORA_DISK_1: starting full datafile backup set
channel ORA_DISK_1: specifying datafile(s) in backup set
input datafile file number=00018 name=/u01/app/oracle/oradata/tbs_tst_idx.286.1134752063
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:01
List of Datafiles
=================
File Status Marked Corrupt Empty Blocks Blocks Examined High SCN
---- ------ -------------- ------------ --------------- ----------
18 FAILED 0 59 7683 1489684
File Name: /u01/app/oracle/oradata/tbs_tst_idx.286.1134752063
Block Type Blocks Failing Blocks Processed
---------- -------------- ----------------
Data 0 0
Index 0 6932
Other 1 689
validate found one or more corrupt blocks
See trace file /u01/app/oracle/diag/rdbms/orcldg/orcldg/trace/orcldg_ora_3719.trc for details
Finished backup at 23-APR-23
说明:如上所示,备份无异常发生,但索引坏块依然存在.