상세 컨텐츠

본문 제목

2023년 1월 31일 3교시 블록 손상

오라클 백업 리커버리

by 병아리 엔지니어 2024. 1. 31. 14:45

본문

(6:00)

★ 블록 손상 block corruption

- 블록을 읽거나 쓸 때마다 일관성 검사를 한다.

  1. 블록의 버전을 체크

  2. 블록의 DBA (Data Block Address) 값과 비교되는 캐시의 DBA 값을 체크

      = 디스크에 있는 블록과 메모리에 있는 블록의 주소가 서로 같은지를 체크,

      만약 두 주소가 같지 않으면 블록 손상이 발생한다.

  3. 활성화된 블록의 체크섬 (건강 상태) 을 확인

- 손상이 발생하는 경우

  1. 미디어 손상

  2. 논리적으로 또는 물리적으로 소프트웨어 손상이 발생할 때

 

(12:43)

RMAN> backup as compressed backupset database;

RMAN 에서 백업 새로 받기

 

RMAN> list backup;

더보기

RMAN> list backup;

List of Backup Sets
===================

BS Key  Type LV Size       Device Type Elapsed Time Completion Time
------- ---- -- ---------- ----------- ------------ ---------------
77      Full    325.02M    DISK        00:00:27     31-JAN-24   
        BP Key: 117   Status: AVAILABLE  Compressed: YES  Tag: TAG20240131T135639
        Piece Name: /u01/app/oracle/fast_recovery_area/ORA11G/backupset/2024_01_31/o1_mf_nnndf_TAG20240131T135639_lvmnr7m9_.bkp
  List of Datafiles in backup set 77
  File LV Type Ckp SCN    Ckp Time  Name
  ---- -- ---- ---------- --------- ----
  1       Full 2316427    31-JAN-24 /u01/app/oracle/oradata/ora11g/system01.dbf
  2       Full 2316427    31-JAN-24 /u01/app/oracle/oradata/ora11g/sysaux01.dbf
  3       Full 2316427    31-JAN-24 /u01/app/oracle/oradata/ora11g/fda_tbs01.dbf

 

        fda_tbs가 눈에 거슬린다면 drop tablespace fda_tbs including contents and datafiles; 로 없애 버리고
        백업을 다시 받도록 하자. (선생님은 그냥 했다고 하심)

 

  4       Full 2316427    31-JAN-24 /u01/app/oracle/oradata/ora11g/users01.dbf
  5       Full 2316427    31-JAN-24 /u01/app/oracle/oradata/ora11g/example01.dbf
  6       Full 2316427    31-JAN-24 /u01/app/oracle/oradata/ora11g/undotbs01.dbf

BS Key  Type LV Size       Device Type Elapsed Time Completion Time
------- ---- -- ---------- ----------- ------------ ---------------
78      Full    9.95M      DISK        00:00:01     31-JAN-24   
        BP Key: 118   Status: AVAILABLE  Compressed: NO  Tag: TAG20240131T135714
        Piece Name: /u01/app/oracle/fast_recovery_area/ORA11G/autobackup/2024_01_31/o1_mf_s_1159711034_lvmnsc1d_.bkp
  SPFILE Included: Modification time: 31-JAN-24
  SPFILE db_unique_name: ORA11G
  Control File Included: Ckp SCN: 2316445      Ckp time: 31-JAN-24

(15:15)

샘플 테이블 만들기

SYS@ora11g> create table hr.emp_copy as select * from hr.employees;
Table created.

 

select file_id, block_id
from dba_extents
where segment_name = 'EMP_COPY'
and owner = 'HR';

저 테이블이 어느 데이터파일 안에 들어 있고, 저 테이블에 속한 첫번째 블록 번호는 무엇인지 확인해보기

(파일 아이디는 4번, 첫번째 블록 번호는 1064)

 

 

select file_name from dba_data_files where file_id = 4;

그래서 그 파일번호 4번인 파일이 어떤 파일인지 확인해봤더니:

