欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  数据库

联机日志损坏时的恢复(正常关闭数据库)

程序员文章站 2022-05-13 12:10:07
...

联机日志损坏时的恢复(正常关闭数据库),创建一个表T2插入两行数据,第一行数据写如果归档日志,第二行数据在联机日志中。

1.创建一个表T2插入两行数据,第一行数据写如果归档日志,第二行数据在联机日志中
SQL> create table t2(
a1 number(10),
a2 char(10)) tablespace users;
SQL> insert into t2 values (11,'aa');
SQL> commit;
SQL> alter system switch logfile;
SQL> insert into t2 values(22,'bb');
SQL> commit;

2.查询日志文件
SQL> select member from v$logfile;

MEMBER
--------------------------------------------------------------------------------
/database/ykg/ykg1a.log
/database/ykg/ykg2a.log

3.正常关闭数据库
SQL> shutdown immediate
Database closed.
Database dismounted.
Oracle instance shut down.

4.模拟联机日志文件损坏
SQL> host rm -rf /database/ykg/ykg*.log

5.正常启动数据库报错
SQL> startup
ORACLE instance started.

Total System Global Area 293601280 bytes
Fixed Size 2020392 bytes
Variable Size 92277720 bytes
Database Buffers 197132288 bytes
Redo Buffers 2170880 bytes
Database mounted.
ORA-00313: open failed for members of log group 1 of thread 1
ORA-00312: online log 1 thread 1: '/database/ykg/ykg1a.log'

6.查看当前联机日志的SEQUENCE号
SQL> archive log list;
Database log mode Archive Mode
Automatic archival Enabled
Archive destination USE_DB_RECOVERY_FILE_DEST
Oldest online log sequence 191
Next log sequence to archive 192
Current log sequence 192

7.假装执行不完全恢复来恢复日志组
RMAN> run {
2> recover database until sequence 193 thread 1;
3> alter database open resetlogs;}

8.验证日志成员已恢复,数据没有丢失
SQL> select member from v$logfile;
MEMBER
--------------------------------------------------------------------------------
/database/ykg/ykg1a.log
/database/ykg/ykg2a.log

联机日志损坏时的恢复(正常关闭数据库)