一、打开闪回数据库
1、确保数据库处于归档模式,如果为非归档模式,将数据库转换成归档模式
SQL> select name,log_mode from v$database;
NAME LOG_MODE
--------- ------------
ORCL NOARCHIVELOG
SQL> select flashback_on from v$database;
FLASHBACK_ON
-------
NO
设置为归档模
Connected to Oracle Database 10g Enterprise Edition Release 10.2.0.4.0
Connected as SYS
档日志的路径
alter system set log_archive_dest_1=‘location=D:\oracle\product\10.2.0\flash_recovery_area\ORCL\ONLINELOG‘;
alter system set log_archive_dest_2=‘location=D:\oracle\product\10.2.0\flash_recovery_area\ORCL\LOG2‘;
查看结果
show parameter log_archive_dest;
SQL> show parameter log_archive_dest;
NAME TYPE VALUE
------------------------------------ ----------- ------------------------------
log_archive_dest string
log_archive_dest_1 string location=D:\oracle\product\10.2.0\flash_recovery_area\ORCL\ONLINELOG
log_archive_dest_10 string
log_archive_dest_2 string location=D:\oracle\product\10.2.0\flash_recovery_area\ORCL\LOG2
log_archive_dest_3 string
log_archive_dest_4 string
log_archive_dest_5 string
log_archive_dest_6 string
log_archive_dest_7 string
log_archive_dest_8 string
log_archive_dest_9 string
关闭数据库
shutdown immediate
启动数据mount状态:
set ORACLE_SID=ORCL
SQL> startup mount;
修改数据库为归档模式:
SQL> alter database archivelog;
打开数据库,查询:
SQL> alter database open;
修改日志文件命名格式:
SQL> alter system set log_archive_max_processes = 5;
SQL> alter system set log_archive_format = "archive_%t_%s_%r.log" scope=spfile;
检查是否成功
SQL> archive log list;
数据库日志模式 存档模式
自动存档 启用
存档终点 D:\oracle\product\10.2.0\flash_recovery_area\ORCL\LOG2
最早的联机日志序列 6223
下一个存档日志序列 6225
当前日志序列 6225
切换一下当前日志 归档当前的重做日志文件
SQL> ALTER SYSTEM ARCHIVE LOG CURRENT;
系统已更改。
2、设置闪回恢复区
设置闪回区大小:
SQL> alter system set db_recovery_file_dest_size=10g scope=spfile;
设置闪回区位置:
SQL> alter system set db_recovery_file_dest=‘D:\oracle\product\10.2.0\flash_recovery_area\‘ scope=spfile;
设置闪回目标为2天,以分钟为单位,每天为1440分钟:
SQL> alter system set db_flashback_retention_target=2880 scope=spfile;
3、打开闪回功能
SQL> shutdown immediate;
SQL> startup mount;
SQL> alter database flashback on;
SQL> alter database open;
4、确认数据库闪回特性已经启用
SQL> select flashback_on from v$database;
FLASHBACK_ON
----------
YES
5、验证闪回数据库功能
alter user scott account unlock;
连接SCOTT用户
Connected to Oracle Database 10g Enterprise Edition Release 10.2.0.4.0
Connected as scott
删除表
SQL> drop table emp;
Table dropped
查看当前的SCN
select dbms_flashback.get_system_change_number from dual;
恢复到最老的SCN
SQL> select * from v$flashback_database_log;
OLDEST_FLASHBACK_SCN OLDEST_FLASHBACK_TIME RETENTION_TARGET FLASHBACK_SIZE ESTIMATED_FLASHBACK_SIZE
-------------------- --------------------- ---------------- -------------- ------------------------
159498340 2015/10/8 20:06:07 2880 15941632 0
闪回操作
shutdown immediate;
startup mount;
flashback database to scn 159498340;
alter database open resetlogs;
----
conn scott/tiger;
SQL> select * from tab;
TNAME TABTYPE CLUSTERID
------------------------------ ------- ----------
DEPT TABLE
EMP TABLE
BONUS TABLE
SALGRADE TABLE
EMP表恢复成功
二、关闭闪回数据库特性:
SQL> shutdown immediate;
SQL> startup mount;
SQL> alter database flashback off;
SQL> alter database open;
版权声明:本文为博主原创文章,未经博主允许不得转载。如果有需要转载请联系[email protected]
时间: 2025-01-01 23:29:40