若想顺利的使用闪回数据库功能,需要先将数据库置于闪回数据库状态。此文记录开启闪回数据库功能的步骤,注意调整过程需要重启数据库并确保数据库处于归档模式。
===========================================================
1.确认数据库是否开启Flashback Database功能
把系统启动到mount状态
startup mount
1. 开启DB闪回之前需确保启用了归档模式
SQL> archive log list
Database log mode Archive Mode
Automatic archival Enabled
……
2. 查看闪回日志是否已启用
SQL> select LOG_MODE,FLASHBACK_ON from v$database;
LOG_MODE FLASHBACK_ON
---------- ---------------
ARCHIVELOG NO
==============================================================
3. 启用闪回日志,即闪回数据库功能
SQL> alter database flashback on;
alter database flashback on
*
ERROR at line 1:
ORA-38706: Cannot turn on FLASHBACK DATABASE logging.
ORA-38709: Recovery Area is not enabled.
报错,无法开启闪回功能。到这里本文的主角--"oerr"命令君隆重登场。
=====================================
修改db_recovery_file_dest、db_recovery_file_dest_size及db_flashback_retention_target三个参数内容
1)db_recovery_file_dest、db_recovery_file_dest_size两个参数用于指定闪回日志存放位置及最大大小。可以根据具体环境做相应调整。
2) 确认db_flashback_retention_target参数设置的内容。
=====================================
4. 根据上文中提示的错误号使用oerr命令排错
$ oerr ORA 38709
38709, 00000, "Recovery Area is not enabled."
// *Cause: An ALTER DATABASE FLASHBACK ON command failed because the
// Recovery Area was not enabled.
// *Action: Set DB_RECOVERY_FILE_DEST to a location and retry
5. 从上述的提示中找到错误原因:DB_RECOVERY_FILE_DEST 没有预设
SQL> show parameter DB_RECOVERY_FILE_DEST
NAME TYPE VALUE
------------------------------------ ----------- ------------------------------
db_recovery_file_dest string
db_recovery_file_dest_size big integer 0
6. 设置DB_RECOVERY_FILE_DEST
su - oradev
$mkdir /u01/DEV/db/flash_recovery_area
SQL> alter system set db_recovery_file_dest='/u01/DEV/db/flash_recovery_area';
alter system set db_recovery_file_dest='/u01/DEV/db/flash_recovery_area'
alter system set db_recovery_file_dest='+DATAC1'
*
ERROR at line 1:
ORA-02097: parameter cannot be modified because specified value is invalid
ORA-19802: cannot use DB_RECOVERY_FILE_DEST without DB_RECOVERY_FILE_DEST_SIZE
7. 使用oerr命令排错
$ oerr ORA 19802
19802, 00000, "cannot use DB_RECOVERY_FILE_DEST without DB_RECOVERY_FILE_DEST_SIZE"
// *Cause: There are two possible cause for this error:
// 1) The DB_RECOVERY_FILE_DEST parameter was in use when no
// DB_RECOVERY_FILE_DEST_SIZE parameter was encountered while
// fetching initialization parameter.
// 2) An attempt was made to set DB_RECOVERY_FILE_DEST with the
// ALTER SYSTEM command when no DB_RECOVERY_FILE_DEST_SIZE
// was in use.
// *Action: Correct the dependency parameter definitions and retry the command.
8. 从上述错误原因与解决方案提示中得知需要先设置DB_RECOVERY_FILE_DEST_SIZE
SQL> alter system set DB_RECOVERY_FILE_DEST_SIZE=100G;
(------alter system set DB_RECOVERY_FILE_DEST_SIZE=500G scope=both; -----)
System altered.
SQL> show parameter db_recovery
NAME TYPE VALUE
------------------------------------ ----------- ------------------------------
db_recovery_file_dest string
db_recovery_file_dest_size big integer 20G
9. 设置DB_RECOVERY_FILE_DEST
SQL> alter system set db_recovery_file_dest='/u01/DEV/db/flash_recovery_area';
(---alter system set db_recovery_file_dest='/u01/DEV/db/flash_recovery_area' scope=both;---)
System altered.
=======================================================================================================
10 确认db_flashback_retention_target参数设置的内容。
11. 闪存日志的保存期限由参数db_flashback_ retention_target控制(单位为分钟)默认是1440分钟,一天的时间。,凡是超出保存期限的闪回日志将会在快速恢复区空间吃紧时被自动删除。
SYS@ora11g> show parameter db_flashback_retention_target
NAME TYPE VALUE
------------------------------------ ----------- ---------
db_flashback_retention_target integer 1440
11. 启用闪回日志,即闪回数据库功能
SQL> alter database flashback on;
Database altered.
此时可以在'db_recovery_file_dest'设定的目录中看到扩展名为.flb的文件,它们就是闪回日志。
$ ls
o1_mf_98mpkdl6_.flb o1_mf_98okkcs9_.flb
12.将数据库切换到open状态
alter database open;