flashback六大技术之flashback database

环境:

sys@ORCL> select * from v$version where rownum=1;

BANNER
----------------------------------------------------------------
Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - Prod

sys@ORCL> !uname -a
Linux localhost.localdomain 2.6.18-308.el5xen #1 SMP Fri Jan 27 17:59:00 EST 2012 i686 i686 i386 GNU/Linux


1 操作原理


RVWR每隔δt把数据块的before image flush到flashback log,形成合法的rowid集,我们简称之“基底”,基底是由RVWR动态向前维护,以使rowid集合法有效。在flashback database时,是先向后退一大步到基底,在向前迈一小步。借助flashback log只能将数据库恢复到某个指定时间点的状态,该状态可能并不是一致性的状态,然后需再运用archive log,去填补两个δt时间面之间的缺痕,使数据库恢复到一致性状态。一言以辟之,flashback database其实是把undo拿去再整理。其特性,用周杰伦的歌《回到过去》,“就回到过去,试着让故事继续.....”。

2 必备条件


① 归档模式
② 指定flash recovery area


flash recovery area设置的越大,flashback database的恢复能力就越强。由下面两个初始化参数控制:
1)db_recovery_file_dest:存储路径
2)db_recovery_file_dest_size:最大可用空间

sys@ORCL> show parameter db_recover 

NAME                                 TYPE        VALUE
------------------------------------ ----------- ------------------------------
db_recovery_file_dest                string      /u01/app/oracle/flash_recovery
                                                 _area
db_recovery_file_dest_size           big integer 2G


③ 启动flashback database
启用该模式必须有两个先决条件:
1)归档模式
2)mount阶段
语法:
alter database flashback on/off;
验证是否开启:
select flashback_on from v$database


④ 启用force logging
force logging强制所有操作均产生redo entries
语法:
alter database force logging;
验证是否开启:
select force_logging from v$database

⑤ v$flashback_database_log

00:19:33 hr@ORCL (^ω^) desc v$flashback_database_log
 名称                                      是否为空? 类型
 ----------------------------------------- -------- ----------------------------
 OLDEST_FLASHBACK_SCN                               NUMBER
 OLDEST_FLASHBACK_TIME                              DATE
 RETENTION_TARGET                                   NUMBER
 FLASHBACK_SIZE                                     NUMBER
 ESTIMATED_FLASHBACK_SIZE                           NUMBER

00:19:55 hr@ORCL (^ω^) select OLDEST_FLASHBACK_SCN from v$flashback_database_log;

未选定行

00:20:45 hr@ORCL (^ω^) select flashback_on from v$database;

FLASHBACK_ON
------------------------------------
NO


3 制约因素


㈠ 控制文件重建
㈡ 数据文件shrunk
㈢ 表空间删除
㈣ 介质损坏
以上改变,其实质,会导致rowid在基底非法无效,便成了制约因素

4 额外补充


① db_flashback_retention_target
控制flashback log数据的保留时间,或者说,你希望flashback database能够恢复的最早时间点。缺省是一天。

sys@ORCL> show parameter db_flashback

NAME                                 TYPE        VALUE
------------------------------------ ----------- ------------------------------
db_flashback_retention_target        integer     1440


② 执行flashback database后,有两种选择:
a)alter database open resetlogs。一旦resetlogs,将不能再flashback至resetlogs之前的时间点,指定的scn之后产生的数据将全部丢失
b)先alter database open read only;
然后expdp将误操作的表的数据导出
再执行recover database
最后impdp导入

③ 开启flashback on需要消费10%的资源,DBA需均衡利弊。

④ 介词to和until的区别:

例子:

to 20 :包括了20

until 20 :没有包括20,也就是19末。

5 测试实验
㈠ 检查必备条件

sys@ORCL> show parameter db_recover

NAME                                 TYPE        VALUE
------------------------------------ ----------- ------------------------------
db_recovery_file_dest                string      /u01/app/oracle/flash_recovery
                                                 _area
db_recovery_file_dest_size           big integer 2G
sys@ORCL> archive log list
Database log mode              Archive Mode
Automatic archival             Enabled
Archive destination            USE_DB_RECOVERY_FILE_DEST
Oldest online log sequence     13
Next log sequence to archive   15
Current log sequence           15
sys@ORCL> select force_logging,flashback_on from v$database;

FOR FLASHBACK_ON
--- ------------------
YES YES


㈡ 测试

hr@ORCL> select dbms_flashback.get_system_change_number from dual;

GET_SYSTEM_CHANGE_NUMBER
------------------------
                  731867

hr@ORCL> truncate table t2;

Table truncated.

hr@ORCL> conn / as sysdba
Connected.
sys@ORCL> shutdown immediate
Database closed.
Database dismounted.
ORACLE instance shut down.
sys@ORCL> startup mount
ORACLE instance started.

Total System Global Area  419430400 bytes
Fixed Size                  1219760 bytes
Variable Size              83886928 bytes
Database Buffers          331350016 bytes
Redo Buffers                2973696 bytes
Database mounted.
sys@ORCL> flashback database to scn 731867;

Flashback complete.

sys@ORCL> alter database open resetlogs;

Database altered.

sys@ORCL> select count(*) from hr.t2;

  COUNT(*)
----------
        19


你可能感兴趣的:(flashback)