日期:2014-05-16  浏览次数:20576 次

使用闪回功能恢复被TRUNCATE表的内容
转自:http://space.itpub.net/519536/viewspace-629763

我们实际感受一下使用Flashback Database功能找回被TRUNCATE表的快感。

1.Oracle数据库版本信息
sys@secooler> select * from v$version;

BANNER
---------------------------
Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - 64bit Production
PL/SQL Release 11.2.0.1.0 - Production
CORE    11.2.0.1.0      Production
TNS for Linux: Version 11.2.0.1.0 - Production
NLSRTL Version 11.2.0.1.0 - Production

2.验证是否启用了flashback database
sys@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-590636
1)关闭数据库,启动到mount状态
sys@secooler> shutdown immediate;
Database closed.
Database dismounted.
ORACLE instance shut down.

NotConnected@> startup mount;
ORACLE instance started.

Total System Global Area  726540288 bytes
Fixed Size                  2216904 bytes
Variable Size             541068344 bytes
Database Buffers          176160768 bytes
Redo Buffers                7094272 bytes
Database 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_dest

NAME                                     TYPE                 VALUE
---------------------------------------- -------------------- ------------------------
db_recovery_file_dest                    string               /oracle/ora11gR2/flash_recovery_area
db_recovery_file_dest_size               big integer          3882M

3)重启数据库到mount状态
NotConnected@> shutdown immediate;
ORA-01109: database not open


Database dismounted.
ORACLE instance shut down.
NotConnected@> startup mount;
ORACLE instance started.

Total System Global Area  726540288 bytes
Fixed Size                  2216904 bytes
Variable Size             541068344 bytes
Database Buffers          176160768 bytes
Redo Buffers                7094272 bytes
Database mounted.

4)开启闪回功能
(1)第一次尝试
NotConnected@> alter database flashback on;
alter database flashback on
*
ERROR a