Flashback Database闪回数据库 使用闪回数据库可以将数据库快速的闪回到过去某个时间点。在启用闪回数据时,会将修改过的块的前映像作为闪回数据库日志保存在闪回恢复区中,如出现逻辑坏块或用户错误操作需要恢复到过去的时间点,闪回数据库将还原数据库的前映像,然后使用归档日志和redo前滚到期望恢复的时间点,因为无需还原数据库的数据文件,所有此过程速度比较传统的还原恢复通常快很多。 启动闪回数据库时,会将前映像数据保存在“闪回缓冲区”中,然后由恢复写入器(Recovery Writer,RVWR)后台进程,将闪回缓冲区的前映像数据保存在闪回恢复区的闪回数据库日志中。 配置闪回数据库相关参数: db_recovery_file_dest 决定闪回恢复区路径 db_recovery_file_dest_size 决定闪回恢复区大小 db_flashback_retention_target 保留恢复近多长时间的数据,单位为分钟。 闪回数据库必须在归档模式下 开启归档 1、SQL> alter system set log_archive_dest_1='location=+oradg/b1/recovery/' scope=both; 2、SQL> shutdown immediate 3、SQL> startup mount 4、SQL> alter database archivelog; 5、SQL> alter database open; 6、SQL> archive log list 设置闪回区大小,路径,闪回保留时间
SQL> alter system set db_recovery_file_dest_size=5G; System altered. SQL> alter system set db_recovery_file_dest='+ORADG'; System altered. SQL> alter system set db_flashback_retention_target=2880; System altered. 开启闪回功能 SQL> startup mount exclusive SQL> alter database flashback on; Database altered. SQL> select flashback_on from v$database; FLASHBACK_ON ------------------ YES |
关闭闪回功能
SQL> startup mount exclusive ORACLE instance started. Total System Global Area 839282688 bytes Fixed Size 2217992 bytes Variable Size 557844472 bytes Database Buffers 276824064 bytes Redo Buffers 2396160 bytes Database mounted. SQL> ?alter database flashback off; Database altered. SQL> alter database open ; Database altered. SQL> alter system set db_recovery_file_dest=''; System altered. |
SQL> create table test_flashback as select * from emp; --创建表 Table created. SQL> select dbms_flashback.get_system_change_number from dual; --记录删除数据前scn GET_SYSTEM_CHANGE_NUMBER ------------------------ 1069396 SQL> delete from test_flashback where deptno=20; --删除数据 5 rows deleted. SQL> commit; Commit complete. SQL> startup mount exclusive --启动到mount exclusive状态 ORACLE instance started. Total System Global Area 839282688 bytes Fixed Size 2217992 bytes Variable Size 557844472 bytes Database Buffers 276824064 bytes Redo Buffers 2396160 bytes Database mounted. SQL> flashback database to scn 1069396; --闪回到删除数据之前,还可以用时间戳闪回如: Flashback complete. --flashback database to to_timestamp('2013-10-8 18:02:34','YYYY-MM-DD HH24:MI:SS') SQL> alter database open read only; ?--以read only 方式打开检查数据库是否闪回成功,如不成功考虑其他形式的闪回 Database altered. SQL> select * from scott.test_flashback where deptno=20; EMPNO ENAME JOB MGR HIREDATE SAL COMM DEPTNO ---------- ---------- --------- ---------- --------- ---------- ---------- ---------- 7369 SMITH CLERK 7902 17-DEC-80 800 20 7566 JONES MANAGER 7839 02-APR-81 2975 20 7788 SCOTT ANALYST 7566 19-APR-87 3000 20 7876 ADAMS CLERK 7788 23-MAY-87 1100 20 7902 FORD ANALYST 7566 03-DEC-81 3000 20 SQL> startup ORACLE instance started. Total System Global Area 839282688 bytes Fixed Size 2217992 bytes Variable Size 557844472 bytes Database Buffers 276824064 bytes Redo Buffers 2396160 bytes Database mounted. ORA-01589: must use RESETLOGS or NORESETLOGS option for database open SQL> alter database open resetlogs; Database altered. |
--闪回数据库之后,后做一次全备