ITPub博客

首页 > Linux操作系统 > Linux操作系统 > DATA GUARD主库丢失数据文件的恢复(1)

DATA GUARD主库丢失数据文件的恢复(1)

原创 Linux操作系统 作者:space6212 时间:2019-05-15 13:24:03 0 删除 编辑

在DATAGUARD中,主库丢失文件时,有多种恢复方式可选:
1、从备库拷贝相关文件到主库上恢复
2、拷贝备库备份到主库还原恢复
3、从主库备份还原恢复

本文主要讨论10G DATAGUARD中,主库丢失数据文件时,用拷贝备库对应的数据文件方式恢复主库。


这种方法要分两种情况讨论:
一、备库文件SCN号比主库控制文件新


这种情况下需要重建控制文件来解决。
导致这种情况一般是主库出现故障时,备库正处于恢复状态。

1、模拟主库丢失文件
SQL> shutdown immediate
ORA-01116: error in opening database file 1
ORA-01110: data file 1: '/u01/oracle/oradata/primary/system01.dbf'
ORA-27041: unable to open file
Linux Error: 2: No such file or directory
Additional information: 3
SQL> shutdown abort
ORACLE instance shut down.
SQL> startup mount
ORACLE instance started.

Total System Global Area 167772160 bytes
Fixed Size 1260696 bytes
Variable Size 109052776 bytes
Database Buffers 54525952 bytes
Redo Buffers 2932736 bytes
Database mounted.

2、从备库拷贝相关文件到主库
首先关闭备库
SQL> shutdown immediate
Database closed.
Database dismounted.
ORACLE instance shut down.
拷贝文件
[oracle@standby primary]$ scp system01.dbf 10.2.98.10:`pwd`
oracle@10.2.98.10's password:
system01.dbf 100% 300MB 2.7MB/s 01:51

3、尝试recover丢失的文件

SQL> recover datafile 1;
ORA-00283: recovery session canceled due to errors
ORA-01122: database file 1 failed verification check
ORA-01110: data file 1: '/u01/oracle/oradata/primary/system01.dbf'
ORA-01207: file is more recent than control file - old control file

失败。这时,因为没有备份,只能通过重建主库控制文件的方式解决。

4、在主库生成文件格式的控制文件
SQL> alter database backup controlfile to trace;

Database altered.

5、重建控制文件
注意:必须要选择NORESETLOGS的方式,否则备库可能会需要重建。

SQL> shutdown immediate
ORA-01109: database not open


Database dismounted.
ORACLE instance shut down.

SQL> CREATE CONTROLFILE REUSE DATABASE "PRIMARY" NORESETLOGS FORCE LOGGING ARCHIVELOG
2 MAXLOGFILES 16
3 MAXLOGMEMBERS 3
4 MAXDATAFILES 100
5 MAXINSTANCES 8
6 MAXLOGHISTORY 292
7 LOGFILE
8 GROUP 1 '/u01/oracle/oradata/primary/redo01.log' SIZE 50M,
9 GROUP 2 '/u01/oracle/oradata/primary/redo02.log' SIZE 50M,
10 GROUP 3 '/u01/oracle/oradata/primary/redo03.log' SIZE 50M
11 --STANDBY LOGFILE
12 --GROUP 4 '/u01/oracle/oradata/primary/standbyredo04.log' SIZE 50M,
13 --GROUP 5 '/u01/oracle/oradata/primary/standbyredo5.log' SIZE 50M,
14 --GROUP 6 '/u01/oracle/oradata/primary/standbyredo6.log' SIZE 50M,
15 --GROUP 7 '/u01/oracle/oradata/primary/standbyredo7.log' SIZE 50M
16 DATAFILE
17 '/u01/oracle/oradata/primary/system01.dbf',
18 '/u01/oracle/oradata/primary/undotbs01.dbf',
19 '/u01/oracle/oradata/primary/sysaux01.dbf',
20 '/u01/oracle/oradata/primary/users01.dbf'
21 CHARACTER SET ZHS16GBK
22 ;

Control file created.

6、恢复数据库
SQL> recover database;
ORA-00279: change 163941 generated at 06/27/2007 23:26:11 needed for thread 1
ORA-00289: suggestion : /u01/archivelog/1_41_626106231.arc
ORA-00280: change 163941 for thread 1 is in sequence #41


Specify log: {=suggested | filename | AUTO | CANCEL}
auto
ORA-00279: change 164058 generated at 06/27/2007 23:27:13 needed for thread 1
ORA-00289: suggestion : /u01/archivelog/1_42_626106231.arc
ORA-00280: change 164058 for thread 1 is in sequence #42
ORA-00278: log file '/u01/archivelog/1_41_626106231.arc' no longer needed for
this recovery


......
......

ORA-00279: change 166472 generated at 06/30/2007 00:18:54 needed for thread 1
ORA-00289: suggestion : /u01/archivelog/1_48_626106231.arc
ORA-00280: change 166472 for thread 1 is in sequence #48
ORA-00278: log file '/u01/archivelog/1_47_626106231.arc' no longer needed for
this recovery


Log applied.
Media recovery complete.
SQL> ALTER SYSTEM ARCHIVE LOG ALL;

System altered.

7、打开主库
SQL> alter database open;

Database altered.

8、为主库添加临时文件
SQL> ALTER TABLESPACE TEMP ADD TEMPFILE '/u01/oracle/oradata/primary/temp01.dbf' REUSE;

Tablespace altered.

至此,主库恢复完成。

二、备库文件SCN号比主库控制文件旧
一般情况下,如果主库故障时,备库正处于只读状态,那么,备库的数据文件SCN一般会比主库小。
这种情况比较简单,把丢失的数据文件从备库拷贝到主库后执行recover就可以了。

1、删除主库数据文件,模拟故障
SQL> startup
ORACLE instance started.

Total System Global Area 167772160 bytes
Fixed Size 1260696 bytes
Variable Size 121635688 bytes
Database Buffers 41943040 bytes
Redo Buffers 2932736 bytes
Database mounted.
ORA-01157: cannot identify/lock data file 1 - see DBWR trace file
ORA-01110: data file 1: '/u01/oracle/oradata/primary/system01.dbf'

2、从备库拷贝相关文件到主库
首先关闭备库
SQL> shutdown immediate
Database closed.
Database dismounted.
ORACLE instance shut down.
拷贝文件
[oracle@standby primary]$ scp system01.dbf 10.2.98.10:`pwd`
oracle@10.2.98.10's password:
system01.dbf 100% 300MB 2.7MB/s 01:51

3、返回主库,执行recover
SQL> recover datafile 1;
Media recovery complete.

4、打开主库
SQL> alter database open;

Database altered.

恢复完成。

来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/231499/viewspace-63830/,如需转载,请注明出处,否则将追究法律责任。

请登录后发表评论 登录
全部评论

注册时间:2005-01-25

  • 博文量
    245
  • 访问量
    168790