oracle 闪回 truncate,【Flashback】使用闪回功能恢复被TRUNCATE表的内容

我们实际感受一下使用Flashback Database功能找回被TRUNCATE表的快感。1.Oracle数据库版本信息sys@secooler> select * from v$version;BANNER---------------------------------------------------------------Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - 64bit ProductionPL/SQL Release 11.2.0.1.0 - ProductionCORE    11.2.0.1.0      ProductionTNS for Linux: Version 11.2.0.1.0 - ProductionNLSRTL Version 11.2.0.1.0 - Production2.验证是否启用了flashback databasesys@secooler> select flashback_on,force_logging from v$database;FLASHBACK_ON       FOR------------------ ---NO                 NO这里显示没有开启闪回功能,同时force_logging也没有开启。3.开启闪回功能和force logging开启过程可以详细参考《【Flashback】启用Flashback闪回功能》http://space.itpub.net/?uid-519536-action-viewspace-itemid-5906361)关闭数据库,启动到mount状态sys@secooler> shutdown immediate;Database closed.Database dismounted.ORACLE instance shut down.NotConnected@> startup mount;ORACLE instance started.Total System Global Area  726540288 bytesFixed Size                  2216904 bytesVariable Size             541068344 bytesDatabase Buffers          176160768 bytesRedo Buffers                7094272 bytesDatabase mounted.2)设置db_recovery_file_dest和db_recovery_file_dest_size参数NotConnected@> alter system set db_recovery_file_dest='/oracle/ora11gR2/flash_recovery_area';System altered.NotConnected@> alter system set db_recovery_file_dest_size=4g scope=spfile;System altered.NotConnected@> show parameter db_recovery_file_destNAME                                     TYPE                 VALUE---------------------------------------- -------------------- ------------------------------------------------------------db_recovery_file_dest                    string               /oracle/ora11gR2/flash_recovery_areadb_recovery_file_dest_size               big integer          3882M3)重启数据库到mount状态NotConnected@> shutdown immediate;ORA-01109: database not openDatabase dismounted.ORACLE instance shut down.NotConnected@> startup mount;ORACLE instance started.Total System Global Area  726540288 bytesFixed Size                  2216904 bytesVariable Size             541068344 bytesDatabase Buffers          176160768 bytesRedo Buffers                7094272 bytesDatabase mounted.4)开启闪回功能(1)第一次尝试NotConnected@> alter database flashback on;alter database flashback on*ERROR at line 1:ORA-38706: Cannot turn on FLASHBACK DATABASE logging.ORA-38707: Media recovery is not enabled.之所以会报此错误,是因为这个数据库没有运行在归档模式下。(2)将数据库修改为归档模式NotConnected@> alter database archivelog;Database altered.(3)再次尝试开启闪回功能,成功。NotConnected@> alter database flashback on;Database altered.5)OPEN数据库,NotConnected@> alter database open;Database altered.6)开启force logging功能sys@secooler> alter database force logging;Database altered.7)最后的验证sys@secooler> select flashback_on,force_logging from v$database;FLASHBACK_ON       FOR------------------ ---YES                YES此时,数据库已经启用闪回功能,同时force_logging也被开启。4.在sec用户下创建一个T表并初始化一条数据sys@secooler> conn sec/secConnected.sec@secooler> select * from tab;no rows selectedsec@secooler> create table t (x varchar2(8));Table created.sec@secooler> insert into t values ('secooler');1 row created.sec@secooler> commit;Commit complete.sec@secooler> select * from t;X--------secooler5.查看当前数据库可以闪回到的时间sec@secooler> alter session set nls_date_format='yyyy-mm-dd hh24:mi:ss';Session altered.sec@secooler> select oldest_flashback_scn,oldest_flashback_time from v$flashback_database_log;OLDEST_FLASHBACK_SCN OLDEST_FLASHBACK_TI-------------------- -------------------8443212 2010-03-17 19:26:456.模拟表T被误TRUNCATEsec@secooler> select sysdate from dual;SYSDATE-------------------2010-03-17 19:47:14sec@secooler> truncate table t;Table truncated.7.此时数据已被删除sec@secooler> select * from t;no rows selected8.使用Flash Database功能1)关闭数据库sys@secooler> shutdown immediate;Database closed.Database dismounted.ORACLE instance shut down.2)开启数据库到mount exclusive状态sys@secooler> startup mount exclusive;ORACLE instance started.Total System Global Area  726540288 bytesFixed Size                  2216904 bytesVariable Size             541068344 bytesDatabase Buffers          176160768 bytesRedo Buffers                7094272 bytesDatabase mounted.3)恢复到truncate表T之前的时间,注意这里时间格式的写法sys@secooler> Flashback Database to timestamp(to_date('2010-03-17 19:47:14','yyyy-mm-dd hh24:mi:ss'));Flashback complete.4)打开数据库到read only状态sys@secooler> alter database open read only;Database altered.5)到sec用户中确认,数据是否被恢复sys@secooler> conn sec/secConnected.sec@secooler> select * from t;X--------secooler“激动人心”的消息:“我secooler又回来啦!”此时也可以以“resetlogs”的方式开启数据库(alter database open resetlogs;),不推荐这样使用,因为这样打开数据库后,恢复到的时间点之后的数据将会丢失。9.小结我们真实完整的操练了一遍Flash Database功能,它可以完美、便捷和快速的恢复被误TRUNCATE的表。在“特定场合”下可以考虑使用这个优秀的功能。“特定场合”:数据库的数据量不大,确认数据库确实可以恢复到指定的时间点。受这个技术本身的Good luck.secooler10.03.17-- The End --

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值