oracle数据库备份与恢复教程详解 第二部分
4.3丢失多个数据文件,实现整个数据库的恢复
4.3.1 os备份方案
os备份归档模式下损坏(丢失)多个数据文件,进行整个数据库的恢复
1、连接数据库,创建测试表并插入记录
复制代码 代码示例:
sql*plus: release 8.1.6.0.0 - production on tue may 6 13:46:32 2003
(c) copyright 1999 oracle corporation. all rights reserved.
sql> connect internal/password as sysdba;
connected.
sql> create table test(a int);
table created
sql> insert into test values(1);
1 row inserted
sql> commit;
commit complete
2、备份数据库,备份除临时数据文件后的所数据文件
sql> @hotbak.sql 或在dos下 svrmgrl @hotbak.sql
3、继续在测试表中插入记录
复制代码 代码示例:
sql> insert into test values(2);
1 row inserted
sql> commit;
commit complete
sql> select * from test;
a
---------------------------------------
1
2
sql> alter system switch logfile;
system altered.
sql> alter system switch logfile;
system altered.
4、关闭数据库,模拟丢失数据文件
复制代码 代码示例:
sql> shutdown immediate;
database closed.
database dismounted.
oracle instance shut down
c:>del d:oracleoradatatestsystem01.dbf
c:>del d:oracleoradatatestindx01.dbf
c:>del d:oracleoradatatesttools01.dbf
c:>del d:oracleoradatatestrbs01.dbf
模拟媒体毁坏(这里删除多个数据文件)
5、启动数据库,检查错误
复制代码 代码示例:
sql> startup
oracle instance started.
total system global area 102020364 bytes
fixed size 70924 bytes
variable size 85487616 bytes
database buffers 16384000 bytes
redo buffers 77824 bytes
database mounted.
ora-01157: cannot identify/lock data file 1 - see dbwr trace file
ora-01110: data file 1: 'd:oracleoradatatestsystem01.dbf'
详细信息可以查看报警文件
ora-1157 signalled during: alter database open...
thu may 08 09:39:36 2003
errors in file d:oracleadmintestbdumptestdbw0.trc:
ora-01157: cannot identify/lock data file 1 - see dbwr trace file
ora-01110: data file 1: 'd:oracleoradatatestsystem01.dbf'
ora-27041: unable to open file
osd-04002: unable to open file
o/s-error: (os 2) 系统找不到指定的文件。
thu may 08 09:39:36 2003
errors in file d:oracleadmintestbdumptestdbw0.trc:
ora-01157: cannot identify/lock data file 2 - see dbwr trace file
ora-01110: data file 2: 'd:oracleoradatatestrbs01.dbf'
ora-27041: unable to open file
osd-04002: unable to open file
o/s-error: (os 2) 系统找不到指定的文件。
thu may 08 09:39:36 2003
errors in file d:oracleadmintestbdumptestdbw0.trc:
ora-01157: cannot identify/lock data file 5 - see dbwr trace file
ora-01110: data file 5: 'd:oracleoradatatesttools01.dbf'
ora-27041: unable to open file
osd-04002: unable to open file
o/s-error: (os 2) 系统找不到指定的文件。
thu may 08 09:39:36 2003
errors in file d:oracleadmintestbdumptestdbw0.trc:
ora-01157: cannot identify/lock data file 6 - see dbwr trace file
ora-01110: data file 6: 'd:oracleoradatatestindx01.dbf'
ora-27041: unable to open file
osd-04002: unable to open file
o/s-error: (os 2) 系统找不到指定的文件。
通过查询v$recover_file可以看到
复制代码 代码示例:
sql> select * from v$recover_file;
file# online error change# time
---------- ------- ------------------ ---------- -----------
1 online file not found 0
2 online file not found 0
5 online file not found 0
6 online file not found 0
有四个数据文件需要恢复
6、拷贝备份回到原地点(restore),开始恢复数据库(recover)
restore过程:
c:>copy d:databaksystem01.dbf d:oracleoradatatest
c:>copy d:databaktestindx01.dbf d:oracleoradatatest
c:>copy d:databaktesttools01.dbf d:oracleoradatatest
c:>copy d:databaktestrbs01.dbf.dbf d:oracleoradatatest
recover过程:
sql> recover database;
ora-00279: change 1073849 generated at 05/08/2003 08:58:35 needed for thread 1
ora-00289: suggestion : d:oracleoradatatestarchivetestt001s00311.arc
ora-00280: change 1073849 for thread 1 is in sequence #311
specify log: {<ret>=suggested | filename | auto | cancel}
auto
ora-00279: change 1073856 generated at 05/08/2003 09:03:27 needed for thread 1
ora-00289: suggestion : d:oracleoradatatestarchivetestt001s00312.arc
ora-00280: change 1073856 for thread 1 is in sequence #312
ora-00278: log file 'd:oracleoradatatestarchivetestt001s00311.arc' no
longer needed for this recovery
ora-00279: change 1073858 generated at 05/08/2003 09:11:43 needed for thread 1
ora-00289: suggestion : d:oracleoradatatestarchivetestt001s00313.arc
ora-00280: change 1073858 for thread 1 is in sequence #313
ora-00278: log file 'd:oracleoradatatestarchivetestt001s00312.arc' no
longer needed for this recovery
ora-00279: change 1073870 generated at 05/08/2003 09:11:46 needed for thread 1
ora-00289: suggestion : d:oracleoradatatestarchivetestt001s00314.arc
ora-00280: change 1073870 for thread 1 is in sequence #314
ora-00278: log file 'd:oracleoradatatestarchivetestt001s00313.arc' no
longer needed for this recovery
log applied.
media recovery complete.
7、打开数据库,检查数据库的数据(完全恢复)
复制代码 代码示例:
sql> alter database open;
database altered.
sql> select * from test;
a
---------------------------------------
1
2
说明:
1、只要有备份与归档存在,就可以实现数据库的完全恢复(不丢失数据)
2、适合于丢失大量数据文件,或包含系统数据文件在内的数据库的恢复
3、恢复过程在mount下进行,如果恢复成功,再打开数据库,down机时间可能比较长一些。
4.3.2 rman备份方案
rman备份归档模式下损坏(丢失)多个数据文件,进行整个数据库的恢复
1、连接数据库,创建测试表并插入记录
复制代码 代码示例:
sql*plus: release 8.1.6.0.0 - production on tue may 6 13:46:32 2003
(c) copyright 1999 oracle corporation. all rights reserved.
sql> connect internal/password as sysdba;
connected.
sql> create table test(a int);
table created
sql> insert into test values(1);
1 row inserted
sql> commit;
commit complete
2、备份数据库
dos下 c:> rman cmdfile=bakup.rcv msglog=backup.log;
以下是backup.log内容。
复制代码 代码示例:
recovery manager: release 8.1.6.0.0 - production
rman> # script:bakup.rcv
2> # creater:chenjiping
3> # date:5.8.2003
4> # desc:backup all database datafile in archive with rman
5>
6> #connect database
7> connect rcvcat rman/rman@back;
8> connect target internal/virpure;
9>
10> #start backup database
11> run{
12> allocate channel c1 type disk;
13> backup full tag 'dbfull' format 'd:backupfull%u_%s_%p' database
14> include current controlfile;
15> sql 'alter system archive log current';
16> release channel c1;
17> }
18> #end
19>
rman-06008: connected to recovery catalog database
rman-06005: connected to target database: test (dbid=1788174720)
rman-03022: compiling command: allocate
rman-03023: executing command: allocate
rman-08030: allocated channel: c1
rman-08500: channel c1: sid=15 devtype=disk
rman-03022: compiling command: backup
rman-03023: executing command: backup
rman-08008: channel c1: starting full datafile backupset
rman-08502: set_count=4 set_stamp=494074368 creation_time=15-may-03
rman-08010: channel c1: specifying datafile(s) in backupset
rman-08522: input datafile fno=00002 name=d:oracleoradatatestrbs01.dbf
rman-08522: input datafile fno=00001 name=d:oracleoradatatestsystem01.dbf
rman-08011: including current controlfile in backupset
rman-08522: input datafile fno=00005 name=d:oracleoradatatesttools01.dbf
rman-08522: input datafile fno=00004 name=d:oracleoradatatesttemp01.dbf
rman-08522: input datafile fno=00006 name=d:oracleoradatatestindx01.dbf
rman-08522: input datafile fno=00003 name=d:oracleoradatatestuser01.dbf
rman-08013: channel c1: piece 1 created
rman-08503: piece handle=d:backupfull04en5ug0_4_1 comment=none
rman-08525: backup set complete, elapsed time: 00:01:16
rman-03023: executing command: partial resync
rman-08003: starting partial resync of recovery catalog
rman-08005: partial resync complete
rman-03022: compiling command: sql
rman-06162: sql statement: alter system archive log current
rman-03023: executing command: sql
rman-03022: compiling command: release
rman-03023: executing command: release
rman-08031: released channel: c1
recovery manager complete.
到这里表示备份成功。
3、继续在测试表中插入记录
复制代码 代码示例:
sql> insert into test values(2);
1 row inserted
sql> commit;
commit complete
sql> select * from test;
a
---------------------------------------
1
2
sql> alter system switch logfile;
system altered.
sql> alter system switch logfile;
system altered.
4、关闭数据库,模拟丢失数据文件
复制代码 代码示例:
sql> shutdown immediate;
database closed.
database dismounted.
oracle instance shut down
c:>del d:oracleoradatatestsystem01.dbf
c:>del d:oracleoradatatestindx01.dbf
c:>del d:oracleoradatatesttools01.dbf
c:>del d:oracleoradatatestrbs01.dbf
5、启动数据库,检查错误
sql> startup
oracle instance started.
total system global area 102020364 bytes
fixed size 70924 bytes
variable size 85487616 bytes
database buffers 16384000 bytes
redo buffers 77824 bytes
database mounted.
ora-01157: cannot identify/lock data file 1 - see dbwr trace file
ora-01110: data file 1: 'd:oracleoradatatestsystem01.dbf'
查询v$recover_file
sql> select * from v$recover_file;
file# online error change# time
---------- ------- ------------------ ---------- -----------
1 online file not found 0
2 online file not found 0
5 online file not found 0
6 online file not found 0
可以知道有四个数据文件需要恢复
6、利用rman进行恢复
c:>rman
recovery manager: release 8.1.6.0.0 - production
rman> connect rcvcat rman/rman@back
rman-06008: connected to recovery catalog database
rman> connect target internal/virpure
rman-06005: connected to target database: test (dbid=1788174720)
rman> run{
2> allocate channel c1 type disk;
3> restore database;
4> recover database;
5> sql 'alter database open';
6> release channel c1;
7> }
rman-03022: compiling command: allocate
rman-03023: executing command: allocate
rman-08030: allocated channel: c1
rman-08500: channel c1: sid=17 devtype=disk
rman-03022: compiling command: restore
rman-03025: performing implicit partial resync of recovery catalog
rman-03023: executing command: partial resync
rman-08003: starting partial resync of recovery catalog
rman-08005: partial resync complete
rman-03022: compiling command: irestore
rman-03023: executing command: irestore
rman-08016: channel c1: starting datafile backupset restore
rman-08502: set_count=4 set_stamp=494074368 creation_time=15-may-03
rman-08089: channel c1: specifying datafile(s) to restore from backup set
rman-08523: restoring datafile 00001 to d:oracleoradatatestsystem01.dbf
rman-08523: restoring datafile 00002 to d:oracleoradatatestrbs01.dbf
rman-08523: restoring datafile 00003 to d:oracleoradatatestuser01.dbf
rman-08523: restoring datafile 00004 to d:oracleoradatatesttemp01.dbf
rman-08523: restoring datafile 00005 to d:oracleoradatatesttools01.dbf
rman-08523: restoring datafile 00006 to d:oracleoradatatestindx01.dbf
rman-08023: channel c1: restored backup piece 1
rman-08511: piece handle=d:backupfull04en5ug0_4_1 tag=dbfull params=null
rman-08024: channel c1: restore complete
rman-03023: executing command: partial resync
rman-08003: starting partial resync of recovery catalog
rman-08005: partial resync complete
rman-03022: compiling command: recover
rman-03022: compiling command: recover(1)
rman-03022: compiling command: recover(2)
rman-03022: compiling command: recover(3)
rman-03023: executing command: recover(3)
rman-08054: starting media recovery
rman-03022: compiling command: recover(4)
rman-06050: archivelog thread 1 sequence 327 is already on disk as file d:oracleoradatatestarchivetestt001s00327.arc
rman-06050: archivelog thread 1 sequence 328 is already on disk as file d:oracleoradatatestarchivetestt001s00328.arc
rman-06050: archivelog thread 1 sequence 329 is already on disk as file d:oracleoradatatestarchivetestt001s00329.arc
rman-06050: archivelog thread 1 sequence 330 is already on disk as file d:oracleoradatatestarchivetestt001s00330.arc
rman-03023: executing command: recover(4)
rman-08515: archivelog filename=d:oracleoradatatestarchivetestt001s00327.arc thread=1 sequence=327
rman-08515: archivelog filename=d:oracleoradatatestarchivetestt001s00328.arc thread=1 sequence=328
rman-08055: media recovery complete
rman-03022: compiling command: sql
rman-06162: sql statement: alter database open
rman-03023: executing command: sql
rman-03022: compiling command: release
rman-03023: executing command: release
rman-08031: released channel: c1
rman>
7、检查数据库的数据(完全恢复)
sql> select * from test;
a
---------------------------------------
1
2
说明:
1、只要有备份与归档存在,rman也可以实现数据库的完全恢复(不丢失数据)
2、同os备份数据库恢复,适合于丢失大量数据文件,或包含系统数据文件在内的数据库的恢复
3、目标数据库在mount下进行,如果恢复成功,再打开数据库。
4、rman的备份与恢复命令相对比较简单并可靠,建议有条件的话,都采用rman进行数据库的备份。
4.4 不完全恢复案例
4.4.1 os备份下的基于时间的恢复
不完全恢复可以分为基于时间的恢复,基于改变的恢复与基于撤消的恢复,这里已基于时间的恢复为例子来说明不完全恢复过程。
基于时间的恢复可以不完全恢复到现在时间之前的某一个时间,对于某些误操作,如删除了一个数据表,可以在备用恢复环境上恢复到表的删除时间之前,然后把该表导出到正式环境,避免一个人为的错误。
1、连接数据库,创建测试表并插入记录
复制代码 代码示例:
sql*plus: release 8.1.6.0.0 - production on tue may 6 13:46:32 2003
(c) copyright 1999 oracle corporation. all rights reserved.
sql> connect internal/password as sysdba;
connected.
sql> create table test(a int);
table created
sql> insert into test values(1);
1 row inserted
sql> commit;
commit complete
2、备份数据库,这里最好备份所有的数据文件,包括临时数据文件
sql> @hotbak.sql 或在dos下 svrmgrl @hotbak.sql
或冷备份也可以
3、删除测试表,假定删除前的时间为t1,在删除之前,便于测试,继续插入数据并应用到归档。
复制代码 代码示例:
sql> insert into test values(2);
1 row inserted
sql> commit;
commit complete
sql> select * from test;
a
---------------------------------------
1
2
sql> alter system switch logfile;
statement processed.
sql> alter system switch logfile;
statement processed.
sql> select to_char(sysdate,'yyyy-mm-dd hh24:mi:ss') from dual;
to_char(sysdate,'yy
-------------------
2003-05-21 14:43:01
sql> drop table test;
table dropped.
4、准备恢复到时间点t1,找回删除的表,先关闭数据库
复制代码 代码示例:
sql> shutdown immediate;
database closed.
database dismounted.
oracle instance shut down.
5、拷贝刚才备份的所有数据文件回来
c:>copy d:databak*.dbf d:oracleoradatatest
6、启动到mount下
复制代码 代码示例:
sql> startup mount;
oracle instance started.
total system global area 102020364 bytes
fixed size 70924 bytes
variable size 85487616 bytes
database buffers 16384000 bytes
redo buffers 77824 bytes
database mounted.
7、开始不完全恢复数据库到t1时间
复制代码 代码示例:
sql> recover database until time '2003-05-21:14:43:01';
ora-00279: change 30944 generated at 05/21/2003 14:40:06 needed for thread 1
ora-00289: suggestion : d:oracleoradatatestarchivetestt001s00191.arc
ora-00280: change 30944 for thread 1 is in sequence #191
specify log: {<ret>=suggested | filename | auto | cancel}
auto
log applied.
media recovery complete.
8、打开数据库,检查数据
复制代码 代码示例:
sql> alter database open resetlogs;
database altered.
sql> select * from test;
a
---------------------------------------
1
2
说明:
1、不完全恢复最好备份所有的数据,冷备份亦可,因为恢复过程是从备份点往后恢复的,如果因为其中一个数据文件的时间戳(scn)大于要恢复的时间点,那么恢复都是不可能成功的。
2、不完全恢复有三种方式,过程都一样,仅仅是recover命令有所不一样,这里用基于时间的恢复作为示例。
3、不完全恢复之后,都必须用resetlogs的方式打开数据库,建议马上再做一次全备份,因为resetlogs之后再用以前的备份恢复是很难了。
4、以上是在删除之前获得时间,但是实际应用中,很难知道删除之前的实际时间,但可以采用大致时间即可,或可以采用分析日志文件(logmnr),取得精确的需要恢复的时间。
5、一般都是在测试机后备用机器上采用这种不完全恢复,恢复之后导出/导入被误删的表回生产系统
4.4.2 rman备份下的基于改变的恢复
以上用os备份说明了一个基于时间的恢复,现在用rman说明一个基于改变的恢复
1、连接数据库,创建测试表并插入记录
复制代码 代码示例:
sql*plus: release 8.1.6.0.0 - production on tue may 6 13:46:32 2003
(c) copyright 1999 oracle corporation. all rights reserved.
sql> connect internal/password as sysdba;
connected.
sql> create table test(a int);
table created
sql> insert into test values(1);
1 row inserted
sql> commit;
commit complete
2、备份数据库
复制代码 代码示例:
c:>rman
recovery manager: release 8.1.6.0.0 - production
rman> connect rcvcat rman/rman@back
rman-06008: connected to recovery catalog database
rman> connect target internal/virpure
rman-06005: connected to target database: test (dbid=874705288)
rman> run{
2> allocate channel c1 type disk;
3> backup full tag 'dbfull' format 'd:backupfull%u_%s_%p' database
4> include current controlfile;
5> sql 'alter system archive log current';
6> release channel c1;
7> }
rman-03022: compiling command: allocate
rman-03023: executing command: allocate
rman-08030: allocated channel: c1
rman-08500: channel c1: sid=12 devtype=disk
rman-03022: compiling command: backup
rman-03023: executing command: backup
rman-08008: channel c1: starting full datafile backupset
rman-08502: set_count=1 set_stamp=494607834 creation_time=21-may-03
rman-08010: channel c1: specifying datafile(s) in backupset
rman-08522: input datafile fno=00001 name=d:oracleoradatatestsystem01.dbf
rman-08011: including current controlfile in backupset
rman-08522: input datafile fno=00002 name=d:oracleoradatatestrbs01.dbf
rman-08522: input datafile fno=00003 name=d:oracleoradatatestusers01.dbf
rman-08522: input datafile fno=00004 name=d:oracleoradatatesttemp01.dbf
rman-08522: input datafile fno=00005 name=d:oracleoradatatesttools01.dbf
rman-08522: input datafile fno=00006 name=d:oracleoradatatestindx01.dbf
rman-08013: channel c1: piece 1 created
rman-08503: piece handle=d:backupfull01enm7eq_1_1 comment=none
rman-08525: backup set complete, elapsed time: 00:00:16
rman-03023: executing command: partial resync
rman-08003: starting partial resync of recovery catalog
rman-08005: partial resync complete
rman-03022: compiling command: sql
rman-06162: sql statement: alter system archive log current
rman-03023: executing command: sql
rman-03022: compiling command: release
rman-03023: executing command: release
rman-08031: released channel: c1
rman>
3、删除测试表,在删除之前,便于测试,继续插入数据并应用到归档,并获取删除前的scn号。
复制代码 代码示例:
sql> insert into test values(2);
1 row inserted
sql> commit;
commit complete
sql> select * from test;
a
---------------------------------------
1
2
sql> alter system switch logfile;
statement processed.
sql> alter system switch logfile;
statement processed.
sql> select max(ktuxescnw * power(2, 32) + ktuxescnb) scn from x$ktuxe;
scn
----------
31014
sql> drop table test;
table dropped.
4、准备恢复到scn 31014,先关闭数据库,然后启动到mount下
复制代码 代码示例:
sql> shutdown immediate;
database closed.
database dismounted.
oracle instance shut down.
sql> startup mount;
oracle instance started.
total system global area 53126412 bytes
fixed size 70924 bytes
variable size 26763264 bytes
database buffers 26214400 bytes
redo buffers 77824 bytes
database mounted.
5、开始恢复到改变点scn 31014
复制代码 代码示例:
rman> run{
2> allocate channel c1 type disk;
3> restore database;
4> recover database until scn 31014;
5> sql 'alter database open resetlogs';
6> release channel c1;
7> }
rman-03022: compiling command: allocate
rman-03023: executing command: allocate
rman-08030: allocated channel: c1
rman-08500: channel c1: sid=10 devtype=disk
rman-03022: compiling command: restore
rman-03022: compiling command: irestore
rman-03023: executing command: irestore
rman-08016: channel c1: starting datafile backupset restore
rman-08502: set_count=1 set_stamp=494613682 creation_time=21-may-03
rman-08089: channel c1: specifying datafile(s) to restore from backup set
rman-08523: restoring datafile 00001 to d:oracleoradatatestsystem01.dbf
rman-08523: restoring datafile 00002 to d:oracleoradatatestrbs01.dbf
rman-08523: restoring datafile 00003 to d:oracleoradatatestusers01.dbf
rman-08523: restoring datafile 00004 to d:oracleoradatatesttemp01.dbf
rman-08523: restoring datafile 00005 to d:oracleoradatatesttools01.dbf
rman-08523: restoring datafile 00006 to d:oracleoradatatestindx01.dbf
rman-08023: channel c1: restored backup piece 1
rman-08511: piece handle=d:backupfull01enmd5i_1_1 tag=dbfull params=null
rman-08024: channel c1: restore complete
rman-03023: executing command: partial resync
rman-08003: starting partial resync of recovery catalog
rman-08005: partial resync complete
rman-03022: compiling command: recover
rman-03022: compiling command: recover(1)
rman-03022: compiling command: recover(2)
rman-03022: compiling command: recover(3)
rman-03023: executing command: recover(3)
rman-08054: starting media recovery
rman-03022: compiling command: recover(4)
rman-06050: archivelog thread 1 sequence 191 is already on disk as file d:oracl
eoradatatestarchivetestt001s00191.arc
rman-06050: archivelog thread 1 sequence 192 is already on disk as file d:oracl
eoradatatestarchivetestt001s00192.arc
rman-03023: executing command: recover(4)
rman-08515: archivelog filename=d:oracleoradatatestarchivetestt001s00191.ar
c thread=1 sequence=191
rman-08515: archivelog filename=d:oracleoradatatestarchivetestt001s00192.ar
c thread=1 sequence=192
rman-08055: media recovery complete
rman-03022: compiling command: sql
rman-06162: sql statement: alter database open resetlogs
rman-03023: executing command: sql
rman-03022: compiling command: release
rman-03023: executing command: release
rman-08031: released channel: c1
6、检查数据
database altered.
sql> select * from test;
a
---------------------------------------
1
2
可以看到,表依然存在
说明:
1、rman也可以实现不完全恢复,方法比os备份恢复的方法更简单可靠
2、rman可以基于时间,基于改变与基于日志序列的不完全恢复,基于日志序列的恢复可以指定恢复到哪个日志序列,如
复制代码 代码示例:
run {
allocate channel ch1 type disk;
allocate channel ch2 type 'sbt_tape';
set until logseq 1234 thread 1;
restore controlfile to '$oracle_home/dbs/cf1.f' ;
replicate controlfile from '$oracle_home/dbs/cf1.f';
alter database mount;
restore database;
recover database;
sql "alter database open resetlogs";
}
3、与所有的不完全恢复一样,必须在mount下,restore所有备份数据文件,需要resetlogs
4、基于改变的恢复比基于时间的恢复更可靠,但是可能也更复杂,需要知道需要恢复到哪一个改变号(scn),在正常生产中,获取scn的办法其实也有很多,如查询数据库字典表(v$archived_log or v$log_history),或分析归档与联机日志(logmnr)等。
第五章 其它恢复案例
5.1 损坏联机日志的恢复方法
5.1.1 损坏非当前联机日志
大家都清楚,联机日志分为当前联机日志和非当前联机日志,非当前联机日志的损坏是比较简单的,一般通过clear命令就可以解决问题。
1、启动数据库,遇到ora-00312 or ora-00313错误,如
ora-00313: open failed for members of log group 1 of thread 1
ora-00312: online log 1 thread 1: 'd:oracleoradatatestredo01.log'
从这里我们知道日志组1的数据文件损坏了
从报警文件可以看到更详细的信息
2、查看v$log视图
sql> select group#,sequence#,archived,status from v$log;
group# sequence# archived status
---------- ---------- -------- ----------------
1 1 yes inactive
2 2 yes inactive
3 3 no current
可以知道,该组是非当前状态,而且已经归档。
3、用clear命令重建该日志文件
sql>alter database clear logfile group 1;
如果是该日志组还没有归档,则需要用
sql>alter database clear unarchived logfile group 1;
4、打开数据库,重新备份数据库
sql>alter database open;
说明:
1、如果损坏的是非当前的联机日志文件,一般只需要clear就可以重建该日志文件,但是如果该数据库处于归档状态但该日志还没有归档,就需要强行clear。
2、建议clear,特别是强行clear后作一次数据库的全备份。
3、此方法适用于归档与非归档数据库
5.1.2 损坏当前联机日志
归档模式下当前日志的损坏有两种情况,
一、是数据库是正常关闭,日志文件中没有未决的事务需要实例恢复,当前日志组的损坏就可以直接用alter database clear unarchived logfile group n来重建。
二、是日志组中有活动的事务,数据库需要媒体恢复,日志组需要用来同步,有两种补救办法
a. 最好的办法就是通过不完全恢复,可以保证数据库的一致性,但是这种办法要求在归档方式下,并且有可用的备份
b. 通过强制性恢复,但是可能导致数据库不一致。
下面分别用来说明这两种恢复方法