/u01/app/oracle/oradata/ora11g/users01.dbf

유저 테이블스페이스에 속한 데이터파일이라고 나온다.

 

 

(18:37)

그럼 이제, 저 테이블에 속한 블록을 손상시켜 보자.

 

SYS@ora11g> ! dd if=/dev/zero of=/u01/app/oracle/oradata/ora11g/users01.dbf bs=8192 seek=1064 count=2 conv=notrunc

디스크에 있는 블록 손상시키기

(seek=1064 count=2: 1064 번 블록부터 해서 2 개 손상시킨 것)

 

(QUESTION. 나 이거 이해가 안 가... ㅠㅠ dd if=/dev/zero? 이게 뭐야?)

(ANSWER. 따로따로 뜯어서 보지 말고 저 명령어 전체를 해석해보면

/dev/zero 에서 0으로 채워진 데이터를 읽어 와서 저 of 부분에 표시된 데이터파일의

특정 블록에 쓰는 작업을 수행하라는 뜻이 된다. 그리고 conv=notrunc 옵션은 파일을 잘라내지 않고 데이터를 추가하라는 뜻으로, 저 옵션을 쓰면 파일의 특정 위치에 0으로 채워진 데이터를 쓰지만 기존 파일의 데이터를 삭제하지는 않고 새로운 데이터를 기존 데이터에 추가하게 된다.)

(QUESTION. /dev/zero 에서 데이터를 가져온다고 했는데 그럼 그 /dev/zero 는 뭐야?)

(ANSWER. 리눅스와 유닉스 기반 시스템에서 사용되는 특별한 파일인데

무한히 많은 0으로 채워진 데이터를 생성하는 데 사용된다고 한다...)

(QUESTION. 그리고 of=/u01/app/oracle/oradata/ora11g/users01.dbf 이건 또 뭐야? 이 데이터파일 안에 있는 블록을 손상시키겠다는 뜻인가?)

(ANSWER. 그러하다.)

(QUESTION. 그리고 bs? 블록 사이즈는 뜬금없이 표시를 왜했어? 그냥 문법인가...)

(ANSWER. 주어진 명령어에서 블록 크기를 지정하면 명령이 한 번에 처리하는 데이터 양을 조절할 수 있다고 한다...)

(QUESTION. 그리고 conv=notrunc 는 또 뭐야?)

(ANSWER. 0으로 채워진 데이터를 추가하는데

원래 파일을 잘라내지 않고 수정된 데이터를 추가하고 싶을 때 쓰는 옵션)

더보기

SYS@ora11g> ! dd if=/dev/zero of=/u01/app/oracle/oradata/ora11g/users01.dbf bs=8192 seek=1064 count=2 conv=notrunc
2+0 records in
2+0 records out
16384 bytes (16 kB) copied, 0.000121729 s, 135 MB/s

 

SYS@ora11g>

alter system flush buffer_cache;

데이터 버퍼 캐시 비우기

(QUESTION. 뭔 소리야... 갑자기 DBC 비우기 명령어를 왜썼어?

위에서 만든 테이블에 대한 데이터가 DBC 안에 안남아있게 하려고?)

(ANSWER. 블록이 깨졌으므로 테이블 조회시 오류가 나야 하는데

이미 메모리에 테이블 조회기록이 남아 있어서 메모리에서 테이블을 볼 수 있으므로 오류 발생하지 않음

그래서 메모리를 비운 것)

 

SYS@ora11g>

alter system flush buffer_cache;

 

한번으로는 안되고 두번 해줘야 말을 듣는다고 한다.

 

SYS@ora11g> select count(*) from hr.emp_copy;

  COUNT(*)
----------
       107

 

그리고 테이블을 조회해보면:
원래는 block corrupted 하면서 오류가 발생해야 정상인데 오류가 안 뜬다.

 

DB 내리기

SYS@ora11g> shutdown immediate
Database closed.
Database dismounted.
ORACLE instance shut down.

 

더보기

#########################################

