|
- create tablespace tbsfda datafile size 20M autoextend off;
- select * from dba_data_files where tablespace_name='TBSFDA';
- select * from dba_flashback_archive;
- create flashback archive fda1 tablespace tbsfda
- quota 20M retention 2 year;
-
- select * from dba_flashback_archive;
-
复制代码 HR:
- [oracle@station87 ~]$ sqlplus /nolog
- SQL*Plus: Release 11.2.0.1.0 Production on Fri Jun 8 03:50:10 2018
- Copyright (c) 1982, 2009, Oracle. All rights reserved.
- SQL> conn hr/oracle_4U
- Connected.
- SQL> select salary from employees where employee_id=100;
- SALARY
- ----------
- 30000
- SQL> alter table employees flashback archive fda1;
- alter table employees flashback archive fda1
- *
- ERROR at line 1:
- ORA-55620: No privilege to use Flashback Archive
- SQL> alter table employees flashback archive fda1;
- Table altered.
- SQL> update employees set salary=40000 where employee_id=100;
- 1 row updated.
- SQL> commit;
- Commit complete.
- SQL>
复制代码- select * from dba_tab_privs tp
- where tp.grantee='HR';
-
- grant flashback archive on fda1 to hr;
-
- select * from dba_flashback_archive_tables;
-
- select * from dba_objects o where o.object_name='EMPLOYEES' and
- o.owner='HR';
-
- select * from hr.SYS_FBA_HIST_73933;
复制代码
- SQL> create table t05311_a ( a number , b varchar2(20)) ;
- Table created.
- SQL> insert into t05311_a values (1,'A') ;
- 1 row created.
- SQL> commit;
- Commit complete.
- SQL> alter table t05311_a flashback archive;
- Table altered.
- SQL>
复制代码
- create flashback archive default fda2 tablespace tbsfda
- quota 20M retention 30 day;
- select * from dba_flashback_archive;
- select * from dba_flashback_archive_tables;
- grant flashback archive on fda2 to hr;
- select * from hr.SYS_FBA_HIST_78247;
复制代码
确认历史表不可更改:
- select * from dba_flashback_archive_tables;
- select * from hr.SYS_FBA_HIST_73933;
- select salary from hr.employees as of scn 1272896 where employee_id=100;
- update hr.SYS_FBA_HIST_73933 set salary=20000;
复制代码
- SQL> select to_char(sysdate,'YYYY-MM-DD:HH24:MI:SS') from dual;
- TO_CHAR(SYSDATE,'YY
- -------------------
- 2018-06-08:04:06:11
- SQL> alter table t05311_a drop ( b) ;
- Table altered.
- SQL> select * from t05311_a;
- A
- ----------
- 1
- SQL> update t05311_a set a=2;
- 1 row updated.
- SQL> commit;
- Commit complete.
- SQL> select * from t05311_a as of timestamp to_timestamp('2018-06-08:04:06:11','YYYY-MM-DD:HH24:MI:SS') ;
- A B
- ---------- --------------------
- 1 A
- SQL> select versions_xid, versions_startscn , a , b from t05311_a
- 2 versions between scn minvalue and maxvalue;
- VERSIONS_XID VERSIONS_STARTSCN A B
- ---------------- ----------------- ---------- --------------------
- 1 A
- 01000C000D030000 1273619 2
- 1273540 1
- SQL> alter table t05311_a enable row movement;
- Table altered.
- SQL> flashback table t05311_a to timestamp to_timestamp('2018-06-08:04:06:11','YYYY-MM-DD:HH24:MI:SS');
- flashback table t05311_a to timestamp to_timestamp('2018-06-08:04:06:11','YYYY-MM-DD:HH24:MI:SS')
- *
- ERROR at line 1:
- ORA-01466: unable to read data - table definition has changed
- SQL>
复制代码
在一个不可扩展的表空间上,FDA空间限额满了,会报以下错误:
- update hr.t04209_uname set uvalue=1567 where uname='a1566'
- *
- ERROR at line 1:
- ORA-55617: Flashback Archive "FDA1" runs out of space and tracking on
- "T04209_UNAME" is suspended
- update hr.t04209_uname set uvalue=1568 where uname='a1567'
- *
- ERROR at line 1:
- ORA-55617: Flashback Archive "FDA1" runs out of space and tracking on
- "T04209_UNAME" is suspended
- update hr.t04209_uname set uvalue=1569 where uname='a1568'
- *
- ERROR at line 1:
- ORA-55617: Flashback Archive "FDA1" runs out of space and tracking on
- "T04209_UNAME" is suspended
- update hr.t04209_uname set uvalue=1570 where uname='a1569'
- *
- ERROR at line 1:
- ORA-01013: user requested cancel of current operation
- SQL>
复制代码- select * from dba_flashback_archive_ts;
- select bytes/1024/1024 from dba_segments s where s.owner='HR'
- and s.segment_name='T04209_UNAME';
-
- alter flashback archive fda1 set default;
-
- select * from dba_flashback_Archive;
-
- select * from dba_flashback_archive_tables;
-
- select * from hr.SYS_FBA_HIST_78257;
-
- alter tablespace tbsfda add datafile size 100M ;
-
- alter flashback archive fda1 modify tablespace tbsfda quota 120M;
-
- select * from dba_flashback_archive_ts;
-
复制代码
- 8 rows updated.
- 8 rows updated.
- 8 rows updated.
- 8 rows updated.
- 8 rows updated.
- 8 rows updated.
- 8 rows updated.
复制代码
全局方案进化:
- SQL> create table part1 ( a number )
- 2 partition by range (a )
- 3 (partition p1 values less than (100),
- 4 partition p2 values less than (maxvalue)) ;
- Table created.
- SQL>
- SQL>
- SQL> insert into part1 values ( 10 ) ;
- 1 row created.
- SQL> insert into part1 values ( 90 ) ;
- 1 row created.
- SQL> insert into part1 values ( 100 ) ;
- 1 row created.
- SQL> commit;
- Commit complete.
- SQL> select * from part1 ( p1 ) ;
- select * from part1 ( p1 )
- *
- ERROR at line 1:
- ORA-00933: SQL command not properly ended
- SQL> select * from part1 partition ( p1 ) ;
- A
- ----------
- 10
- 90
- SQL> select * from part1 partition ( p2 ) ;
- A
- ----------
- 100
- SQL> alter table part1 flashback archive;
- Table altered.
- SQL>
- SQL>
- SQL> alter table part1 split partition p1 at ( 50 )
- 2 into ( partition p11 , partition p12 ) ;
- alter table part1 split partition p1 at ( 50 )
- *
- ERROR at line 1:
- ORA-55610: Invalid DDL statement on history-tracked table
- SQL>
复制代码- select * from dba_flashback_archive_tables ;
- select * from hr.SYS_FBA_HIST_78265;
- begin
- dbms_flashback_archive.disassociate_fba(
- owner_name => 'HR',
- table_name => 'PART1');
- end;
-
- update hr.SYS_FBA_HIST_7826a5 set a=8;
-
- commit;
-
- select * from hr.SYS_FBA_HIST_78265;
-
- begin
- dbms_flashback_archive.reassociate_fba(
- owner_name => 'HR',
- table_name => 'PART1');
- end;
-
复制代码- SQL>
- SQL> alter table part1 split partition p1 at ( 50 )
- 2 into ( partition p11 , partition p12 ) ;
- Table altered.
- SQL> select * from part1 partition (p11) ;
- A
- ----------
- 20
- SQL> select * from part1 partition (p12) ;
- A
- ----------
- 90
- SQL> select * from part1 partition (p2) ;
- A
- ----------
- 100
- SQL> select * from part1 as of scn 1347953;
- A
- ----------
- 8
- 20
- 90
- 100
- SQL>
复制代码
闪回删除表:
- SQL> conn / as sysdba
- Connected.
- SQL> show parameter recycle
- NAME TYPE VALUE
- ------------------------------------ ----------- ------------------------------
- buffer_pool_recycle string
- db_recycle_cache_size big integer 0
- recyclebin string on
- SQL> conn hr/oracle_4U
- Connected.
- SQL> create table t05311_b ( a number ) ;
- Table created.
- SQL> insert into t05311_b values (1) ;
- 1 row created.
- SQL> commit;
- Commit complete.
- SQL> drop table t05311_b ;
- Table dropped.
- SQL> create table t05311_b ( a date ) ;
- Table created.
- SQL> insert into t05311_b values ( sysdate ) ;
- 1 row created.
- SQL> commit;
- Commit complete.
- SQL> drop table t05311_b ;
- Table dropped.
- SQL> create table t05311_c ( a varchar2(20) ) ;
- Table created.
- SQL> rename t05311_c to t05311_b;
- Table renamed.
- SQL> insert into t05311_b values ( 'A' ) ;
- 1 row created.
- SQL> commit;
- Commit complete.
- SQL> drop table t05311_b;
- Table dropped.
- SQL> flashback table t05311_b to before drop ;
- Flashback complete.
- SQL> select * from t05311_b;
- A
- --------------------
- A
- SQL> flashback table "BIN$bhOnD4s0L7XgUKjAVwAvIA==$0" to before drop rename to t05311_c;
- Flashback complete.
- SQL> select * from t05311_c;
- A
- ----------
- 1
- SQL> insert into t04209_uname select * from t04209_uname;
- 800000 rows created.
- SQL> rollback;
- Rollback complete.
- SQL> flashback table t05311_b to before drop rename to t05311_d;
- flashback table t05311_b to before drop rename to t05311_d
- *
- ERROR at line 1:
- ORA-38305: object not in RECYCLE BIN
- SQL>
复制代码
- select bytes/1024/1024 from dba_data_files
- where tablespace_name='USERS';
-
- select * from dba_recyclebin;
-
- select * from hr."BIN$bhOnD4s0L7XgUKjAVwAvIA==$0";
复制代码
- SQL> create table t05311_d ( a number ) ;
- Table created.
- SQL> insert into t05311_d values (1) ;
- 1 row created.
- SQL> commit;
- Commit complete.
- SQL> drop table t05311_d purge;
- Table dropped.
- SQL> flashback table t05311_d to before drop;
- flashback table t05311_d to before drop
- *
- ERROR at line 1:
- ORA-38305: object not in RECYCLE BIN
- SQL> create table t05311_d ( a number ) ;
- Table created.
- SQL> insert into t05311_d values (1) ;
- 1 row created.
- SQL> commit;
- Commit complete.
- SQL> drop table t05311_d ;
- Table dropped.
- SQL> purge table t05311_d;
- Table purged.
- SQL> create table t05311_d ( a number ) ;
- Table created.
- SQL> insert into t05311_d values (1) ;
- 1 row created.
- SQL> commit;
- Commit complete.
- SQL> drop table t05311_d ;
- Table dropped.
- SQL>
复制代码
- select * from dba_recyclebin;
- purge tablespace users user hr;
- purge dba_recyclebin;
复制代码- select flashback_on from v$database;
- select * from v$flashback_database_log;
- alter database flashback on;
- select * from v$flashback_database_logfile;
复制代码
|
|