最近在一个测试数据上设置了参数db_recovery_file_dest_size (也就是flashback recovery area的大小),并且把archive log destination 指向了这个flashback recovery area, (USE_DB_RECOVERY_FILE_DEST)
Database log mode Archive Mode
Automatic archival Enabled
Archive destination USE_DB_RECOVERY_FILE_DEST
Oldest online log sequence 305
Next log sequence to archive 307
Current log sequence 307
由于flashback recovery area的大小设置不够大,归档日志文件占用的空间却越来越大,所以经常会出现数据库启动不起来的问题,因为用语空间不足,造成online redo log file不能归档,所以数据库没法open。每次都会用rman来清理下flashback recovery area,但是这太繁琐。当然可以让数据库运行于nonarchive log 模式下,但是这个显然不是很好的选择,毕竟归档日志文件在数据库恢复的时候还是很关键的。
( 设置数据库是否为归档模式的操作很简单,
SQL> alter database archivelog
但是需要注意的是,这个操作需要在mount状态下进行.)
所以,一个折中的方法是换个地方来保存归档日志文件,当然可以增加flashback recovery area的大小或者定期把归档日志文件转移到其他磁盘。本文的目的不在于探讨best practice, 主要是温习下基本的关于更改归档日志文件路径的操作而已。
Part 1: How to Get the Log Mode under which Oracle is Running
尽管Oracle数据库几乎都应该运行在archive log模式下,但是总有些exceptions. 有时候我们需要快速知道一个数据库是否运行在archive log模式下,一般来说可以通过动态视图v$database查询得到。v$database结构如下,
Name Null? Type
----------------------------------------- -------- ----------------
DBID NUMBER
NAME VARCHAR2(9)
CREATED DATE
RESETLOGS_CHANGE# NUMBER
RESETLOGS_TIME DATE
PRIOR_RESETLOGS_CHANGE# NUMBER
PRIOR_RESETLOGS_TIME DATE
LOG_MODE VARCHAR2(12)
CHECKPOINT_CHANGE# NUMBER
ARCHIVE_CHANGE# NUMBER
CONTROLFILE_TYPE VARCHAR2(7)
CONTROLFILE_CREATED DATE
CONTROLFILE_SEQUENCE# NUMBER
CONTROLFILE_CHANGE# NUMBER
CONTROLFILE_TIME DATE
OPEN_RESETLOGS VARCHAR2(11)
VERSION_TIME DATE
OPEN_MODE VARCHAR2(10)
PROTECTION_MODE VARCHAR2(20)
PROTECTION_LEVEL VARCHAR2(20)
REMOTE_ARCHIVE VARCHAR2(8)
ACTIVATION# NUMBER
SWITCHOVER# NUMBER
DATABASE_ROLE VARCHAR2(16)
ARCHIVELOG_CHANGE# NUMBER
ARCHIVELOG_COMPRESSION VARCHAR2(8)
SWITCHOVER_STATUS VARCHAR2(20)
DATAGUARD_BROKER VARCHAR2(8)
GUARD_STATUS VARCHAR2(7)
SUPPLEMENTAL_LOG_DATA_MIN VARCHAR2(8)
SUPPLEMENTAL_LOG_DATA_PK VARCHAR2(3)
SUPPLEMENTAL_LOG_DATA_UI VARCHAR2(3)
FORCE_LOGGING VARCHAR2(3)
PLATFORM_ID NUMBER
PLATFORM_NAME VARCHAR2(101)
RECOVERY_TARGET_INCARNATION# NUMBER
LAST_OPEN_INCARNATION# NUMBER
CURRENT_SCN NUMBER
FLASHBACK_ON VARCHAR2(18)
SUPPLEMENTAL_LOG_DATA_FK VARCHAR2(3)
SUPPLEMENTAL_LOG_DATA_ALL VARCHAR2(3)
DB_UNIQUE_NAME VARCHAR2(30)
STANDBY_BECAME_PRIMARY_SCN NUMBER
FS_FAILOVER_STATUS VARCHAR2(21)
FS_FAILOVER_CURRENT_TARGET VARCHAR2(30)
FS_FAILOVER_THRESHOLD NUMBER
FS_FAILOVER_OBSERVER_PRESENT VARCHAR2(7)
FS_FAILOVER_OBSERVER_HOST VARCHAR2(512)
SQL>
ORACLE instance started.
Total System Global Area 612368384 bytes
Fixed Size 1298208 bytes
Variable Size 381681888 bytes
Database Buffers 222298112 bytes
Redo Buffers 7090176 bytes
SQL> select dbid, name, log_mode, open_mode from v$database;
select dbid, name, log_mode, open_mode from v$database
*
ERROR at line 1:
ORA-01507: database not mounted
SQL> alter database mount;
Database altered.
SQL> select dbid, name, log_mode, open_mode from v$database;
DBID NAME LOG_MODE OPEN_MODE
---------- --------- ------------ ----------
1235521622 ORCL ARCHIVELOG MOUNTED
SQL> alter database open;
Database altered.
SQL> select dbid, name, log_mode, open_mode from v$database;
DBID NAME LOG_MODE OPEN_MODE
---------- --------- ------------ ----------
1235521622 ORCL ARCHIVELOG READ WRITE
SQL>
除了查询动态视图v$databse, 还可以通过sql*plus命令 archive log list 来获得, 如下
Database log mode Archive Mode
Automatic archival Enabled
Archive destination USE_DB_RECOVERY_FILE_DEST
Oldest online log sequence 305
Next log sequence to archive 307
Current log sequence 307
SQL>
从返回的信息不光可以看到数据库是否运行归档模式,还可以得到归档日志的目录以及当前在线日志的sequence. 还有两个与log相关的动态性能视图比较重要,v$log 和 v$log_history, 分别对应于online log 和 archived log, 简单地来理解。
Name Null? Type
----------------------------------------- -------- ---------------
GROUP# NUMBER
THREAD# NUMBER
SEQUENCE# NUMBER
BYTES NUMBER
MEMBERS NUMBER
ARCHIVED VARCHAR2(3)
STATUS VARCHAR2(16)
FIRST_CHANGE# NUMBER
FIRST_TIME DATE
SQL> desc v$log_history;
Name Null? Type
----------------------------------------- -------- ---------------
RECID NUMBER
STAMP NUMBER
THREAD# NUMBER
SEQUENCE# NUMBER
FIRST_CHANGE# NUMBER
FIRST_TIME DATE
NEXT_CHANGE# NUMBER
RESETLOGS_CHANGE# NUMBER
RESETLOGS_TIME DATE
SQL>
Part 2:How to Change Redo Log File Archvie Dest
关于如何更改归档日志文件的存储路径,OBE有个示例(http://www.oracle.com/technology/obe/paa/obe-arc/html/Chg_Arch_Dest.htm), 针对我的测试数据库,我可以进行如下的简单操作即可,
adata\orcl\archivelog';
System altered.
SQL> archive log list;
Database log mode Archive Mode
Automatic archival Enabled
Archive destination E:\oracle\product\10.2.0\oradata\orcl\archivelog
Oldest online log sequence 305
Next log sequence to archive 307
Current log sequence 307
SQL>