【备份恢复】 闪回数据库(二) 基于SCN闪回数据库

1.创建测试环境并获取当前SCN
SYS@PROD1>conn scott/tiger;
Connected.
SCOTT@PROD1>create table fbdb_scn as select 1 as id,dbms_flashback.get_system_change_number as scn,sysdate as dd from dual;

Table created.

SCOTT@PROD1>select * from fbdb_scn;

       ID        SCN DD
---------- ---------- -------------------
        1    1228382 2016-12-26 15:36:32

得到此时的SCN,本次测试将数据库倒带到此处,也就是最终的结果,fbdb_scn表中只有一条记录
SCOTT@PROD1>select dbms_flashback.get_system_change_number as scn from dual;

      SCN
----------
  1228438

(或者在sys用户select current_scn from v$database;)
SCOTT@PROD1>insert into fbdb_scn select 2 as id,dbms_flashback.get_system_change_number as scn,sysdate as dd from dual;

1 row created.

SCOTT@PROD1>commit;

Commit complete.

SCOTT@PROD1>select * from fbdb_scn;

       ID        SCN DD
---------- ---------- -------------------
        1    1228382 2016-12-26 15:36:32
        2    1228467 2016-12-26 15:38:56


2.删除scott用户
SYS@PROD1>drop user scott cascade;

User dropped.

3.数据库启动到mount模式,为闪回数据库做准备
SYS@PROD1>shutdown immediate;
Database closed.
Database dismounted.
ORACLE instance shut down.
SYS@PROD1>startup mount;
ORACLE instance started.

Total System Global Area  835104768 bytes
Fixed Size                  2257840 bytes
Variable Size             520096848 bytes
Database Buffers          310378496 bytes
Redo Buffers                2371584 bytes
Database mounted.

正常关库,一致性状态保存。启动mount,利用控制文件找到闪回日志,并应用闪回日志。

4.执行基于 SCN 闪回数据库操作
SYS@PROD1>flashback database to scn 1228438;

Flashback complete.

5.以 RESETLOGS 选项打开数据库

先以read only方式打开数据库,看是否满足预期的结果。
SYS@PROD1>alter database open read only;

Database altered.

SYS@PROD1>select username from dba_users where username='SCOTT';

USERNAME
------------------------------
SCOTT

SYS@PROD1>select * from scott.fbdb_scn;

       ID        SCN DD
---------- ---------- -------------------
        1    1228382 2016-12-26 15:36:32

SYS@PROD1>shutdown immediate;
Database closed.
Database dismounted.
ORACLE instance shut down.

SYS@PROD1>startup;
ORACLE instance started.

Total System Global Area  835104768 bytes
Fixed Size                  2257840 bytes
Variable Size             520096848 bytes
Database Buffers          310378496 bytes
Redo Buffers                2371584 bytes
Database mounted.
ORA-01589: must use RESETLOGS or NORESETLOGS option for database open

SYS@PROD1>alter database open resetlogs;

Database altered.

SYS@PROD1>select * from scott.fbdb_scn;

       ID        SCN DD
---------- ---------- -------------------
        1    1228382 2016-12-26 15:36:32













       
       
       
       
       
       












































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

转载于:http://blog.itpub.net/31400681/viewspace-2131404/

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值