All technological notes.
Corrupted data block:
types of curroptions:
Physical/Media corruptionLogical/Software corruptionCorrupt blocks are discovered 被发现的时间
validation check.
CHECK_OBJECT, if a block is encountered that has a corrupt buffer cache header, then that block is skipped.Whenever a block is read or written, a consistency check is performed:
the database marks a block as media corrupt and then writes it to disk 标记并写入磁碟
Physical/Media corruption:
Physical corruption checking is enabled.默认会检查media corruption is due to faulty hardware
Logical/Software corruption:
Logical corruption checking is disabled. 默认不会检查CHECK LOGICAL option to check for logical corruption.Block media recoveryBlock corruptions can be divided into interblock corruption and intrablock corruption.
intrablock corruption:
physical or logical corruption. 可以是物理或逻辑interblock corruption:
logical corruption. 只能是逻辑ORA-01578 errorORA-01578 error
"ORACLE data block corrupted (file # %s, block # %s)"alert.log fileAlways returns the tablespace relative file number and block number错误信息
ORA-01578 returns the tablespace relative file number相对文件编号OR2-01110 error displays the absolute file number. 绝对文件编号Usually, the result of a hardware problem. 问题诊断
ORA-01578 error is always returned with the same arguments, it is most likely a media corrupt block.Diagnosis:
alert log and operating system log file.ANALYZE command:
ANALYZE TABLE emp VALIDATE STRUCTURE CASCADE ONLINE;Recovery:
Resolve any hardware issues:
Find out whether there are more corruptions.
Hardware failures should be addressed immediately.
| Parameter | Use |
|---|---|
DB_BLOCK_CHECKING |
Prevent memory and data corruption |
DB_BLOCK_CHECKSUM |
Detect I/O storage, disk corruption |
Recommended generic block-corruption parameters:
DB_BLOCK_CHECKING
database blocks.FALSEFULL or MEDIUMDB_BLOCK_CHECKSUM:
cache header of every data block when writing it to disk.Checksums
TYPICALFULLEach of the parameters set to detect corruption impacts performance to varying degrees and thus requires testing before production use.
Block media recovery:
recover only on blocks that are marked corrupt or fail a corruption check.
By default, RMAN searches
flashback logs
media recovery on the blocks. 映像备份优先Block media recovery can use only redo logs for media recovery, not incremental backups. 只使用 redo logsfull or level 0 incremental backups.Benefits
mean time to recover (MTTR)Syntax:
-- Recover a single block
RECOVER DATAFILE 6 BLOCK 3;
-- Recover multiple blocks in multiple data files
RECOVER
DATAFILE 2 BLOCK 43
DATAFILE 2 BLOCK 79
DATAFILE 6 BLOCK 183;
-- Recover all blocks logged in V$DATABASE_BLOCK_CORRUPTION
RECOVER CORRUPTION LIST;
V$DATABASE_BLOCK_CORRUPTION View:
Physical/Media corruption and Logical corruptionExample:
ORA-01578: ORACLE data block corrupted (file # 7, block # 3)
ORA-01110: data file 7: '/oracle/oradata/orcl/tools01l.dbf’
ORA-01578: ORACLE data block corrupted (file # 2, block # 235)
ORA-01110: data file 2: '/oracle/oradata/orcl/undotbsOl.dbf’'
RECOVER
DATAFILE 7 BLOCK 3
DATAFILE 2 BLOCK 235;
ARCHIVELOG mode and be open or mounted with a current control file.proxy copies:
corrupt blocks must be full or level 0 backups. 包含在全备份中Proxy copies:
archived redo logs for the recovery.
level 1 incremental backups.Block media recovery cannot survive a missing or inaccessible archived redo log, although it can sometimes survive missing redo records.flashback logs for good copies of corrupt blocks, Flashback Database must be enabled.
flashback logging is enabled and contains older, uncorrupted versions of the corrupt blocks, then RMAN can use these blocks, possibly speeding up the recovery. flashback logging 可以提高效率, 但前提是启动 flashback.RECOVER. . . BLOCK command:
archive logs from backup if necessarycorrupt blocks before block recovery can take placemethod to get information of corrupt blocks:
LIST FAILURE, VALIDATE, or BACKUP ... VALIDATE commandV$DATABASE_BLOCK_CORRUPTION viewalert log and user trace files (identified in the V$DIAG_INFO view)SQL ANALYZE TABLE and ANALYZE INDEX commandsDBVERIFY utilityBC user, the BCTBS tablespace, and the BCCOPY table.sqlplus / as sysdba
ALTER SESSION SET container=orclpdb;
show con_name
ALTER DATABASE open;
show pdbs
-- CLEANUP from previous run
DROP USER bc CASCADE;
DROP TABLESPACE bctbs INCLUDING CONTENTS AND DATAFILES;
-- Create tablespace
CREATE TABLESPACE bctbs
DATAFILE '/u01/app/oracle/oradata/ORCL/orclpdb/bctbs01.dbf'
SIZE 10M REUSE
SEGMENT SPACE MANAGEMENT MANUAL;
-- Create user
CREATE USER bc IDENTIFIED BY pass4BC
DEFAULT TABLESPACE bctbs
QUOTA UNLIMITED ON bctbs;
GRANT CREATE SESSION TO bc;
-- create table and populate
-- be sure table is at least 2 blocks long
CREATE TABLE bc.bccopy
TABLESPACE bctbs
AS SELECT * FROM HR.EMPLOYEES;
INSERT INTO bc.bccopy
SELECT * FROM bc.bccopy;
INSERT INTO bc.bccopy
SELECT * FROM bc.bccopy;
-- confirm table has been created
SELECT salary
FROM bc.bccopy
WHERE rownum = 1;

rman target "'sys@orclpdb as sysdba'"
-- backup tbsp
BACKUP AS COPY TABLESPACE bctbs;
EXIT

sqlplus / as sysdba
ALTER SESSION SET container=orclpdb;
show con_name
UPDATE bc.bccopy SET salary = salary+1;
COMMIT;
-- confirm updated
SELECT salary
FROM bc.bccopy
WHERE rownum = 1;

Corrupt a data file created
Bccopy table to force the corrupt block to be discovered.sqlplus / as sysdba
ALTER SESSION SET container=orclpdb;
-- Find the file and block numbers
SELECT DISTINCT
MIN(DBMS_ROWID.ROWID_RELATIVE_FNO(rowid)) as FILE_NO,
MIN(DBMS_ROWID.ROWID_BLOCK_NUMBER(rowid)) as BLOCK_NO
FROM bc.bccopy;
-- FILE_NO BLOCK_NO
-- 108 129
ALTER SYSTEM FLUSH BUFFER_CACHE;

BLOCK_NO column.# linux bash command
# Corrupts 2 consecutive blocks.
# make sure the table is in 2 consequetive blocks
# the location of data file
FILE='/u01/app/oracle/oradata/ORCL/orclpdb/bctbs01.dbf'
# block_no
BLOCK=129
# the block size
BLOCKSIZE=8196
# write the content to the block
dd of=$FILE bs=$BLOCKSIZE conv=notrunc seek=$BLOCK <<EOF
the content is written to block
EOF
dd of=$FILE bs=$BLOCKSIZE conv=notrunc seek=`expr 1 + $BLOCK` <<EOF
the content is written to the next block
EOF

SELECT *
FROM bc.bccopy;
/*
ORA-01578: ORACLE data block corrupted (file # 106, block # 129)
ORA-01110: data file 106: '/u01/app/oracle/oradata/ORCL/orclpdb/bctbs01.dbf'
01578. 00000 - "ORACLE data block corrupted (file # %s, block # %s)"
*Cause: The data block indicated was corrupt. This was a physical
corruption, also called a media corruption. The cause is unknown
but is most likely external to the database. If ORA-26040 is also
signaled, the corruption is due to NOLOGGING or UNRECOVERABLE
operations.
*Action: The general method to repair a media corrupt block is to restore
a backup and recover the backup. For databases in ARCHIVELOG
mode, use block media recovery or media recovery. In some situations,
you can also drop the segment and re-create it. For example, you can
drop an index and re-create the index
*/

SELECT *
FROM V$DATABASE_BLOCK_CORRUPTION;
-- 108 129 2 0 CHECKSUM 3

rman target "'/ as sysbackup'"
-- Check failures
LIST FAILURE;
-- view suggested repair strategy.
ADVISE FAILURE;
-- preview the recovery script
REPAIR FAILURE PREVIEW;
-- # block media recovery for multiple blocks
-- recover datafile 108 block 129 to 130;
-- recover the corrupted blocks.
REPAIR FAILURE;
-- Confirm the recovery
LIST FAILURE;
EXIT

$ sqlplus / as sysdba
alter session set container = orclpdb;
-- query after recovery
SELECT salary
FROM BC.BCCOPY
WHERE rownum = 1;
exit

rman target "'sys@orclpdb as sysdba'"
DELETE NOPROMPT copy of tablespace bctbs;
exit;

sqlplus / as sysdba
ALTER SESSION SET container=orclpdb;
DROP USER bc CASCADE;
DROP TABLESPACE bctbs INCLUDING CONTENTS AND DATAFILES;
EXIT;
proactive health checks: 主动防御, 周期性检查
periodic health checks through
Health MonitorVALIDATE command.In general, when a reactive check detects failure(s) in a database component, you may want to execute a more complete check of the affected component. 被动检查出失败, 则需要全面检查.
VALIDATE command:
corrupt data blocksnever-used blocksbackup sets and data blocks可以检查个别备份和数据文件ADR
LIST FAILURE command to view all failures recorded in the repository.physical corruption only. 默认只检查物理坏块
CHECK LOGICAL to check for logical corruption as well.intrablock corruptions only.VALIDATE DATABASE command
VALIDATE BACKUPSET command.ADR as a finding.V$DATABASE_BLOCK_CORRUPTION view, as well as in the RMAN output.rman target /
-- alidate the database
BACKUP VALIDATE DATABASE ARCHIVELOG ALL;
LIST BACKUP;
-- no backup was created

physical corruption.
CHECK LOGICAL clause to include checks for logical corruption.BACKUP VALIDATE CHECK LOGICAL DATABASE ARCHIVELOG ALL;
