天天看點

resetlogs 打開資料庫時新生成日志位置問題

若系統中缺少聯機日志,以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 實驗前提

      重建控制檔案語句如下

參數檔案中指定omf參數

---------------------------------------- ----------------------------------------

db_create_file_dest                      /oracle/CRM/ZBCRM/

db_create_online_log_dest_5

2 實驗過程如下:

[oracle@oracle ~]$ cat control1.sql

[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 

SQL> col member for a60

SQL> /

---------- ------------------------------------------------------------

         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打開資料庫後日志位置

    重建控制檔案中指定日志條目語句如下

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

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_recovery_file_dest_size                         0

3 實驗過程如下:

[oracle@oracle ~]$ cat control2.sql

SQL*Plus: Release 11.2.0.2.0 Production on Fri Jul 26 16:52:26 2013

SQL> @/oracle/control2.sql

         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打開資料庫後日志位置

[oracle@oracle ~]$ sqlplus  / as sysdba

SQL*Plus: Release 11.2.0.2.0 Production on Fri Jul 26 17:01:24 2013

         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下。

本文轉自 zhangxuwl 51CTO部落格,原文連結:http://blog.51cto.com/jiujian/1275820,如需轉載請自行聯系原作者