Wed Jan 31 14:09:19 2024
ALTER SYSTEM: Flushing buffer cache

#########################################

 

잠잠...

 

OS 로 나가서 OS 명령어로 체크해보기

 

[oracle@oracle ~]$ dbv userid=system/oracle file=/u01/app/oracle/oradata/ora11g/users01.dbf blocksize=8192

커럽션이 발생한 블록들 보기

더보기

[oracle@oracle ~]$ dbv userid=system/oracle file=/u01/app/oracle/oradata/ora11g/users01.dbf blocksize=8192

 

DBVERIFY: Release 11.2.0.4.0 - Production on Wed Jan 31 14:22:07 2024

Copyright (c) 1982, 2011, Oracle and/or its affiliates.  All rights reserved.

DBVERIFY - Verification starting : FILE = /u01/app/oracle/oradata/ora11g/users01.dbf
Page 128 is marked corrupt
Corrupt block relative dba: 0x01000080 (file 4, block 128)   --- 128 번 블록부터
Completely zero block found during dbv:

Page 129 is marked corrupt
Corrupt block relative dba: 0x01000081 (file 4, block 129 --- 129 번 블록까지 두 블록
Completely zero block found during dbv:

Page 1064 is marked corrupt
Corrupt block relative dba: 0x01000428 (file 4, block 1064)   --- 1064번 블록부터
Completely zero block found during dbv:

Page 1065 is marked corrupt
Corrupt block relative dba: 0x01000429 (file 4, block 1065)    --- 1065번 블록까지 두 블록
Completely zero block found during dbv:

 

128, 129, 1064, 1065 블록 안에 있는 내용 zero 로 만들기


DBVERIFY - Verification complete

Total Pages Examined         : 1120      --- 체크한 총 블록의 수

 

(QUESTION. 근데 저게 정확히 뭘 말하는 거야?

dbv 블록 번호 128 번 / 1064 번에 도착해서 블록 안에 있는 내용을 0으로 만들어 버리기까지

체크한 블록 수라는 거야?)

(ANSWER. 그냥 해당 블록이 망가졌다고 나온 )


Total Pages Processed (Data) : 201       --- 테이블 블록의 수
Total Pages Failing   (Data) : 0       --- 문제가 있는 블록의 수
Total Pages Processed (Index): 64       --- 인덱스 블록의 수
Total Pages Failing   (Index): 0       --- 인덱스 블록 중 문제가 있는 블록의 수
Total Pages Processed (Other): 557       --- 테이블이나 인덱스 외 다른 블록의 수
Total Pages Processed (Seg)  : 111       --- segments 관련 정보 블록 수
Total Pages Failing   (Seg)  : 0       --- segment 관련 정보 블록 중 문제되는 블록 수
Total Pages Empty            : 183       --- 비어 있는 블록 수
Total Pages Marked Corrupt   : 4       --- 문제가 있어서 corrupted 라고 marked 라고 표시해놓 블록의 수
Total Pages Influx           : 0       --- 블록 커럽션을 체크하는 시점에

                                                       만약 다른 사용자가 데이터를 변경하고 있는 블록이 있었다면

                                                       dbv 를 사용하기 위해 다시 읽은 블록 수 (= 누군가 쓰고 있었던 블록 수)

                                                       (influx 후 다시 dbv 사용)
Total Pages Encrypted        : 0       --- 암호화한 블록의 수
Highest block SCN            : 2316734 (0.2316734)       --- 체크한 블록들의 SCN 번호들 중 가장 높은 SCN 번호

원래는 테이블 조회 시점에 데이터가 안나오고

파일번호와 블록번호를 알려주면서 오류가 떠야 정상인데, 지금은 안 띄워주니 어쩔 수 없다.

 

RMAN 으로 와서 RMAN 으로 블록 커럽션을 체크하는 수밖에...

 

RMAN> validate datafile 4;

4번 데이터파일 체크하기: 원래는 marked corrupt 해서 뭐라도 표시가 나와야 하는데 그런 것도 없다.

(왜 이러지...)

더보기

RMAN> validate datafile 4;

Starting validate at 31-JAN-24
using target database control file instead of recovery catalog
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=21 device type=DISK
channel ORA_DISK_1: starting validation of datafile
channel ORA_DISK_1: specifying datafile(s) for validation
input datafile file number=00004 name=/u01/app/oracle/oradata/ora11g/users01.dbf
channel ORA_DISK_1: validation complete, elapsed time: 00:00:03
List of Datafiles
=================
File Status Marked Corrupt Empty Blocks Blocks Examined High SCN
---- ------ -------------- ------------ --------------- ----------
4    FAILED 1              183          1161            2316734 
  File Name: /u01/app/oracle/oradata/ora11g/users01.dbf
  Block Type Blocks Failing Blocks Processed
  ---------- -------------- ----------------
  Data       0              201
  Index      0              64
  Other      3              672

validate found one or more corrupt blocks
See trace file /u01/app/oracle/diag/rdbms/ora11g/ora11g/trace/ora11g_ora_21718.trc for details
Finished validate at 31-JAN-24

 

RMAN> list failure;

더보기

RMAN> list failure;

List of Database Failures
=========================

Failure ID Priority Status    Time Detected Summary
---------- -------- --------- ------------- -------
15151      HIGH     OPEN      31-JAN-24     Datafile 4: '/u01/app/oracle/oradata/ora11g/users01.dbf' contains one or more corrupt blocks
102        HIGH     OPEN      08-JAN-24     One or more non-system datafiles are offline

 

RMAN> list failure 15151 detail;

더보기

RMAN> list failure 15151 detail;

List of Database Failures
=========================

Failure ID Priority Status    Time Detected Summary
---------- -------- --------- ------------- -------
15151      HIGH     OPEN      31-JAN-24     Datafile 4: '/u01/app/oracle/oradata/ora11g/users01.dbf' contains one or more corrupt blocks
  Impact: Some objects in tablespace USERS might be unavailable
  List of child failures for parent failure ID 15151
  Failure ID Priority Status    Time Detected Summary
  ---------- -------- --------- ------------- -------
  15172      HIGH     OPEN      31-JAN-24     Block 1065 in datafile 4: '/u01/app/oracle/oradata/ora11g/users01.dbf' is media corrupt
    Impact: Object EMP_COPY owned by HR might be unavailable
  15166      HIGH     OPEN      31-JAN-24     Block 1064 in datafile 4: '/u01/app/oracle/oradata/ora11g/users01.dbf' is media corrupt
    Impact: Object EMP_COPY owned by HR might be unavailable
  15160      HIGH     OPEN      31-JAN-24     Block 129 in datafile 4: '/u01/app/oracle/oradata/ora11g/users01.dbf' is media corrupt
    Impact: Object DEPT owned by SCOTT might be unavailable
  15154      HIGH     OPEN      31-JAN-24     Block 128 in datafile 4: '/u01/app/oracle/oradata/ora11g/users01.dbf' is media corrupt
    Impact: Object DEPT owned by SCOTT might be unavailable

 

통째로 리커버리해도 되지만 이번에는 손상된 블록만 리커버리해 보자.

 

RMAN> advise failure;

더보기

RMAN> advise failure;

List of Database Failures
=========================

Failure ID Priority Status    Time Detected Summary
---------- -------- --------- ------------- -------
15151      HIGH     OPEN      31-JAN-24     Datafile 4: '/u01/app/oracle/oradata/ora11g/users01.dbf' contains one or more corrupt blocks
  Impact: Some objects in tablespace USERS might be unavailable
  List of child failures for parent failure ID 15151
  Failure ID Priority Status    Time Detected Summary
  ---------- -------- --------- ------------- -------
  15172      HIGH     OPEN      31-JAN-24     Block 1065 in datafile 4: '/u01/app/oracle/oradata/ora11g/users01.dbf' is media corrupt
    Impact: Object EMP_COPY owned by HR might be unavailable
  15166      HIGH     OPEN      31-JAN-24     Block 1064 in datafile 4: '/u01/app/oracle/oradata/ora11g/users01.dbf' is media corrupt
    Impact: Object EMP_COPY owned by HR might be unavailable
  15160      HIGH     OPEN      31-JAN-24     Block 129 in datafile 4: '/u01/app/oracle/oradata/ora11g/users01.dbf' is media corrupt
    Impact: Object DEPT owned by SCOTT might be unavailable
  15154      HIGH     OPEN      31-JAN-24     Block 128 in datafile 4: '/u01/app/oracle/oradata/ora11g/users01.dbf' is media corrupt
    Impact: Object DEPT owned by SCOTT might be unavailable

analyzing automatic repair options; this may take some time
using channel ORA_DISK_1
analyzing automatic repair options complete

Mandatory Manual Actions
========================
no manual actions available

Optional Manual Actions
=======================
no manual actions available

Automated Repair Options
========================
Option Repair Description
------ ------------------
1      Recover multiple corrupt blocks in datafile 4
  Strategy: The repair includes complete media recovery with no data loss
  Repair script: /u01/app/oracle/diag/rdbms/ora11g/ora11g/hm/reco_3336874624.hm

 

RMAN> repair failure preview;

더보기

RMAN> repair failure preview;

Strategy: The repair includes complete media recovery with no data loss
Repair script: /u01/app/oracle/diag/rdbms/ora11g/ora11g/hm/reco_3336874624.hm

contents of repair script:
   # block media recovery for multiple blocks
   recover datafile 4 block 128 to 129, 1064 to 1065;

 

RMAN> repair failure;

Do you really want to execute the above repair (enter YES or NO)? yes

더보기

RMAN> repair failure;

Strategy: The repair includes complete media recovery with no data loss
Repair script: /u01/app/oracle/diag/rdbms/ora11g/ora11g/hm/reco_3336874624.hm

contents of repair script:
   # block media recovery for multiple blocks
   recover datafile 4 block 128 to 129, 1064 to 1065;

Do you really want to execute the above repair (enter YES or NO)? yes
executing repair script

Starting recover at 31-JAN-24
using channel ORA_DISK_1
searching flashback logs for block images until SCN 2316427
finished flashback log search, restored 2 blocks

channel ORA_DISK_1: restoring block(s)
channel ORA_DISK_1: specifying block(s) to restore from backup set
restoring blocks of datafile 00004
channel ORA_DISK_1: reading from backup piece /u01/app/oracle/fast_recovery_area/ORA11G/backupset/2024_01_31/o1_mf_nnndf_TAG20240131T135639_lvmnr7m9_.bkp
channel ORA_DISK_1: piece handle=/u01/app/oracle/fast_recovery_area/ORA11G/backupset/2024_01_31/o1_mf_nnndf_TAG20240131T135639_lvmnr7m9_.bkp tag=TAG20240131T135639
channel ORA_DISK_1: restored block(s) from backup piece 1
channel ORA_DISK_1: block restore complete, elapsed time: 00:00:01

starting media recovery
media recovery complete, elapsed time: 00:00:01

Finished recover at 31-JAN-24
repair failure complete

 

RMAN> validate datafile 4;

더보기

RMAN> validate datafile 4;

Starting validate at 31-JAN-24
using channel ORA_DISK_1
channel ORA_DISK_1: starting validation of datafile
channel ORA_DISK_1: specifying datafile(s) for validation
input datafile file number=00004 name=/u01/app/oracle/oradata/ora11g/users01.dbf
channel ORA_DISK_1: validation complete, elapsed time: 00:00:01
List of Datafiles
=================
File Status Marked Corrupt Empty Blocks Blocks Examined High SCN
---- ------ -------------- ------------ --------------- ----------
4    OK     0              183          1161            2316734 
  File Name: /u01/app/oracle/oradata/ora11g/users01.dbf
  Block Type Blocks Failing Blocks Processed
  ---------- -------------- ----------------
  Data       0              201
  Index      0              64
  Other      0              672

Finished validate at 31-JAN-24

 

RMAN> validate database;

커럽션이 발생한 것이 있는지 데이터베이스 레벨로 체크 : 하나도 없다고 나온다.

(시간이 좀 걸리므로 현장에서는 영업시간에 절대로 하지말기)

더보기

RMAN> validate database;

Starting validate at 31-JAN-24
using channel ORA_DISK_1
channel ORA_DISK_1: starting validation of datafile
channel ORA_DISK_1: specifying datafile(s) for validation
input datafile file number=00001 name=/u01/app/oracle/oradata/ora11g/system01.dbf
input datafile file number=00002 name=/u01/app/oracle/oradata/ora11g/sysaux01.dbf
input datafile file number=00005 name=/u01/app/oracle/oradata/ora11g/example01.dbf
input datafile file number=00006 name=/u01/app/oracle/oradata/ora11g/undotbs01.dbf
input datafile file number=00003 name=/u01/app/oracle/oradata/ora11g/fda_tbs01.dbf
input datafile file number=00004 name=/u01/app/oracle/oradata/ora11g/users01.dbf
channel ORA_DISK_1: validation complete, elapsed time: 00:00:25
List of Datafiles
=================
File Status Marked Corrupt Empty Blocks Blocks Examined High SCN
---- ------ -------------- ------------ --------------- ----------
1    OK     0              14230        96005           2319257 
  File Name: /u01/app/oracle/oradata/ora11g/system01.dbf
  Block Type Blocks Failing Blocks Processed
  ---------- -------------- ----------------
  Data       0              63981
  Index      0              13478
  Other      0              4311

File Status Marked Corrupt Empty Blocks Blocks Examined High SCN
---- ------ -------------- ------------ --------------- ----------
2    OK     0              17303        93550           2319256 
  File Name: /u01/app/oracle/oradata/ora11g/sysaux01.dbf
  Block Type Blocks Failing Blocks Processed
  ---------- -------------- ----------------
  Data       0              23322
  Index      0              17789
  Other      0              35026

File Status Marked Corrupt Empty Blocks Blocks Examined High SCN
---- ------ -------------- ------------ --------------- ----------
3    OK     0              1085         1280            2300845 
  File Name: /u01/app/oracle/oradata/ora11g/fda_tbs01.dbf
  Block Type Blocks Failing Blocks Processed
  ---------- -------------- ----------------
  Data       0              40
  Index      0              1
  Other      0              154

File Status Marked Corrupt Empty Blocks Blocks Examined High SCN
---- ------ -------------- ------------ --------------- ----------
4    OK     0              183          1161            2316734 
  File Name: /u01/app/oracle/oradata/ora11g/users01.dbf
  Block Type Blocks Failing Blocks Processed
  ---------- -------------- ----------------
  Data       0              201
  Index      0              64
  Other      0              672

File Status Marked Corrupt Empty Blocks Blocks Examined High SCN
---- ------ -------------- ------------ --------------- ----------
5    OK     0              31355        43363           2308784 
  File Name: /u01/app/oracle/oradata/ora11g/example01.dbf
  Block Type Blocks Failing Blocks Processed
  ---------- -------------- ----------------
  Data       0              6583
  Index      0              1145
  Other      0              4277

File Status Marked Corrupt Empty Blocks Blocks Examined High SCN
---- ------ -------------- ------------ --------------- ----------
6    OK     0              1            5219            2319257 
  File Name: /u01/app/oracle/oradata/ora11g/undotbs01.dbf
  Block Type Blocks Failing Blocks Processed
  ---------- -------------- ----------------
  Data       0              0
  Index      0              0
  Other      0              5215

channel ORA_DISK_1: starting validation of datafile
channel ORA_DISK_1: specifying datafile(s) for validation
including current control file for validation
including current SPFILE in backup set
channel ORA_DISK_1: validation 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              632
Finished validate at 31-JAN-24

관련글 더보기