若系统中缺少联机日志,以resetlogs方式重建控制文件,那么当我们以alter database open resetlogs方式打开数据库时,新生成的联机日志会位于何处?
一:下面分别讨论几种情况
1 如果在重建控制文件语句中未指定日志条目,未指定omf参数,那么resetlogs 打开数据库时,自动创建的日志位于何处
2 如果在重建控制文件语句中未指定日志条目,仅指定了omf参数db_create_file_dest, 那么resetlogs 打开数据库时,自动创建的日志位于何处
3 如果在重建控制文件语句中指定了日志条目,指定了omf参数,那么resetlogs 打开数据库事,自动创建的日志位于何处
4 如果在重建控制文件语句中未指定日志条目,指定了omf参数db_create_file_dest和 db_create_online_log_dest_n 那么resetlogs 打开数据库时,自动创建的日志位于何处
二:实验
实验1 重建控制文件语句未指定日志条目,未指定omf参数,那么resetlogs打开数据库后日志位置
1 实验前提
重建控制文件中不指定日志条目语句如下
STARTUP NOMOUNT
CREATE CONTROLFILE REUSE DATABASE "ZBCRM" RESETLOGS ARCHIVELOG
MAXLOGFILES 16
MAXLOGMEMBERS 3
MAXDATAFILES 100
MAXINSTANCES 8
MAXLOGHISTORY 292
DATAFILE
'/oracle/CRM/ZBCRM/system01.dbf',
'/oracle/CRM/ZBCRM/sysaux01.dbf',
'/oracle/CRM/ZBCRM/undotbs01.dbf',
'/oracle/CRM/ZBCRM/users01.dbf',
'/oracle/CRM/ZBCRM/sysaux02.dbf'
CHARACTER SET ZHS16GBK
;
参数文件中未指定omf参数
NAME VALUE
---------------------------------------- --------------------------------------------------
db_create_file_dest
db_create_online_log_dest_1
db_create_online_log_dest_2
db_create_online_log_dest_3
db_create_online_log_dest_4
db_create_online_log_dest_5
db_recovery_file_dest
db_recovery_file_dest_size 0
2 过程如下:
SQL> @/oracle/control1.sql
ORACLE instance started.
Total System Global Area 1152450560 bytes
Fixed Size 2225832 bytes
Variable Size 704645464 bytes
Database Buffers 436207616 bytes
Redo Buffers 9371648 bytes
Control file created.
SQL> alter database open;
alter database open
*
ERROR at line 1:
ORA-01589: must use RESETLOGS or NORESETLOGS option for database open
SQL> alter database open resetlogs;
Database altered.
SQL> select open_mode from v$database;
OPEN_MODE
--------------------
READ WRITE
SQL> col member for a50
SQL> select group#,member from v$logfile;
GROUP# MEMBER
---------- --------------------------------------------------
2 /oracle/app/db1/dbs/log2ZBCRM.dbf
1 /oracle/app/db1/dbs/log1ZBCRM.dbf
结果:当控制文件重建语句中未指定日志条目,也未设置omf参数,那么resetlogs 打开数据库后新创建的日志文件位于dbs目录下。
实验2 重建控制文件语句中未指定了日志位置,指定omf参数,那么resetlogs打开数据库后日志位置
1 实验前提
重建控制文件语句如下
STARTUP NOMOUNT
CREATE CONTROLFILE REUSE DATABASE "ZBCRM" RESETLOGS ARCHIVELOG
MAXLOGFILES 16
MAXLOGMEMBERS 3
MAXDATAFILES 100
MAXINSTANCES 8
MAXLOGHISTORY 292
DATAFILE
'/oracle/CRM/ZBCRM/system01.dbf',
'/oracle/CRM/ZBCRM/sysaux01.dbf',
'/oracle/CRM/ZBCRM/undotbs01.dbf',
'/oracle/CRM/ZBCRM/users01.dbf',
'/oracle/CRM/ZBCRM/sysaux02.dbf'
CHARACTER SET ZHS16GBK
;
参数文件中指定omf参数
NAME VALUE
---------------------------------------- ----------------------------------------
db_create_file_dest /oracle/CRM/ZBCRM/
db_create_online_log_dest_1
db_create_online_log_dest_2
db_create_online_log_dest_3
db_create_online_log_dest_4
db_create_online_log_dest_5
db_recovery_file_dest
db_recovery_file_dest_size 0
2 实验过程如下:
[oracle@oracle ~]$ cat control1.sql
STARTUP NOMOUNT
CREATE CONTROLFILE REUSE DATABASE "ZBCRM" RESETLOGS ARCHIVELOG
MAXLOGFILES 16
MAXLOGMEMBERS 3
MAXDATAFILES 100
MAXINSTANCES 8
MAXLOGHISTORY 292
DATAFILE
'/oracle/CRM/ZBCRM/system01.dbf',
'/oracle/CRM/ZBCRM/sysaux01.dbf',
'/oracle/CRM/ZBCRM/undotbs01.dbf',
'/oracle/CRM/ZBCRM/users01.dbf',
'/oracle/CRM/ZBCRM/sysaux02.dbf'
CHARACTER SET ZHS16GBK
;
[oracle@oracle ~]$ sqlplus / as sysdba
SQL*Plus: Release 11.2.0.2.0 Production on Fri Jul 26 16:33:49 2013
Copyright (c) 1982, 2010, Oracle. All rights reserved.
Connected to an idle instance.
SQL> @/oracle/control1.sql
ORACLE instance started.
Total System Global Area 1152450560 bytes
Fixed Size 2225832 bytes
Variable Size 704645464 bytes
Database Buffers 436207616 bytes
Redo Buffers 9371648 bytes
Control file created.
SQL> alter database open resetlogs;
Database altered.
SQL> col member for a60
SQL> /
GROUP# MEMBER
---------- ------------------------------------------------------------
2 /oracle/CRM/ZBCRM/ZBCRM/onlinelog/o1_mf_2_8z4f4kon_.log
1 /oracle/CRM/ZBCRM/ZBCRM/onlinelog/o1_mf_1_8z4f4gcl_.log
结果:当重建控制文件语句中为指定日志条目,仅指定omf参数db_create_file_dest时,resetlogs打开数据库后,日志位于db_create_file_dest指定的目录。
实验3 重建控制文件语句指定日志条目,指定omf参数,那么resetlogs打开数据库后日志位置
1 实验前提
重建控制文件中指定日志条目语句如下
STARTUP NOMOUNT
CREATE CONTROLFILE REUSE DATABASE "ZBCRM" RESETLOGS ARCHIVELOG
MAXLOGFILES 16
MAXLOGMEMBERS 3
MAXDATAFILES 100
MAXINSTANCES 8
MAXLOGHISTORY 292
LOGFILE
GROUP 1 '/oracle/CRM/ZBCRM/redo01.log' SIZE 200M BLOCKSIZE 512,
GROUP 2 '/oracle/CRM/ZBCRM/redo02.log' SIZE 200M BLOCKSIZE 512,
GROUP 3 '/oracle/CRM/ZBCRM/redo03.log' SIZE 200M BLOCKSIZE 512
-- STANDBY LOGFILE
DATAFILE
'/oracle/CRM/ZBCRM/system01.dbf',
'/oracle/CRM/ZBCRM/sysaux01.dbf',
'/oracle/CRM/ZBCRM/undotbs01.dbf',
'/oracle/CRM/ZBCRM/users01.dbf',
'/oracle/CRM/ZBCRM/sysaux02.dbf'
CHARACTER SET ZHS16GBK
;
2 omf 参数如下:
NAME VALUE
-------------------------------------------------- ------------------------------------------------------------
db_create_file_dest /oracle/CRM/ZBCRM/
db_create_online_log_dest_1 /oracle/CRM/ZBCRM/log1
db_create_online_log_dest_2 /oracle/CRM/ZBCRM/log2
db_create_online_log_dest_3
db_create_online_log_dest_4
db_create_online_log_dest_5
db_recovery_file_dest
db_recovery_file_dest_size 0
3 实验过程如下:
[oracle@oracle ~]$ cat control2.sql
STARTUP NOMOUNT
CREATE CONTROLFILE REUSE DATABASE "ZBCRM" RESETLOGS ARCHIVELOG
MAXLOGFILES 16
MAXLOGMEMBERS 3
MAXDATAFILES 100
MAXINSTANCES 8
MAXLOGHISTORY 292
LOGFILE
GROUP 1 '/oracle/CRM/ZBCRM/redo01.log' SIZE 200M BLOCKSIZE 512,
GROUP 2 '/oracle/CRM/ZBCRM/redo02.log' SIZE 200M BLOCKSIZE 512,
GROUP 3 '/oracle/CRM/ZBCRM/redo03.log' SIZE 200M BLOCKSIZE 512
-- STANDBY LOGFILE
DATAFILE
'/oracle/CRM/ZBCRM/system01.dbf',
'/oracle/CRM/ZBCRM/sysaux01.dbf',
'/oracle/CRM/ZBCRM/undotbs01.dbf',
'/oracle/CRM/ZBCRM/users01.dbf',
'/oracle/CRM/ZBCRM/sysaux02.dbf'
CHARACTER SET ZHS16GBK
;
[oracle@oracle ~]$ sqlplus / as sysdba
SQL*Plus: Release 11.2.0.2.0 Production on Fri Jul 26 16:52:26 2013
Copyright (c) 1982, 2010, Oracle. All rights reserved.
Connected to an idle instance.
SQL> @/oracle/control2.sql
ORACLE instance started.
Total System Global Area 1152450560 bytes
Fixed Size 2225832 bytes
Variable Size 704645464 bytes
Database Buffers 436207616 bytes
Redo Buffers 9371648 bytes
Control file created.
SQL> alter database open resetlogs;
Database altered.
SQL> col member for a50
SQL> select group#,member from v$logfile;
GROUP# MEMBER
---------- --------------------------------------------------
3 /oracle/CRM/ZBCRM/redo03.log
2 /oracle/CRM/ZBCRM/redo02.log
1 /oracle/CRM/ZBCRM/redo01.log
结果:当重建控制文件语句中指定日志条目,又指定了omf参数,那么新生成的日志文件位置以控制文件为准。
实验4 重建控制文件语句中未指定了日志位置,指定omf参数db_create_file_dest和 db_create_online_log_dest_n,那么resetlogs打开数据库后日志位置
1 实验前提
重建控制文件中指定日志条目语句如下
STARTUP NOMOUNT
CREATE CONTROLFILE REUSE DATABASE "ZBCRM" RESETLOGS ARCHIVELOG
MAXLOGFILES 16
MAXLOGMEMBERS 3
MAXDATAFILES 100
MAXINSTANCES 8
MAXLOGHISTORY 292
LOGFILE
GROUP 1 '/oracle/CRM/ZBCRM/redo01.log' SIZE 200M BLOCKSIZE 512,
GROUP 2 '/oracle/CRM/ZBCRM/redo02.log' SIZE 200M BLOCKSIZE 512,
GROUP 3 '/oracle/CRM/ZBCRM/redo03.log' SIZE 200M BLOCKSIZE 512
-- STANDBY LOGFILE
DATAFILE
'/oracle/CRM/ZBCRM/system01.dbf',
'/oracle/CRM/ZBCRM/sysaux01.dbf',
'/oracle/CRM/ZBCRM/undotbs01.dbf',
'/oracle/CRM/ZBCRM/users01.dbf',
'/oracle/CRM/ZBCRM/sysaux02.dbf'
CHARACTER SET ZHS16GBK
;
2 omf 参数如下:
NAME VALUE
-------------------------------------------------- ------------------------------------------------------------
db_create_file_dest /oracle/CRM/ZBCRM/
db_create_online_log_dest_1 /oracle/CRM/ZBCRM/log1
db_create_online_log_dest_2 /oracle/CRM/ZBCRM/log2
db_create_online_log_dest_3
db_create_online_log_dest_4
db_create_online_log_dest_5
db_recovery_file_dest
db_recovery_file_dest_size 0
3 实验过程如下:
[oracle@oracle ~]$ cat control1.sql
STARTUP NOMOUNT
CREATE CONTROLFILE REUSE DATABASE "ZBCRM" RESETLOGS ARCHIVELOG
MAXLOGFILES 16
MAXLOGMEMBERS 3
MAXDATAFILES 100
MAXINSTANCES 8
MAXLOGHISTORY 292
DATAFILE
'/oracle/CRM/ZBCRM/system01.dbf',
'/oracle/CRM/ZBCRM/sysaux01.dbf',
'/oracle/CRM/ZBCRM/undotbs01.dbf',
'/oracle/CRM/ZBCRM/users01.dbf',
'/oracle/CRM/ZBCRM/sysaux02.dbf'
CHARACTER SET ZHS16GBK
;
[oracle@oracle ~]$ sqlplus / as sysdba
SQL*Plus: Release 11.2.0.2.0 Production on Fri Jul 26 17:01:24 2013
Copyright (c) 1982, 2010, Oracle. All rights reserved.
Connected to an idle instance.
SQL> @/oracle/control1.sql
ORACLE instance started.
Total System Global Area 1152450560 bytes
Fixed Size 2225832 bytes
Variable Size 704645464 bytes
Database Buffers 436207616 bytes
Redo Buffers 9371648 bytes
Control file created.
SQL> alter database open resetlogs;
Database altered.
SQL> col member for a60
SQL> select group#,member from v$logfile;
GROUP# MEMBER
---------- ------------------------------------------------------------
2 /oracle/CRM/ZBCRM/log1/ZBCRM/onlinelog/o1_mf_2_8z4grccs_.log
2 /oracle/CRM/ZBCRM/log2/ZBCRM/onlinelog/o1_mf_2_8z4grd0x_.log
1 /oracle/CRM/ZBCRM/log1/ZBCRM/onlinelog/o1_mf_1_8z4gr4yz_.log
1 /oracle/CRM/ZBCRM/log2/ZBCRM/onlinelog/o1_mf_1_8z4gr5p0_.log
结果:ofm参数中优先级db_create_online_log_dest_n高于db_create_file_dest
总结:通过以上实验不难看出,当resetlogs打开数据库时,生成新的日志文件位置由以下因素决定:
先以控制文件中记录的日志文件位置为准.如果控制文件中没日志位置信息,则会查omf参数,优先级为,先db_create_online_log_dest_n后db_create_file_dest。
如果未指定omf参数则生成日志文件的默认位置为:比如linux 就是dbs下。