Oracle 归档模式的打开及关闭

来源:互联网 发布:js prompt 使用方法 编辑:程序博客网 时间:2024/05/21 22:42
Oracle可以运行在2种模式下:归档模式(archivelog)和非归档模式(noarchivelog)

归档模式可以提高Oracle数据库的可恢复性,生产数据库都应该运行在此模式下,归档模式应该和相应的备份策略相结合,只有归档模式没有相应的备份策略只会带来麻烦。


本文简单介绍如何启用和关闭数据库的归档模式。

1.shutdown normal或shutdown immediate关闭数据库


[oracle@jumper oracle]$ sqlplus "/ as sysdba"
SQL*Plus: Release 9.2.0.4.0 - Production on Sat Oct 15 15:48:36 2005
Copyright (c) 1982, 2002, Oracle Corporation.  All rights reserved.
Connected to:
Oracle9i Enterprise Edition Release 9.2.0.4.0 - Production
With the Partitioning option
JServer Release 9.2.0.4.0 - Production
SQL> shutdown immediate;
Database closed.
Database dismounted.
ORACLE instance shut down.

2.启动数据库到mount状态
SQL> startup mount;
ORACLE instance started.
Total System Global Area  101782828 bytes
Fixed Size                   451884 bytes
Variable Size              37748736 bytes
Database Buffers           62914560 bytes
Redo Buffers                 667648 bytes
Database mounted.

3.启用或停止归档模式
如果要启用归档模式,此处使用
alter database archivelog 命令。

SQL>alter database archivelog;Database altered.
SQL> alter database open;
Database altered.


SQL> archive log list;

Database log modeArchive ModeAutomatic archival             Enabled
Archive destination            /opt/oracle/oradata/conner/archive
Oldest online log sequence     148
Next log sequence to archive   151
Current log sequence           151

如果需要停止归档模式,此处使用:
alter database noarchivelog命令。

SQL> shutdown immediate; 
Database closed.
Database dismounted.
ORACLE instance shut down.
SQL> startup mount;
ORACLE instance started.
Total System Global Area  101782828 bytes
Fixed Size                   451884 bytes
Variable Size              37748736 bytes
Database Buffers           62914560 bytes
Redo Buffers                 667648 bytes
Database mounted.

SQL>alter database noarchivelog;

Database altered.

SQL> alter database open;
Database altered.
SQL> archive log list;
Database log modeNo Archive ModeAutomatic archival             Enabled
Archive destination            /opt/oracle/oradata/conner/archive
Oldest online log sequence     149
Current log sequence           152

4.修改相应的初始化参数
Oracle10g之前,你还需要修改初始化参数使数据库处于自动归档模式。
在pfile/spfile中设置如下参数:
log_archive_start = true
重启数据库此参数生效,此时数据库处于自动归档模式。
也可以在数据库启动过程中,手工执行:
archive log start

使数据库启用自动归档,但是重启后数据库仍然处于手工归档模式。

===================================================

 一 设置为归档方式

1 sql> archive log list;   #查看是不是归档方式
2 sql> alter system set log_archive_start=true scope=spfile; #启用主动归档
   sql> alter system set log_archive_dest=''location=/oracle/ora9/oradata/arch'' scope=spfile;#设置归档路径
   sql> alter system set log_archive_dest_1=''location=/oracle/ora9/oradata/arch1'' scope=spfile;
   sql> alter system set log_archive_dest_2=''location=/oracle/ora9/oradata/arch2'' scope=spfile;#如果归档到两个位置,则可以通过上边方法实现
  sql> alter system set log_archive_format=''arch_%d_%t_%r_%s.log''  #设置归档日记款式
3 sql> shutdown immediate;
4 sql> startup mount;    #打开控制文件,不打开数据文件
5 sql> alter database archivelog; #将数据库切换为归档模式
6 sql> alter database open;   #将数据文件打开
7 sql> archive log list;   #查看此时是否处于归档模式
8 查询以确定数据库位于archivelog模式中且归档过程正在运行
sql> select log_mode from v$database;
sql> select archiver from v$instance;
9 日志切换
sql> alter system switch logfile;
10 这次日志切换将归档写到两个目标地,
  1,即第二步的/oracle/ora9/oradata/arch1和/oracle/ora9/oradata/arch1,要是要对目录确认
在oracle情况中运行如下查询:
sql> select name from v$archived_log;
而后在操作系统中确认查询所列出的文件


二 设置非归档方式

1 sql> archive log list;   #查看是否是归档方式
2 sql> alter system set log_archive_start=false scope=spfile; #禁用自动归档
3 sql> shutdown immediate;
4 sql> startup mount;    #打开控制文件,不打开数据文件
5 sql> alter database noarchivelog; #将数据库切换为非归档模式
6 sql> alter database open;   #将数据文件打开
7 sql> archive log list;   #查看此时便处于非归档模式


三 归档相关命令

archive log stop;
archive log start;
archive log list;


show parameters;
show parameters log_archive_start;
show parameters log_archive_max_process; #归档进程数
alter system set log_archive_max_process=5; #将归档进程数改为5
select * from v$bgprocess;    #检察后台进程


0 0