| 闪回级别 | 闪回场景 | 闪回技术 | 对象依赖 | 影响数据 |
| 数据库 | 表截断、逻辑错误、其他多表意外事件 | 闪回DATABASE | 闪回日志、undo | 是 |
| DROP | 删除表 | 闪回DROP | 回收站(recyclebin) | 是 |
| 表 | 更新、删除、插入记录 | 闪回TABLE | 还原数据,undo | 是 |
| 查询 | 当前数据和历史数据对比 | 闪回QUERY | 还原数据,undo | 否 |
| 版本查询 | 比较行版本 | 闪回Version Query | 还原数据,undo | 否 |
| 事务查询 | 比较 | 闪回Transaction Query | 还原数据,undo | 否 |
| 归档 | DDL、DML | 闪回Archive | 归档日志 | 是 |
SQL> archive log list; Database log mode Archive Mode Automatic archival Enabled Archive destination /home/U01/app/oracle/oradata/testdb/arch Oldest online log sequence 844 Next log sequence to archive 846 Current log sequence 846 ##如未开启,在mount状态执行alter database archivelog;
SQL> select flashback_on from v$database; FLASHBACK_ON ------------------ NO
mount状态:alter database archivelog;
SQL> alter system set db_recovery_file_dest='/home/U01/app/oracle/fast_recovery_area' scope=both; System altered. SQL> alter system set db_recovery_file_dest_size=60G scope=both; System altered. SQL> alter system set db_flashback_retention_target=4320 scope=both; System altered.
SQL> alter database flashback on; Database altered.
SQL> select flashback_on from v$database; FLASHBACK_ON ------------------ YES
SQL> alter database flashback off; Database altered.
SQL> select * from scott.dept;
DEPTNO DNAME LOC
---------- -------------- -------------
ACCOUNTING NEW YORK
RESEARCH DALLAS
SALES CHICAGO
OPERATIONS BOSTON
SQL> delete from scott.dept where deptno=40;
row deleted.
SQL> commit;
Commit complete.
SQL> select * from scott.dept as of timestamp sysdate-10/1440;
DEPTNO DNAME LOC
---------- -------------- -------------
ACCOUNTING NEW YORK
RESEARCH DALLAS
SALES CHICAGO
OPERATIONS BOSTON
SQL> select * from scott.dept as of timestamp to_timestamp('2017-12-14 16:20:00','yyyy-mm-dd hh24:mi:ss');
DEPTNO DNAME LOC
---------- -------------- -------------
ACCOUNTING NEW YORK
RESEARCH DALLAS
SALES CHICAGO
OPERATIONS BOSTON
SQL> select * from scott.dept as of scn 16801523;
DEPTNO DNAME LOC
---------- -------------- -------------
ACCOUNTING NEW YORK
RESEARCH DALLAS
SALES CHICAGO
OPERATIONS BOSTON
SQL> flashback table scott.dept to timestamp to_timestamp('2017-12-14 16:20:00','yyyy-mm-dd hh24:mi:ss');
flashback table scott.dept to timestamp to_timestamp('2017-12-14 16:20:00','yyyy-mm-dd hh24:mi:ss')
ERROR at line 1:
ORA-08189: cannot flashback the table because row movement is not enabled
SQL> select row_movement from dba_tables where table_name='DEPT' and owner='SCOTT';
ROW_MOVE
--------
DISABLED
SQL> alter table scott.dept enable row movement;
Table altered.
SQL> flashback table scott.dept to timestamp to_timestamp('2017-12-14 16:20:00','yyyy-mm-dd hh24:mi:ss');
Flashback complete.
SQL> select * from scott.dept;
DEPTNO DNAME LOC
---------- -------------- -------------
ACCOUNTING NEW YORK
RESEARCH DALLAS
SALES CHICAGO
OPERATIONS BOSTON
SQL> alter table scott.dept disable row movement;
Table altered.
SQL> select * from t ; ID NAME ---------- --------------------------------------- 2 4 SQL> drop table t; Table dropped. SQL> show recyclebin; ORIGINAL NAME RECYCLEBIN NAME OBJECT TYPE DROP TIME ---------------- ------------------------------ ------------ ------------------- T BIN$YEh2QcvZdJLgUxyAgQpnVQ==$0 TABLE 2017-12-14:15:02:06 SQL> flashback table t to before drop; Flashback complete. SQL> select * from t; ID NAME ---------- ------------------------------------- 2 4
SQL> show recyclebin; ORIGINAL NAME RECYCLEBIN NAME OBJECT TYPE DROP TIME ---------------- ------------------------------ ------------ ------------------- T BIN$YEh2QcvddJLgUxyAgQpnVQ==$0 TABLE 2017-12-14:15:07:54 T BIN$YEh2QcvcdJLgUxyAgQpnVQ==$0 TABLE 2017-12-14:15:07:27 SQL> flashback table "BIN$YEh2QcvcdJLgUxyAgQpnVQ==$0" to before drop ; Flashback complete. SQL> show recyclebin; ORIGINAL NAME RECYCLEBIN NAME OBJECT TYPE DROP TIME ---------------- ------------------------------ ------------ ------------------- T BIN$YEh2QcvddJLgUxyAgQpnVQ==$0 TABLE 2017-12-14:15:07:54 SQL> flashback table t to before drop rename to tt; Flashback complete.
SQL> select * from scott.EMP;
EMPNO ENAME JOB MGR HIREDATE SAL COMM DEPTNO
---------- ---------- --------- ---------- ------------------- ---------- ---------- ----------
SMITH CLERK 7902 1980-12-17 00:00:00 800 20
ALLEN SALESMAN 7698 1981-02-20 00:00:00 1600 300 30
WARD SALESMAN 7698 1981-02-22 00:00:00 1250 500 30
JONES MANAGER 7839 1981-04-02 00:00:00 2975 20
MARTIN SALESMAN 7698 1981-09-28 00:00:00 1250 1400 30
BLAKE MANAGER 7839 1981-05-01 00:00:00 2850 30
CLARK MANAGER 7839 1981-06-09 00:00:00 2450 10
SCOTT ANALYST 7566 1987-04-19 00:00:00 3000 20
KING PRESIDENT 1981-11-17 00:00:00 5000 10
TURNER SALESMAN 7698 1981-09-08 00:00:00 1500 0 30
ADAMS CLERK 7788 1987-05-23 00:00:00 1100 20
JAMES CLERK 7698 1981-12-03 00:00:00 950 30
FORD ANALYST 7566 1981-12-03 00:00:00 3000 20
MILLER CLERK 7782 1982-01-23 00:00:00 1300 10
rows selected.
SQL> truncate table scott.EMP;
Table truncated.
SQL> shutdown immediate;
Database closed.
Database dismounted.
ORACLE instance shut down.
SQL> startup mount;
ORACLE instance started.
Total System Global Area 9.4067E+10 bytes
Fixed Size 2263936 bytes
Variable Size 9395242112 bytes
Database Buffers 8.4557E+10 bytes
Redo Buffers 112766976 bytes
Database mounted.
SQL> flashback database to timestamp to_timestamp('2017-12-14 14:12:46','yyyy-mm-dd HH24:MI:SS');
Flashback complete.
SQL> alter database open resetlogs;
Database altered.
SQL> select * from scott.emp;
EMPNO ENAME JOB MGR HIREDATE SAL COMM DEPTNO
---------- ---------- --------- ---------- ------------------- ---------- ---------- ----------
SMITH CLERK 7902 1980-12-17 00:00:00 800 20
ALLEN SALESMAN 7698 1981-02-20 00:00:00 1600 300 30
WARD SALESMAN 7698 1981-02-22 00:00:00 1250 500 30
JONES MANAGER 7839 1981-04-02 00:00:00 2975 20
MARTIN SALESMAN 7698 1981-09-28 00:00:00 1250 1400 30
BLAKE MANAGER 7839 1981-05-01 00:00:00 2850 30
CLARK MANAGER 7839 1981-06-09 00:00:00 2450 10
SCOTT ANALYST 7566 1987-04-19 00:00:00 3000 20
KING PRESIDENT 1981-11-17 00:00:00 5000 10
TURNER SALESMAN 7698 1981-09-08 00:00:00 1500 0 30
ADAMS CLERK 7788 1987-05-23 00:00:00 1100 20
JAMES CLERK 7698 1981-12-03 00:00:00 950 30
FORD ANALYST 7566 1981-12-03 00:00:00 3000 20
MILLER CLERK 7782 1982-01-23 00:00:00 1300 10
rows selected.
SQL> select * from scott.dept;
DEPTNO DNAME LOC ADDR
---------- -------------- ------------- ------------------------------
ACCOUNTING NEW YORK
RESEARCH DALLAS
SALES CHICAGO
SQL> create restore point before_201712151111 guarantee flashback database;
Restore point created.
SQL> create table scott.t as select * from scott.dept;
Table created.
SQL> truncate table scott.t;
Table truncated.
SQL> shutdown immediate;
Database closed.
Database dismounted.
ORACLE instance shut down.
SQL> startup mount;
ORACLE instance started.
Total System Global Area 9.4067E+10 bytes
Fixed Size 2263936 bytes
Variable Size 9663677568 bytes
Database Buffers 8.4289E+10 bytes
Redo Buffers 112766976 bytes
Database mounted.
SQL> flashback database to restore point before_201712151111;
Flashback complete.
SQL> alter database open resetlogs;
Database altered.
此时主库scott.t已不存在:
SQL> select * from scott.t;
select * from scott.t
*
ERROR at line 1:
ORA-00942: table or view does not exist
此时从库的scott.依旧存在,主备同步终止
解决方案:在主库创建快照时间点,从库自动停止应用日志,等主库闪回后,重新应用日志即可。
如果已经做了上述操作,从库可以选择重建
ALTER DATABASE REGISTER LOGFILE '/xx/xx/archive.dbf';
select scn, STORAGE_SIZE ,to_char(time,'yyyy-mm-dd hh24:mi:ss') time,NAME from v$restore_point;
select database_role,open_mode,db_unique_name,flashback_on from v$database;
SQL> set line 200;
SQL> set pagesize 2000;
SQL> select database_role,open_mode,db_unique_name,flashback_on from v$database;
DATABASE_ROLE OPEN_MODE DB_UNIQUE_NAME FLASHBACK_ON
---------------- -------------------- ------------------------------ ------------------
PHYSICAL STANDBY READ ONLY testdbms NO
SQL> ALTER DATABASE CONVERT TO SNAPSHOT STANDBY;
Database altered.
SQL> select database_role,open_mode,db_unique_name,flashback_on from v$database;
DATABASE_ROLE OPEN_MODE DB_UNIQUE_NAME FLASHBACK_ON
---------------- -------------------- ------------------------------ ------------------
SNAPSHOT STANDBY MOUNTED testdbms RESTORE POINT ONLY
SQL> alter database open;
Database altered.
SQL> select open_mode from v$database;
OPEN_MODE
--------------------
READ WRITE
此时备库操作:
SQL> select * from scott.emp;
EMPNO ENAME JOB MGR HIREDATE SAL COMM DEPTNO
---------- ---------- --------- ---------- ------------------- ---------- ---------- ----------
SMITH CLERK 7902 1980-12-17 00:00:00 800 20
ALLEN SALESMAN 7698 1981-02-20 00:00:00 1600 300 30
WARD SALESMAN 7698 1981-02-22 00:00:00 1250 500 30
JONES MANAGER 7839 1981-04-02 00:00:00 2975 20
MARTIN SALESMAN 7698 1981-09-28 00:00:00 1250 1400 30
BLAKE MANAGER 7839 1981-05-01 00:00:00 2850 30
CLARK MANAGER 7839 1981-06-09 00:00:00 2450 10
SCOTT ANALYST 7566 1987-04-19 00:00:00 3000 20
KING PRESIDENT 1981-11-17 00:00:00 5000 10
TURNER SALESMAN 7698 1981-09-08 00:00:00 1500 0 30
ADAMS CLERK 7788 1987-05-23 00:00:00 1100 20
JAMES CLERK 7698 1981-12-03 00:00:00 950 30
FORD ANALYST 7566 1981-12-03 00:00:00 3000 20
MILLER CLERK 7782 1982-01-23 00:00:00 1300 10
rows selected.
SQL> truncate table scott.emp;
Table truncated.
主库操作:
SQL> create table scott.t as select * from scott.dept;
Table created.
SQL> select * from scott.t;
DEPTNO DNAME LOC ADDR
---------- -------------- ------------- ------------------------------
ACCOUNTING NEW YORK
RESEARCH DALLAS
SALES CHICAGO
备库恢复到物理standby
SQL> shutdown immediate;
Database closed.
Database dismounted.
ORACLE instance shut down.
SQL> startup mount;
ORACLE instance started.
Total System Global Area 9.4067E+10 bytes
Fixed Size 2263936 bytes
Variable Size 9663677568 bytes
Database Buffers 8.4289E+10 bytes
Redo Buffers 112766976 bytes
Database mounted.
SQL> ALTER DATABASE CONVERT TO PHYSICAL STANDBY;
Database altered.
SQL> shutdown immediate;
ORA-01507: database not mounted
ORACLE instance shut down.
SQL> startup ;
ORACLE instance started.
Total System Global Area 9.4067E+10 bytes
Fixed Size 2263936 bytes
Variable Size 9663677568 bytes
Database Buffers 8.4289E+10 bytes
Redo Buffers 112766976 bytes
Database mounted.
Database opened.
##此时备库的数据已经恢复到转变snapshot standby时间点
SQL> select database_role,open_mode,db_unique_name,flashback_on from v$database;
DATABASE_ROLE OPEN_MODE DB_UNIQUE_NAME FLASHBACK_ON
---------------- -------------------- ------------------------------ ------------------
PHYSICAL STANDBY READ ONLY testdbms NO
SQL> select * from scott.emp;
EMPNO ENAME JOB MGR HIREDATE SAL COMM DEPTNO
---------- ---------- --------- ---------- ------------------- ---------- ---------- ----------
SMITH CLERK 7902 1980-12-17 00:00:00 800 20
ALLEN SALESMAN 7698 1981-02-20 00:00:00 1600 300 30
WARD SALESMAN 7698 1981-02-22 00:00:00 1250 500 30
JONES MANAGER 7839 1981-04-02 00:00:00 2975 20
MARTIN SALESMAN 7698 1981-09-28 00:00:00 1250 1400 30
BLAKE MANAGER 7839 1981-05-01 00:00:00 2850 30
CLARK MANAGER 7839 1981-06-09 00:00:00 2450 10
SCOTT ANALYST 7566 1987-04-19 00:00:00 3000 20
KING PRESIDENT 1981-11-17 00:00:00 5000 10
TURNER SALESMAN 7698 1981-09-08 00:00:00 1500 0 30
ADAMS CLERK 7788 1987-05-23 00:00:00 1100 20
JAMES CLERK 7698 1981-12-03 00:00:00 950 30
FORD ANALYST 7566 1981-12-03 00:00:00 3000 20
MILLER CLERK 7782 1982-01-23 00:00:00 1300 10
rows selected.
SQL> alter database recover managed standby database using current logfile disconnect;
Database altered.
SQL> select * from scott.t;
DEPTNO DNAME LOC ADDR
---------- -------------- ------------- ------------------------------
ACCOUNTING NEW YORK
RESEARCH DALLAS
SALES CHICAGO
SQL> select database_role,open_mode,db_unique_name,flashback_on from v$database;
DATABASE_ROLE OPEN_MODE DB_UNIQUE_NAME FLASHBACK_ON
---------------- -------------------- ------------------------------ ------------------
PHYSICAL STANDBY READ ONLY WITH APPLY testdbms NO
SQL> select NAME,OPEN_MODE ,DATABASE_ROLE,CURRENT_SCN,FLASHBACK_ON from v$database; NAME OPEN_MODE DATABASE_ROLE CURRENT_SCN FLASHBACK_ON ------------- -------------------- ---------------- ----------- ------------------ TESTDB READ WRITE PRIMARY 16812246 YES
SQL> select to_char(systimestamp,'yyyy-mm-dd HH24:MI:SS') as sysdt , dbms_flashback.get_system_change_number scn from dual; SYSDT SCN ------------------- ---------- 2017-12-14 14:28:33 16813234
SQL> select * from V$FLASHBACK_DATABASE_LOG; OLDEST_FLASHBACK_SCN OLDEST_FLASHBACK_TI RETENTION_TARGET FLASHBACK_SIZE ESTIMATED_FLASHBACK_SIZE -------------------- ------------------- ---------------- -------------- ------------------------ 16801523 2017-12-14 11:35:05 4320 104857600 244113408
SQL> select * from V$flashback_database_stat; BEGIN_TIME END_TIME FLASHBACK_DATA DB_DATA REDO_DATA ESTIMATED_FLASHBACK_SIZE ------------------- ------------------- -------------- ---------- ---------- ------------------------ 2017-12-14 14:34:53 2017-12-14 14:56:43 1703936 9977856 1487872 0
select scn,to_char(time_dp,'yyyy-mm-dd hh24:mi:ss')from sys.smon_scn_time;
select scn, STORAGE_SIZE ,to_char(time,'yyyy-mm-dd hh24:mi:ss') time,NAME from v$restore_point;
FLASHBACK DATABASE TO TIMESTAMP to_timestamp('2017-12-14 14:28:33','yyyy-mm-dd HH24:MI:SS');;
flashback database to scn 16813234;
flashback table table_name to before drop; flashback table table_name to before drop rename to table_name_new;
flashback table table_name to scn scn_number;
flashback table table_name to timestamp to_timestamp('2017-12-14 14:28:33','yyyy-mm-dd hh24:mi:ss');
select * from table_name as of timestamp to_timestamp('2017-12-14 14:28:33','yyyy-mm-dd hh24:mi:ss');
select * from scott.dept as of scn 16801523;
create restore point before_201712151111 guarantee flashback database; flashback database to restore point before_201712151111;
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有