基于时间闪回数据库(九)

在已启动闪回数据库功能的基础上进行的测试http://space.itpub.net/685769/viewspace-749364

一、在scott用户下创建一张表、并记录系统时间(如果记录了系统时间,那么可以准确的闪回到指定时间点)
SCOTT@ORA11GR2>create  table fbdb_time as select sysdate as dd from dual;
Table created.
SCOTT@ORA11GR2>select sysdate from dual;
SYSDATE
——————-
2012-11-17 21:52:26
SCOTT@ORA11GR2>
二、删除scott用户,并将数据库启动到mount状态下
SCOTT@ORA11GR2>

conn / as sysdba

Connected.
SYS@ORA11GR2>drop user scott cascade;
User dropped.
SYS@ORA11GR2>startup mount force;
ORACLE instance started.
Total System Global Area  849530880 bytes
Fixed Size                  1339824 bytes
Variable Size             641732176 bytes
Database Buffers          201326592 bytes
Redo Buffers                5132288 bytes
Database mounted.
SYS@ORA11GR2>
三、第一次闪回,我们不用刚刚记录的时间,我们闪回到三分钟之前,看看是什么情况
SYS@ORA11GR2>
flashback database to timestamp  sysdate – 3/1440;
Flashback complete.
SYS@ORA11GR2>
四、此时,数据库可以启动到read only状态,查看是否闪回到我想要的时间点(即:scott用户已创建fbdb_time表以后)
SYS@ORA11GR2>

alter database open read only;

Database altered.
SYS@ORA11GR2>
五、经验证,

scott.fbdb_time表不存在,说明,我们闪回闪过了。
SYS@ORA11GR2>

select * from scott.fbdb_time;

select * from scott.fbdb_time
              *
ERROR at line 1:
ORA-00942: table or view does not exist
SYS@ORA11GR2>
六、重新到mount状态下,再次闪回(如果我们不知道具体的时间点的话,我们只能一次一次以read only打开数据库试验,直到我们满意为止)
SYS@ORA11GR2>

startup mount force;

ORACLE instance started.
Total System Global Area  849530880 bytes
Fixed Size                  1339824 bytes
Variable Size             641732176 bytes
Database Buffers          201326592 bytes
Redo Buffers                5132288 bytes
Database mounted.
SYS@ORA11GR2>
七、由于我们记录了当时的时间,所以,我们直接闪回到那个时间点即可
SYS@ORA11GR2>

flashback database to timestamp to_date(’2012-11-17 21:52:26′,’yyyy-mm-dd hh24:mi:ss’);

Flashback complete.
SYS@ORA11GR2>
八、再次以read only打开数据库,验证,正如我们所想的一样,回到了删除scott用户之前的状态
SYS@ORA11GR2>

alter database open read only;

Database altered.
SYS@ORA11GR2>conn scott/tiger
Connected.
SCOTT@ORA11GR2>conn / as sysdba
Connected.
SYS@ORA11GR2>select * from scott.fbdb_time;
DD
——————-
2012-11-17 21:52:09
SYS@ORA11GR2>
九、重启数据库,以

resetlogs方式打开数据库, 闪回数据库完成
SYS@ORA11GR2>

shutdown abort;

ORACLE instance shut down.
SYS@ORA11GR2>
SYS@ORA11GR2>startup mount;
ORACLE instance started.
Total System Global Area  849530880 bytes
Fixed Size                  1339824 bytes
Variable Size             641732176 bytes
Database Buffers          201326592 bytes
Redo Buffers                5132288 bytes
Database mounted.
SYS@ORA11GR2>alter database open resetlogs;
Database altered.
SYS@ORA11GR2>
十、小结
如果使用了闪回数据库,往往都是在不知道具体时间的情况下,为了损失更小,我们只能一次又一次的read only打开数据库来验证结果;
一般情况下,开启闪回数据库的生产库很少,毕竟还是比较耗资源的(特别是DML操作比较频繁的数据库);
还有就是,如果我们使用了闪回功能,那么归档日志都重新开始了,我们之前的 备份就失效了,在使用了闪回数据库后,记得做一次数据库的全备。

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

转载于:http://blog.itpub.net/23009281/viewspace-758024/

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值