Sunday, May 24, 2009

การกู้ข้อมูลกรณี Control File เสีย

Updated: 5/4/2009

การกู้ข้อมูลกรณีที่เกิดเหตุต่อไปนี้:
ระบบฐานข้อมูลเป็นแบบ Noarchivelog, Control files เสียหายทั้งหมด ไม่ว่าจะมีการแก้ไขโครงสร้างทางกายภาพของระบบฐานข้อมูล (เช่นเพิ่มสมาชิกของ redo log)หลังจากการแบ็คอัพครั้งสุดท้าย (ไม่ว่าจะเป็นแบบ Whole หรือ Incremental)หรือไม่ คุณจะต้องมีแบ็คอัพเก็บไว้ โดยจะต้องมีการแบ็คอัพ Control file ไว้ด้วยทุกครั้ง

วิธีการแก้ไขโดยสังเขป
1) Open database in nomount mode เพื่อให้ Database ปล่อย Control File เราจึงจะกู้ Control ที่แบ็คอัพไว้มาทับได้
2) Recover control file คือการกู้ Control File ที่ได้แบ็คอัพไว้ล่าสุด
3) Mount the database เมื่อกู้ Control File ได้แล้วเราจะให้ Database Mount กับ Control File อีกครั้ง
4) Recover the database คือขั้นตอนการกู้คืนฐานข้อมูลกลับมาตามโครงสร้างของฐานข้อมูลที่ปรากฎใน Control File ที่กู้มา
5) Open the database with resetlogs เราต้อง Open Database โดยให้ Reset Log เนื่องจากเราได้ Recover Database (โดยใช้ Redo Log) แล้ว เราไม่มีความจำเป็นจะต้องใช้ Redo Log อีกต่อไป (และไม่ควรจะใช้ด้วย) เราจึง Reset Log ทั้งหมด

ถ้าคุณมีการเปลี่ยนแปลงโครงสร้างทางกายภาพของระบบฐานข้อมูลหลังจากการ Backup ครั้งล่าสุด คุณอาจจะสูญเสียการเปลี่ยนแปลงเหล่านั้น

1) Open database in nomount mode
C:\Documents and Settings\FB00012Chalermpon>rman
Recovery Manager: Release 10.2.0.1.0 - Production on Fri May 23 15:51:41 2008
Copyright (c) 1982, 2005, Oracle. All rights reserved.

RMAN> connect target
connected to target database: orcl2 (not mounted)

2) Recover control file
RMAN> restore controlfile from autobackup;
Starting restore at 23-MAY-08
using target database control file instead of recovery catalog
allocated channel: ORA_DISK_1
channel ORA_DISK_1: sid=157 devtype=DISK
recovery area destination: D:\oracle\product\10.2.0/flash_recovery_area
database name (or database unique name) used for search: ORCL2
channel ORA_DISK_1: autobackup found in the recovery area
channel ORA_DISK_1: autobackup found: D:\ORACLE\PRODUCT\10.2.0\FLASH_RECOVERY_AR
EA\ORCL2\AUTOBACKUP\2008_05_23\O1_MF_S_655486779_43F0S6O1_.BKP
channel ORA_DISK_1: control file restore from autobackup complete
output filename=D:\ORACLE\PRODUCT\10.2.0\ORADATA\ORCL2\CONTROL01.CTL
output filename=D:\ORACLE\PRODUCT\10.2.0\ORADATA\ORCL2\CONTROL02.CTL
output filename=D:\ORACLE\PRODUCT\10.2.0\ORADATA\ORCL2\CONTROL03.CTL
Finished restore at 23-MAY-08

3) Mount the database
RMAN> alter database mount;
database mounted
released channel: ORA_DISK_1

4) Recover the database
RMAN> recover database;
Starting recover at 23-MAY-08
Starting implicit crosscheck backup at 23-MAY-08
allocated channel: ORA_DISK_1
channel ORA_DISK_1: sid=156 devtype=DISK
Finished implicit crosscheck backup at 23-MAY-08
Starting implicit crosscheck copy at 23-MAY-08
using channel ORA_DISK_1
Crosschecked 4 objects
Finished implicit crosscheck copy at 23-MAY-08
searching for all files in the recovery area
cataloging files...
cataloging done
List of Cataloged Files

=======================
File Name: D:\ORACLE\PRODUCT\10.2.0\FLASH_RECOVERY_AREA\ORCL2\AUTOBACKUP\2008_05
_23\O1_MF_S_655486779_43F0S6O1_.BKP

using channel ORA_DISK_1
starting media recovery
archive log thread 1 sequence 7 is already on disk as file D:\ORACLE\PRODUCT\10.
2.0\ORADATA\ORCL2\REDO02.LOG
archive log filename=D:\ORACLE\PRODUCT\10.2.0\ORADATA\ORCL2\REDO02.LOG thread=1
sequence=7
media recovery complete, elapsed time: 00:00:03

Finished recover at 23-MAY-08

5) Open the database with resetlogs
RMAN> alter database open resetlogs;
database opened

เมื่อ Open database ได้แล้ว shutdown database แบบ immediate
แล้ว Open database อีกครั้งด้วยโหมด Mountและให้ทำการ Full Backup ทันที

บทความที่เกี่ยวเนื่องกัน
1. การกู้ข้อมูลกรณี Redo Log File ที่ไม่ได้ Active อยู่เสีย

No comments:

Post a Comment