模拟备库块损坏
使用swingbench给主库施加一定的压力
./oewizard -cl -create -scale 1 -cs //192.168.×:1521/guangxi -dbap dingjia -u soe1 -p soe1 -ts soe1 -df /u01/app/oracle/oradata/guangxi/soe1.dbf -s ./charbench -c ../configs/SOE_Server_Side_V2.xml -u soe1 -p soe1 -r hu.xml -stats full -dbap dingjia -dbau "sys as sysdba" -uc 1 -rt 0:01 -cs //192.168.×/guangxil
手工用dd在备库上制作一个坏块。
$ dd of=/u01/app/oracle/oradata/guangxist/system01.dbf bs=8192 conv=notrunc seek=23 <<EOF > Corrupt block! Corrupt block! Corrupt block! Corrupt block! Corrupt block! > EOF 0+1 records in 0+1 records out 75 bytes (75 B) copied, 0.00150869 s, 49.7 kB/s
检查备库,发现已经有坏块了:
RMAN> backup validate check logical tablespace system; Starting backup at 09-JUN-20 using target database control file instead of recovery catalog allocated channel: ORA_DISK_1 channel ORA_DISK_1: SID=1149 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=00001 name=/u01/app/oracle/oradata/guangxist/system01.dbf channel ORA_DISK_1: backup set complete, elapsed time: 00:00:03 List of Datafiles ================= File Status Marked Corrupt Empty Blocks Blocks Examined High SCN ---- ------ -------------- ------------ --------------- ---------- 1 FAILED 0 18740 41600 2616809 File Name: /u01/app/oracle/oradata/guangxist/system01.dbf Block Type Blocks Failing Blocks Processed ---------- -------------- ---------------- Data 0 14917 Index 0 4865 Other 1 3078 validate found one or more corrupt blocks See trace file /u01/app/oracle/diag/rdbms/guangxi1/guangxist/trace/guangxist_ora_22286.trc for details channel ORA_DISK_1: starting full datafile backup set channel ORA_DISK_1: specifying datafile(s) in backup set including current control file in backup set including current SPFILE in backup set channel ORA_DISK_1: backup set complete, elapsed time: 00:00:01 List of Control File and SPFILE =============================== File Type Status Blocks Failing Blocks Examined ------------ ------ -------------- --------------- SPFILE OK 0 2 Control File OK 0 596 Finished backup at 09-JUN-20 SQL> select * from v$database_block_corruption; FILE# BLOCK# BLOCKS CORRUPTION_CHANGE# CORRUPTIO ---------- ---------- ---------- ------------------ --------- 1 23 1 0 CORRUPT SQL> set linesize 200 select d.DB_UNIQUE_NAME,d.open_mode,d.log_mode,d.DATABASE_ROLE,d.PROTECTION_MODE from v$database d;SQL> DB_UNIQUE_NAME OPEN_MODE LOG_MODE DATABASE_ROLE PROTECTION_MODE ------------------------------ -------------------- ------------ ---------------- -------------------- guangxi1 MOUNTED ARCHIVELOG PHYSICAL STANDBY MAXIMUM PERFORMANCE SQL>
在主库执行被损坏的表空间的备份并传输到备库
RMAN> backup datafile 1 format '/u01/app/oracle/oradata/guangxi/systembk-%U.dbf'; [oracle@oracle11-1 ~]$ scp /u01/app/oracle/oradata/guangxi/systembk-0* oracle@192.168.×:/u01/app/oracle/oradata oracle@192.168.×'s password: systembk-0rv2api9_1_1.dbf 100% 191MB 10.6MB/s 00:18 systembk-0sv2apig_1_1.dbf 100% 9632KB 4.7MB/s 00:02
在备库上恢复
停止备库的同步
SQL> ALTER DATABASE RECOVER MANAGED STANDBY DATABASE CANCEL;
使用rman恢复备份集:
RMAN> catalog start with '/u01/app/oracle/oradata/systembk-0rv2api9_1_1.dbf'; RMAN> catalog start with '/u01/app/oracle/oradata/systembk-0sv2apig_1_1.dbf'; RMAN> restore datafile 1; Starting restore at 09-JUN-20 using target database control file instead of recovery catalog allocated channel: ORA_DISK_1 channel ORA_DISK_1: SID=13 device type=DISK channel ORA_DISK_1: starting datafile backup set restore channel ORA_DISK_1: specifying datafile(s) to restore from backup set channel ORA_DISK_1: restoring datafile 00001 to /u01/app/oracle/oradata/guangxist/system01.dbf channel ORA_DISK_1: reading from backup piece /u01/app/oracle/oradata/systembk-0rv2api9_1_1.dbf channel ORA_DISK_1: piece handle=/u01/app/oracle/oradata/systembk-0rv2api9_1_1.dbf tag=TAG20200609T134648 channel ORA_DISK_1: restored backup piece 1 channel ORA_DISK_1: restore complete, elapsed time: 00:00:15 Finished restore at 09-JUN-20
恢复完成再检验,发现坏块已经修复:
RMAN> backup validate check logical tablespace system; Starting backup at 09-JUN-20 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=00001 name=/u01/app/oracle/oradata/guangxist/system01.dbf channel ORA_DISK_1: backup set complete, elapsed time: 00:00:07 List of Datafiles ================= File Status Marked Corrupt Empty Blocks Blocks Examined High SCN ---- ------ -------------- ------------ --------------- ---------- 1 OK 0 11572 41601 2693637 File Name: /u01/app/oracle/oradata/guangxist/system01.dbf Block Type Blocks Failing Blocks Processed ---------- -------------- ---------------- Data 0 14917 Index 0 4865 Other 0 10246 channel ORA_DISK_1: starting full datafile backup set channel ORA_DISK_1: specifying datafile(s) in backup set including current control file in backup set including current SPFILE in backup set channel ORA_DISK_1: backup set complete, elapsed time: 00:00:01 List of Control File and SPFILE =============================== File Type Status Blocks Failing Blocks Examined ------------ ------ -------------- --------------- SPFILE OK 0 2 Control File OK 0 596 Finished backup at 09-JUN-20 RMAN>
启动主库备库的数据同步
SQL> select * from v$database_block_corruption; no rows selected SQL> ALTER DATABASE RECOVER MANAGED STANDBY DATABASE DISCONNECT FROM SESSION; Database altered.
验证数据同步正常