Flashback以undo段为基础,受限于undo_retention参数。如果使用flashback特性,需要启动Automatic Undo Management,Automatic Undo Management由以下两个参数决定:
UNDO_MANAGEMENT:值为AUTO表示使用了自动撤销管理表空间,MANUAL则表示手动管理。
UNDO_TABLESPACE:Oracle数据库中可以创建多个UNDO表空间,不过同时只能使用一个,当UNDO_MANAGEMENT初始化参数值为AUTO时,UNDO_TABLESPACE参数用来指定当前使用的UNDO表空间名称。
UNDO表空间的大小,直接影响到Flashback Query的查询能力,因为多版本查询所依赖的UNDO段都存储在UNDO表空间中,
该表空间越大,所能够存储的UNDO数据越多,如果该表空间可用空间非常小,则查询可能触发ORA-1555错误。
Oracle 11g 里又出了一个新特性: Oracle Flashback Data Archive ,通过设计闪回归档区,以和undo区别开来。这样可以为闪回归档提供单独策略,用来闪回到指定时间。
Flashback分为:
1.flashback database
2.flashback drop
3.flashback table
4.flashback query(flashback query,flashback version query,flashback transaction query)
一、设置闪回恢复区
oracle提供一个闪回恢复区的概念,用来存储恢复使用的文件,如flashback log,archive log,backup set等。
通过以下几个参数设置:
db_recovery_file_dest 闪回恢复区位置
db_recovery_file_dest_size恢复区大小
db_flashback_retention_target 数据保存时间,单位为分钟。实际的回退和恢复区空间大小有关。默认值1440分钟大概为10%的数据变动的情况。
SQL> show parameter db_recovery;
NAME TYPE VALUE
------------------------------------ ----------- ------------------------------
db_recovery_file_dest string /u01/app/oracle/flash_recovery_area
db_recovery_file_dest_size big integer 10G
SQL> show parameter db_flashback;
NAME TYPE VALUE
------------------------------------ ----------- ------------------------------
db_flashback_retention_target integer 1440
db_recovery_file_dest 设置为空,可以停用
二取消闪回恢复区
db_recovery_file_dest 设置为空,则停用闪回恢复区,如果已经启用flashback database,则无法使用。
SQL> alter system set db_recovery_file_dest='';
alter system set db_recovery_file_dest=''
ORA-02097: parameter cannot be modified because specified value is invalid
ORA-38775: cannot disable recovery area - flashback database is enabled
SQL> alter system set db_recovery_file_dest='' scope=spfile;
System altered.
SQL> shutdown immediate;
Database closed.
Database dismounted.
ORACLE instance shut down.
SQL> startup
ORACLE instance started.
Total System Global Area 451981312 bytes
Fixed Size 1337100 bytes
Variable Size 352323828 bytes
Database Buffers 92274688 bytes
Redo Buffers 6045696 bytes
Database mounted.
ORA-38760: This database instance failed to turn on flashback database
在11.2.0.1.0版本中,禁用闪回特性,会提示错误
SQL> alter system set db_recovery_file_dest='/u01/app/oracle/flash_recovery_area' scope=spfile;
System altered.
SQL> shutdown immediate;
ORA-01109: database not open
Database dismounted.
ORACLE instance shut down.
SQL> startup
ORACLE instance started.
Total System Global Area 451981312 bytes
Fixed Size 1337100 bytes
Variable Size 352323828 bytes
Database Buffers 92274688 bytes
Redo Buffers 6045696 bytes
Database mounted.
Database opened.
三、查看恢复区文件类型,使用空间大小和文件数量等。
SQL> select * from v$flash_recovery_area_usage;
FILE_TYPE PERCENT_SPACE_USED PERCENT_SPACE_RECLAIMABLE NUMBER_OF_FILES
-------------------- ------------------ ------------------------- ---------------
CONTROL FILE 0 0 0
REDO LOG 0 0 0
ARCHIVED LOG 38.89 0 102
BACKUP PIECE 13.18 0 35
IMAGE COPY 0 0 0
FLASHBACK LOG 33.23 0 797
FOREIGN ARCHIVED LOG 0 0 0
7 rows selecte
四、通过v$archived_log视图查看文件是否为恢复文件。
SQL> select t.NAME,t.IS_RECOVERY_DEST_FILE from v$archived_log t;
NAME IS_RECOVERY_DEST_FILE
-------------------------------------------------------------------------------- ---------------------
/u01/app/oracle/oradata/orcl/redo01.log NO
/u01/app/oracle/oradata/orcl/redo02.log NO
/u01/app/oracle/oradata/orcl/redo03.log NO
/u01/app/oracle/flash_recovery_area/ORCL/archivelog/2013_07_02/o1_mf_1_4_8x5jsy8 YES
设置闪回恢复区以后,则一些参数不能使用。
SQL> show parameter log_archive_dest;
NAME TYPE VALUE
------------------------------------ ----------- ------------------------------
log_archive_dest string
SQL> alter system set log_archive_dest='/u01/app/oracle/';
alter system set log_archive_dest='/u01/app/oracle/'
ORA-02097: parameter cannot be modified because specified value is invalid
ORA-16018: cannot use LOG_ARCHIVE_DEST with LOG_ARCHIVE_DEST_n or DB_RECOVERY_FILE_DEST
多个数据库的恢复区可以在同一个位置,但是DB_NAME或DB_UNIQUE_NAME不能一样。RAC的恢复区位于共享磁盘,可以为所有实例访问。
五、闪回区管理,可以通过视图dba_outstanding_alerts,里面介绍的原因,推荐操作,警告线,严重警告线等。
SQL> select t.object_name,t.object_type,t.reason,t.suggested_action from dba_outstanding_alerts t;
OBJECT_NAME OBJECT_TYPE REASON SUGGESTED_ACTION
------------------------------ ------------------------------ -------------------------------------------------------------------------------- --------------------------------------------------------------------------------
RECOVERY AREA RECOVERY AREA db_recovery_file_dest_size of 10737418240 bytes is 85.30% used and has 157854208 Choices to free up space from recovery area: 1. Consider changing RMAN RETENTION
六、计算闪回占用的空间
SQL> select sum(percent_space_used)*3/100 from v$flash_recovery_area_usage;
SUM(PERCENT_SPACE_USED)*3/100
-----------------------------
2.5635
单位是G
阅读(1972) | 评论(0) | 转发(1) |