이 포스트는 Oracle® 데이터베이스에서 시스템 데이터 파일을 포함한 데이터 파일의 단일 또는 다중 블록 손상을 복구하는 방법에 대해 논의합니다. 블록 손상은 데이터베이스 중단의 일반적인 원인입니다.
데이터베이스 블록의 내용이 Oracle 데이터베이스가 찾기를 기대하는 것과 다를 때 블록이 손상된 것입니다. 블록 손상이 방지되거나 복구되지 않으면, 손상이 데이터베이스를 다운시키고 주요 비즈니스 데이터의 손실을 초래할 수 있습니다.
이것은 프로덕션 데이터베이스에서 직면하고 수정해야 하는 실시간 문제 중 하나입니다.
블록 손상 찾기 및 수정
다음 이미지는 가능한 블록 손상을 보여줍니다:
이미지 출처: https://blog.toadworld.com/2017/12/01/block-corruption-in-an-oracle-database
손상 찾기
손상을 찾으려면 다음 명령어를 실행하세요:
SQL> select * from V$DATABASE_BLOCK_CORRUPTION; FILE# BLOCK# BLOCKS CORRUPTION_CHANGE# CORRUPTION ----- ---------- ---------- ------------------ ---------- 352 173191 9 0 ALL ZERO SQL> SELECT FILE_ID,RELATIVE_FNO,FILE_NAME,TABLESPACE_NAME FROM DBA_DATA_FILES WHERE FILE_ID=352; FILE_ID RELATIVE_FNO FILE_NAME TABLESPACE_NAME ---------- ------------ -------------------------------------------------- ------------------ 352 352 /u01/apps_st/samusxxxxxxxx_data2/system09.dbf SYSTEM SQL> SELECT owner, segment_name, segment_type FROM dba_extents WHERE RELATIVE_FNO = 352 AND Block_id BETWEEN 173191 AND 173191 + blocks - 1; OWNER SEGMENT_NAME SEGMENT_TYPE -------- --------------- ------------------ SYS I_COL3 INDEX SYS C_OBJ# CLUSTER
참고: 이 경우, SYS 객체 세그먼트 I_COL3에 블록 손상이 있습니다. dbv 명령어로 보고된 손상된 블록은 dba_free_space 뷰에서 free로 표시됩니다.
블록 해제
파일 352의 블록을 해제하려면 다음 명령어를 실행하세요:
SQL> select * from V$DATABASE_BLOCK_CORRUPTION; FILE# BLOCK# BLOCKS CORRUPTION_CHANGE# CORRUPTION ----- ---------- ---------- ------------------ ---------- 352 173191 9 0 ALL ZERO SQL> Select * from dba_free_space where file_id =352 and 173191 between block_id and block_id + blocks -1; TABLESPACE_NAME FILE_ID BLOCK_ID BYTES BLOCKS RELATIVE_FNO --------------- ------- -------- ----- ---------- ------------ SYSTEM 352 173191 73728 9 352
블록 강제 정리
블록이 해제된 후, 다음 명령어를 사용하여 해당 손상된 블록을 강제로 정리할 수 있습니다. 이는 어떤 세그먼트에도 속하지 않은 손상된 블록을 포맷하는 것으로도 알려져 있습니다.
1. 사용자 생성 및 데이터베이스 액세스 권한 부여.
create user Scott identified by password default tablespace SYSTEM; grant resource, connect, create table, create trigger to Scott;
2. 데이터 파일에 대한 손상된 블록 식별
[Thu Nov 17 11:59:19 orbdev@samusxxxxxxxx:~ ] $ dbv file='/mnt/apps_st/samusxxxxxxxx_data2/system09.dbf' userid=sys/xxxxx DBVERIFY: Release 11.2.0.4.0 - Production on Thu Nov 17 11:59:21 2016 Copyright (c) 1982, 2011, Oracle and/or its affiliates. All rights reserved. DBVERIFY - Verification starting: FILE = /mnt/apps_st/samusxxxxxxxx_data2/system09.dbf Page 173191 is marked corrupt Corrupt block relative dba: 0x5802a487 (file 352, block 173191) Completely zero block found during dbv: Page 173192 is marked corrupt Corrupt block relative dba: 0x5802a488 (file 352, block 173192) Completely zero block found during dbv: Page 173193 is marked corrupt Corrupt block relative dba: 0x5802a489 (file 352, block 173193) Completely zero block found during dbv: Page 173194 is marked corrupt Corrupt block relative dba: 0x5802a48a (file 352, block 173194) Completely zero block found during dbv: Page 173195 is marked corrupt Corrupt block relative dba: 0x5802a48b (file 352, block 173195) Completely zero block found during dbv: Page 173196 is marked corrupt Corrupt block relative dba: 0x5802a48c (file 352, block 173196) Completely zero block found during dbv: Page 173197 is marked corrupt Corrupt block relative dba: 0x5802a48d (file 352, block 173197) Completely zero block found during dbv: Page 173198 is marked corrupt Corrupt block relative dba: 0x5802a48e (file 352, block 173198) Completely zero block found during dbv: Page 173199 is marked corrupt Corrupt block relative dba: 0x5802a48f (file 352, block 173199) Completely zero block found during dbv: DBVERIFY - Verification complete Total Pages Examined : 917504 Total Pages Processed (Data): 253735 Total Pages Failing (Data) : 0 Total Pages Processed (Index): 335744 Total Pages Failing (Index): 0 Total Pages Processed (Other): 375 Total Pages Processed (Seg) : 17 Total Pages Failing (Seg) : 0 Total Pages Empty : 327624 Total Pages Marked Corrupt : 9 Total Pages Influx : 0 Total Pages Encrypted : 0 Highest block SCN : 3412538527 (1421.3412538527) [Thu Nov 17 12:00:13 orbdev@samusxxxxxxxx:~ ] $
3. 자유 공간 찾기
Select * from dba_free_space where file_id= <Absolute file number> and <corrupted block number> between block_id and block_id + blocks -1; SQL> Select * from dba_free_space where file_id=352 and 173191 between block_id and block_id + blocks -1; TABLESPACE_NAME FILE_ID BLOCK_ID BYTES BLOCKS RELATIVE_FNO --------------- ---------- ---------- ---------- --------- ------------ SYSTEM 352 173196 73728 9 352
4. 첫 손상 블록 재포맷
모든 손상된 블록이 재포맷될 때까지 4단계를 반복하세요.
create table scott.s (n number,c varchar2(4000)) nologging tablespace SYSTEM; select owner,table_name,tablespace_name from dba_tables where table_name='S'; SQL> CREATE OR REPLACE TRIGGER corrupt_trigger AFTER INSERT ON scott.s REFERENCING OLD AS p_old NEW AS new_p FOR EACH ROW DECLARE corrupt EXCEPTION; BEGIN IF (dbms_rowid.rowid_block_number(:new_p.rowid)=&blocknumber) and (dbms_rowid.rowid_relative_fno(:new_p.rowid)=&filenumber) THEN RAISE corrupt; END IF; EXCEPTION WHEN corrupt THEN RAISE_APPLICATION_ERROR(-20000, 'Corrupt block has been formatted'); END; / Enter value for blocknumber: 173191 old 8: IF (dbms_rowid.rowid_block_number(:new_p.rowid)=&blocknumber) new 8: IF (dbms_rowid.rowid_block_number(:new_p.rowid)=173191) Enter value for filenumber: 352 old 9: and (dbms_rowid.rowid_relative_fno(:new_p.rowid)=&filenumber) THEN new 9: and (dbms_rowid.rowid_relative_fno(:new_p.rowid)=352) THEN Trigger created. Select BYTES/1024/1024 from dba_free_space where file_id=352 and 173191 between block_id and block_id + blocks -1; 72K SQL> BEGIN FOR i IN 1..100000 LOOP EXECUTE IMMEDIATE 'alter table scott.s allocate extent (DATAFILE '||'''/mnt/apps_st/samusxxxxxxxx_data2/system09.dbf''' ||'SIZE 72K)'; END LOOP; END; / SQL> BEGIN FOR i IN 1..1000000 LOOP INSERT /*+ APPEND */ INTO scott.s select i, lpad('REFORMAT',3092, 'R') from dual; commit ; END LOOP; END; / SQL> Select * from v$database_block_corruption; no rows selected DROP TABLE scott.s; Alter system switch logfile; Alter system checkpoint; DROP trigger corrupt_trigger;
5. 손상된 블록이 수정되었는지 확인
SQL> select * from V$DATABASE_BLOCK_CORRUPTION; no rows selected [Wed Nov 16 08:12:37 orbdev@samusxxxxxx:~ ] $ dbv file='/mnt/apps_st/samusxxxxxx_data2/system09.dbf' userid=sys/**** DBVERIFY: Release 11.2.0.4.0 - Production on Wed Nov 16 08:12:41 2016 Copyright (c) 1982, 2011, Oracle and/or its affiliates. All rights reserved. DBVERIFY - Verification starting : FILE = /mnt/apps_st/samusxxxxxx_data2/system09.dbf DBVERIFY - Verification complete Total Pages Examined : 655359 Total Pages Processed (Data) : 260868 Total Pages Failing (Data) : 0 Total Pages Processed (Index): 340482 Total Pages Failing (Index): 0 Total Pages Processed (Other): 278 Total Pages Processed (Seg): 15 Total Pages Failing (Seg): 0 Total Pages Empty : 53716 Total Pages Marked Corrupt : 0 Total Pages Influx : 0 Total Pages Encrypted : 0 Highest block SCN : 136830000 (1422.136830000) [Wed Nov 16 08:14:50 orbldev2@samusxxxxxx:~ ] $
결론
데이터 손상을 감지하고 방지하기 위해 다음 Maximum Availability Architecture (MAA) 모범 사례를 수행하세요:
- Oracle Data Guard 사용.
- Oracle 데이터베이스 블록 손상 감지 파라미터 설정.
- Recovery Manager (RMAN)로 백업 및 복구 전략 구현.
이 고가용성 솔루션은 Oracle 데이터베이스와 통합되어 기본 데이터 구조를 활용합니다. 따라서 이 도구들은 지능형 데이터 보호 및 재해 복구의 새로운 클래스를 제공합니다.
피드백 탭을 사용하여 의견을 남기거나 질문하세요.
데이터베이스 서비스 및 Rackspace 애플리케이션 서비스에 대해 자세히 알아보세요.