标签:
前面闪回都是基于undo来实现的闪回,由于我们的闪回都是不确定时间的,所以就会导致ORA-01555(快照太旧或者被覆盖)、ORA-01466(表定义被改)、ORA-08180(没有快照)等错误。
SQL> CREATE TABLESPACEhis_data_1 datafile ‘+DATA‘ size 500m;
Tablespacecreated.
SQL> create flashback archivedefault fba1 tablespace his_data_1 retention 7 day;
Flashbackarchive created.
SQL> create flashback archive fba2 tablespace his_data_1 QUOTA 200mRETENTION 30 day;
Flashbackarchive created.
SQL> grant flashback archive onfba1 to scott;
Grantsucceeded.
SQL> grant flashback archiveon fba2 to scott;
Grantsucceeded.
SQL> create tableempsal_his(empno number,ename varchar2(10),sal number) flashback archive;(默认为fba1)
Tablecreated.
SQL> create table t(id int)flashback archive fba2;
Tablecreated.
17:07:57 SQL> insert intoscott.t select object_id from dba_objects;
75465rows created.
17:09:12 SQL> commit;
Commitcomplete
[oracle@oracle trace]$ tail -falert_oracle007.log
Thread1 advanced to log sequence 63 (LGWR switch)
Current log# 3 seq# 63 mem# 0:/u01/app/oracle/oradata/oracle007/redo03.log
ThuMay 07 17:12:06 2015
ArchivedLog entry 60 added for thread 1 sequence 62 ID 0x958cb7c1 dest 1:
ThuMay 07 16:46:52 2015
Starting background process FBDA
Thu May 07 16:46:52 2015
FBDA started with pid=27, OS id=35751
17:11:59 SQL> create undo tablespaceundotbs2 datafile ‘+DATA‘ size 100m;
Tablespacecreated.
17:14:59 SQL> alter system setundo_tablespace=‘undotbs2‘;
Systemaltered.
17:56:27 SQL> drop tablespace undotbs1including contents and datafiles;
Tablespacedropped.
查看刚创建表没有添加内容时表里的内容
SQL> select id from t as of timestampto_timestamp(‘2015-5-7 17:05:57 ‘,‘YYYY-MM-DD hh24:mi:ss‘);
norows selected
向表内增加一条数据
SQL> insert into t values(1);
1row created.
SQL> commit;
Commitcomplete.
查看在增加数据之前表里行的条数
SQL> select count(id) from t asof timestamp to_timestamp(‘2015-5-7 18:07:04‘,‘YYYY-MM-DD hh24:mi:ss‘);
COUNT(ID)
----------
75465
查看在增加数据之后表里行的条数
SQL> select count(id) from t;
COUNT(ID)
----------
75466
norows selected
SQL> select flashback_archive_name,tablespace_name,quota_in_mb fromdba_flashback_archive_ts;
FLASHBACK_ARCHIVE_NAME TABLESPACE_NAME QUOTA_IN_MB
------------------------------------------------------------ ------------------------------
FBA1 HIS_DATA_1
FBA2 HIS_DATA_1 200
SQL> selectflashback_archive_name,to_char(CREATE_TIME,‘dd-mm_yyyy‘)created,retention_in_days,statusfrom dba_flashback_archive;
FLASHBACK_ARCHIVE_NAME CREATED RETENTION_IN_DAYS STATUS
---------------------------------------- ----------------- -------
FBA1 07-05_2015 7 DEFAULT
FBA2 07-05_2015 30
SQL> select * from dba_flashback_archive_tables;
TABLE_NAME OWNER_NAME FLASHBACK_ARCHIVE_NAME ARCHIVE_TABLE_NAME STATUS
------------------------------------------------------------ ------------------------------ ------------------------------------------------------------------
EMPSAL_HIS SCOTT FBA1 SYS_FBA_HIST_78982(后面的数字对应的是dba_object里object_id,这个表对应的是装历史数据库块的) ENABLED
T SCOTT FBA2 SYS_FBA_HIST_78983 ENABLED
SQL> selecttable_name,tablespace_name from user_tables where table_name like ‘%FBA%‘;
TABLE_NAME TABLESPACE_NAME
------------------------------------------------------------
SYS_FBA_DDL_COLMAP_78983(记录DDL操作) HIS_DATA_1
SYS_FBA_TCRV_78983(每一个事物、改变的信息) HIS_DATA_1
SYS_FBA_HIST_78983(记录表实际改变的数据)
SQL> alterflashback archive fba1 modify tablespace his_data_1 quota 200M;
Flashback archive altered.
SQL> alterflashback archive fba1 modify retention1 day;
Flashback archive altered.
SQL> drop flashback archive fba1;
Flashback archive dropped.
1.1.1.1.18手动清除所有归档
SQL> alterflashback archive fba2 purge all;
Flashback archive altered.
SQL> alterflashback archive fba2 purge before timestamp (systimestamp - interval ‘1‘ day);(清除一天前的,month,year);
Flashback archive altered.
标签:
原文地址:http://blog.csdn.net/bzfys/article/details/45560559