手动配置归档,闪回

一、开启归档:
进入数据库
export ORACLE_SID=zwb
sqlplus '/as sysdba'

1、查看数据库是否处于归档模式:
SQL> archive log list
Database log mode              No Archive Mode                              ----非归档
Automatic archival             Disabled
Archive destination            /oracle/app/product/10.2.0/db_1/dbs/arch     ---归档路径
Oldest online log sequence     1
Current log sequence           2

2、设置归档路径
$mkdir -p /data/archlog
alter system set log_archive_dest_1='location=/data/archlog' scope=both;

如果Oracle 9i,需要设置log_archive_start为true,表示自动切换归档,10g以上已废弃该参数
 alter system set log_archive_start=true scope=spfile;
 
 3、关闭数据库
 SQL> shutdown immediate
 SQL>STARTUP MOUNT                 ---启动到MOUNT状态
 SQL>alter database archivelog;    ---开归档
 SQL> archive log list             ---检查
Database log mode              Archive Mode
Automatic archival             Enabled
Archive destination            /data/archlog
Oldest online log sequence     2
Next log sequence to archive   4
Current log sequence           4

查看多大切一次归档
SQL> select * from v$log;     ---可以看到50M切一次                                 
SQL> show parameter lag       ---查看多少时间自动生成一条归档

NAME                                 TYPE        VALUE
------------------------------------ ----------- ------------------------------
archive_lag_target                   integer     0
plsql_ccflags                        string
plsql_compiler_flags                 string      INTERPRETED, NON_DEBUG    

 如果需要10分钟切换一次归档,需要设置
 alter system set archive_lag_target=600;
 
测试 手动切换归档
 SQL> alter system switch logfile;
可看到在 /data/archlog 下出现一条归档

 
二、关闭归档模式
SQL> shutdown immediate
SQL> startup mount
SQL>alter database noarchivelog;
SQL> archive log list
Database log mode              No Archive Mode
Automatic archival             Disabled
Archive destination            /data/archlog
Oldest online log sequence     2
Current log sequence           4


配置闪回:
配置闪回前提数据库必须处于归档模式,如果处于非归档模式配置闪回,则会出现以下错误:
SQL> alter database flashback on;
alter database flashback on
*
ERROR at line 1:
ORA-38706: Cannot turn on FLASHBACK DATABASE logging.
ORA-38707: Media recovery is not enabled.


SQL> show parameter recover     ---查看闪回状态

NAME                                 TYPE        VALUE
------------------------------------ ----------- ------------------------------
db_recovery_file_dest                string
db_recovery_file_dest_size           big integer 0
recovery_parallelism                 integer     0

1、$ mkdir -p /data/flashback      --新建闪回路径
alter system set db_recovery_file_dest_size=1024m;       ---配置闪回空间
alter system set db_recovery_file_dest='/data/flashback';  ---设置闪回路径

2.SQL> show parameter flash     ---查看闪回日志保留时间,默认1天,单位(分钟)

NAME                                 TYPE        VALUE
------------------------------------ ----------- ------------------------------
db_flashback_retention_target        integer     1440

SQL> alter system set db_flashback_retention_target=2880;   --修改闪回日志保留时间


3.将数据库启动至mount状态,打开闪回
SQL> alter database flashback on;
查看闪回是否开启
SQL> select flashback_on from v$database;


4.关闭闪回
SQL> shutdown immediate
SQL> startup mount
SQL> alter database flashback off;

你可能感兴趣的:(数据库,职场,休闲,归档闪回)