首页 > 数据库 > Oracle > 使用恢复建议恢复数据库
----恢复丢失当前使用重做日志文件状况下的数据库:
---查看日志文件的信息:
sys@PROD>col member for a50
sys@PROD>select group#,member from v$logfile;
GROUP# MEMBER
---------- --------------------------------------------------
3 /u01/app/oracle/oradata/PROD/redo03.log
2 /u01/app/oracle/oradata/PROD/redo02.log
1 /u01/app/oracle/oradata/PROD/redo01.log
#共有三个日志文件组,每个组只有一个日志成员。
---查看日志组的状态:
sys@PROD>
sys@PROD>select group#,status from v$log;
GROUP# STATUS
---------- ----------------
1 INACTIVE
2 INACTIVE
3 CURRENT
#当前正在使用的是第三号日志文件组。
---查看当前的数据库模式:
sys@PROD>archive log list;
Database log mode Archive Mode
Automatic archival Enabled
Archive destination USE_DB_RECOVERY_FILE_DEST
Oldest online log sequence 13
Next log sequence to archive 15
Current log sequence 15
#当前数据库处于归档模式,如果不是归档模式,需要调至归档模式。
---给每个日志组添加一个日志成员:
sys@PROD>Alter database add logfile member
2 '/u01/app/oracle/oradata/PROD/redo01b.log' to group 1;
Database altered.
sys@PROD>Alter database add logfile member
2 '/u01/app/oracle/oradata/PROD/redo02b.log' to group 2;
Database altered.
sys@PROD>Alter database add logfile member
2 '/u01/app/oracle/oradata/PROD/redo03b.log' to group 3;
Database altered.
#日志文件成功添加完成,添加的日志文件成员默认的大小与该组原有的成员的大小一致。
当在添加日志组的时候,需要指定日志文件成员的大小。
---再次查看日志文件信息:
sys@PROD>select group#,member from v$logfile;
GROUP# MEMBER
---------- --------------------------------------------------
3 /u01/app/oracle/oradata/PROD/redo03.log
2 /u01/app/oracle/oradata/PROD/redo02.log
1 /u01/app/oracle/oradata/PROD/redo01.log
1 /u01/app/oracle/oradata/PROD/redo01b.log
2 /u01/app/oracle/oradata/PROD/redo02b.log
3 /u01/app/oracle/oradata/PROD/redo03b.log
#日志成员添加成功。
---查看日志组与成员的信息:
sys@PROD>select group#,status,members,bytes/1024/1024 Mbytes
2 from v$log;
GROUP# STATUS MEMBERS MBYTES
---------- ---------------- ---------- ----------
1 INACTIVE 2 50
2 INACTIVE 2 50
3 CURRENT 2 50
#当前使用的是第三组日志文件,每个日志组包括两个日志成功,每个日志文件的大小为50M。
---删除当前使用日志组的一个日志成员:
/u01/app/oracle/oradata/PROD/redo03b.log
sys@PROD>!rm /u01/app/oracle/oradata/PROD/redo03b.log
sys@PROD>!ls /u01/app/oracle/oradata/PROD/redo03b.log
ls: /u01/app/oracle/oradata/PROD/redo03b.log: No such file or directory
#删除完成。
---致性关库并重新打开:
sys@PROD>shutdown immediate;
Database closed.
Database dismounted.
ORACLE instance shut down.
sys@PROD>startup
ORACLE instance started.
Total System Global Area 835104768 bytes
Fixed Size 2257840 bytes
Variable Size 507513936 bytes
Database Buffers 322961408 bytes
Redo Buffers 2371584 bytes
Database mounted.
ORA-03113: end-of-file on communication channel
Process ID: 5748
Session ID: 1 Serial number: 5
----尝试切换日志文件:
[oracle@enmo ~]$ sqlplus / as sysdba
SQL*Plus: Release 11.2.0.4.0 Production on Fri Nov 18 11:06:44 2016
Copyright (c) 1982, 2013, Oracle. All rights reserved.
Connected to an idle instance.
PROD>startup mount;
ORACLE instance started.
Total System Global Area 835104768 bytes
Fixed Size 2257840 bytes
Variable Size 507513936 bytes
Database Buffers 322961408 bytes
Redo Buffers 2371584 bytes
Database mounted.
PROD>alter system switch logfile;
alter system switch logfile
*
ERROR at line 1:
ORA-01109: database not open
---通过rman查看文件错误信息:
[oracle@enmo ~]$ rman target /
Recovery Manager: Release 11.2.0.4.0 - Production on Fri Nov 18 11:09:32 2016
Copyright (c) 1982, 2011, Oracle and/or its affiliates. All rights reserved.
connected to target database: PROD (DBID=338469376, not open)
RMAN>
RMAN> list failure;
using target database control file instead of recovery catalog
List of Database Failures
=========================
Failure ID Priority Status Time Detected Summary
---------- -------- --------- ------------- -------
2025 CRITICAL OPEN 18-NOV-16 Redo log group 3 is unavailable
2022 HIGH OPEN 18-NOV-16 Redo log file /u01/app/oracle/oradata/PROD/redo03.log is corrupt
---通过rman查看恢复丢失文件的建议:
RMAN> advise failure;
List of Database Failures
=========================
Failure ID Priority Status Time Detected Summary
---------- -------- --------- ------------- -------
2025 CRITICAL OPEN 18-NOV-16 Redo log group 3 is unavailable
2022 HIGH OPEN 18-NOV-16 Redo log file /u01/app/oracle/oradata/PROD/redo03.log is corrupt
analyzing automatic repair options; this may take some time
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=20 device type=DISK
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 Open resetlogs
Strategy: The repair includes complete media recovery with no data loss
---利用rman通过修复建议修复丢失的文件:
RMAN> repair failure;
Strategy: The repair includes complete media recovery with no data loss
Repair script: /u01/app/oracle/diag/rdbms/prod/PROD/hm/reco_3535562984.hm
contents of repair script:
# recover database until cancel and open resetlogs
sql 'alter database recover database until cancel';
alter database open resetlogs;
Do you really want to execute the above repair (enter YES or NO)? yes
executing repair script
sql statement: alter database recover database until cancel
database opened
repair failure complete
---修复完成并打开数据库:
PROD>select status from v$instance;
STATUS
------------
OPEN
#数据库已经处于打开状态。
来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/31392094/viewspace-2128969/ ,如需转载,请注明出处,否则将追究法律责任。