resetlogs noresetlogs,resetlogs
SQL> select * from v$version where rownum=1;
BANNER
--------------------------------------------------------------------------------
Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - Production
SQL> !cat /etc/issue
Enterprise Linux Enterprise Linux Server release 5.5 (Carthage)
Kernel \r on an \m
我們在通過重建控制檔案時,到底以哪種方式,resetlogs還是noresetlogs呢?
關於控制檔案的建立過程,參考之前寫過的文章http://blog.itpub.net/29876893/viewspace-1575070/,在備份的建立 控制檔案的指令碼中,也詳細介紹了重建的過程,交代了resetlogs和noresetlogs兩種方式,細則給出了添加TEMP資料表空間的資料檔案。
SQL> alter database backup controlfile to trace;
資料庫已更改。
SQL> select value from v$diag_info where name='Default Trace File';
VALUE
--------------------------------------------------------------------------------
/u01/app/oracle/diag/rdbms/orcl3939/orcl3939/trace/orcl3939_ora_22671.trc
開啟控制檔案的建立語句的備份trace檔案:
*** 2015-06-17 12:17:18.453
*** SESSION ID:(125.7) 2015-06-17 12:17:18.454
*** CLIENT ID:() 2015-06-17 12:17:18.454
*** SERVICE NAME:(SYS$USERS) 2015-06-17 12:17:18.454
*** MODULE NAME:(sqlplus@localhost.localdomain (TNS V1-V3)) 2015-06-17 12:17:18.454
*** ACTION NAME:() 2015-06-17 12:17:18.454
-- The following are current System-scope REDO Log Archival related
-- parameters and can be included in the database initialization file.
--
-- LOG_ARCHIVE_DEST=''
-- LOG_ARCHIVE_DUPLEX_DEST=''
--
-- LOG_ARCHIVE_FORMAT=%t_%s_%r.dbf
--
-- DB_UNIQUE_NAME="orcl3939"
--
-- LOG_ARCHIVE_CONFIG='SEND, RECEIVE, NODG_CONFIG'
-- LOG_ARCHIVE_MAX_PROCESSES=4
-- STANDBY_FILE_MANAGEMENT=MANUAL
-- STANDBY_ARCHIVE_DEST=?/dbs/arch
-- FAL_CLIENT=''
-- FAL_SERVER=''
--
-- LOG_ARCHIVE_DEST_1='LOCATION=USE_DB_RECOVERY_FILE_DEST'
-- LOG_ARCHIVE_DEST_1='MANDATORY NOREOPEN NODELAY'
-- LOG_ARCHIVE_DEST_1='ARCH NOAFFIRM EXPEDITE NOVERIFY SYNC'
-- LOG_ARCHIVE_DEST_1='NOREGISTER NOALTERNATE NODEPENDENCY'
-- LOG_ARCHIVE_DEST_1='NOMAX_FAILURE NOQUOTA_SIZE NOQUOTA_USED NODB_UNIQUE_NAME'
-- LOG_ARCHIVE_DEST_1='VALID_FOR=(PRIMARY_ROLE,ONLINE_LOGFILES)'
-- LOG_ARCHIVE_DEST_STATE_1=ENABLE
--
-- Below are two sets of SQL statements, each of which creates a new
-- control file and uses it to open the database. The first set opens
-- the database with the NORESETLOGS option and should be used only if
-- the current versions of all online logs are available. The second
-- set opens the database with the RESETLOGS option and should be used
-- if online logs are unavailable.
-- The appropriate set of statements can be copied from the trace into
-- a script file, edited as necessary, and executed when there is a
-- need to re-create the control file.
--
-- Set #1. NORESETLOGS case
--
-- The following commands will create a new control file and use it
-- to open the database.
-- Data used by Recovery Manager will be lost.
-- Additional logs may be required for media recovery of offline
-- Use this only if the current versions of all online logs are
-- available.
-- After mounting the created controlfile, the following SQL
-- statement will place the database in the appropriate
-- protection mode:
-- ALTER DATABASE SET STANDBY DATABASE TO MAXIMIZE PERFORMANCE
STARTUP NOMOUNT
CREATE CONTROLFILE REUSE DATABASE "ORCL3939" NORESETLOGS NOARCHIVELOG
MAXLOGFILES 16
MAXLOGMEMBERS 3
MAXDATAFILES 100
MAXINSTANCES 8
MAXLOGHISTORY 292
LOGFILE
GROUP 1 '/u01/app/oracle/oradata/orcl3939/redo01.log' SIZE 50M BLOCKSIZE 512,
GROUP 2 '/u01/app/oracle/oradata/orcl3939/redo02.log' SIZE 50M BLOCKSIZE 512,
GROUP 3 '/u01/app/oracle/oradata/orcl3939/redo03.log' SIZE 50M BLOCKSIZE 512
-- STANDBY LOGFILE
DATAFILE
'/u01/app/oracle/oradata/orcl3939/system01.dbf',
'/u01/app/oracle/oradata/orcl3939/sysaux01.dbf',
'/u01/app/oracle/oradata/orcl3939/undotbs01.dbf',
'/u01/app/oracle/oradata/orcl3939/user01.dbf',
'/u01/app/oracle/oradata/orcl3939/example01.dbf',
'/u01/app/oracle/oradata/orcl3939/chao.dbf',
'/u01/app/oracle/oradata/orcl3939/big_file',
'/u01/app/oracle/oradata/orcl3939/undo_w.dbf',
'/u01/app/oracle/oradata/orcl3939/a.dbf',
'/u01/app/oracle/oradata/orcl3939/v.dbf'
CHARACTER SET AL32UTF8
;
-- Commands to re-create incarnation table
-- Below log names MUST be changed to existing filenames on
-- disk. Any one log file from each branch can be used to
-- re-create incarnation records.
-- ALTER DATABASE REGISTER LOGFILE '/u01/app/oracle/flash_recovery_area/ORCL3939/archivelog/2015_06_17/o1_mf_1_1_%u_.arc';
-- ALTER DATABASE REGISTER LOGFILE '/u01/app/oracle/flash_recovery_area/ORCL3939/archivelog/2015_06_17/o1_mf_1_1_%u_.arc';
-- Recovery is required if any of the datafiles are restored backups,
-- or if the last shutdown was not normal or immediate.
RECOVER DATABASE
-- Database can now be opened normally.
ALTER DATABASE OPEN;
-- Commands to add tempfiles to temporary tablespaces.
-- Online tempfiles have complete space information.
-- Other tempfiles may require adjustment.
ALTER TABLESPACE TEMP ADD TEMPFILE '/u01/app/oracle/oradata/orcl3939/temp01.dbf'
SIZE 2526M REUSE AUTOEXTEND ON NEXT 655360 MAXSIZE 32767M;
ALTER TABLESPACE TEMP_WANG ADD TEMPFILE '/u01/app/oracle/oradata/orcl3939/temp_wang.dbf'
SIZE 31457280 REUSE AUTOEXTEND OFF;
-- End of tempfile additions.
--
-- Set #2. RESETLOGS case
--
-- The following commands will create a new control file and use it
-- to open the database.
-- Data used by Recovery Manager will be lost.
-- The contents of online logs will be lost and all backups will
-- be invalidated. Use this only if online logs are damaged.
-- After mounting the created controlfile, the following SQL
-- statement will place the database in the appropriate
-- protection mode:
-- ALTER DATABASE SET STANDBY DATABASE TO MAXIMIZE PERFORMANCE
STARTUP NOMOUNT
CREATE CONTROLFILE REUSE DATABASE "ORCL3939" RESETLOGS NOARCHIVELOG
MAXLOGFILES 16
MAXLOGMEMBERS 3
MAXDATAFILES 100
MAXINSTANCES 8
MAXLOGHISTORY 292
LOGFILE
GROUP 1 '/u01/app/oracle/oradata/orcl3939/redo01.log' SIZE 50M BLOCKSIZE 512,
GROUP 2 '/u01/app/oracle/oradata/orcl3939/redo02.log' SIZE 50M BLOCKSIZE 512,
GROUP 3 '/u01/app/oracle/oradata/orcl3939/redo03.log' SIZE 50M BLOCKSIZE 512
-- STANDBY LOGFILE
DATAFILE
'/u01/app/oracle/oradata/orcl3939/system01.dbf',
'/u01/app/oracle/oradata/orcl3939/sysaux01.dbf',
'/u01/app/oracle/oradata/orcl3939/undotbs01.dbf',
'/u01/app/oracle/oradata/orcl3939/user01.dbf',
'/u01/app/oracle/oradata/orcl3939/example01.dbf',
'/u01/app/oracle/oradata/orcl3939/chao.dbf',
'/u01/app/oracle/oradata/orcl3939/big_file',
'/u01/app/oracle/oradata/orcl3939/undo_w.dbf',
'/u01/app/oracle/oradata/orcl3939/a.dbf',
'/u01/app/oracle/oradata/orcl3939/v.dbf'
CHARACTER SET AL32UTF8
;
-- Commands to re-create incarnation table
-- Below log names MUST be changed to existing filenames on
-- disk. Any one log file from each branch can be used to
-- re-create incarnation records.
-- ALTER DATABASE REGISTER LOGFILE '/u01/app/oracle/flash_recovery_area/ORCL3939/archivelog/2015_06_17/o1_mf_1_1_%u_.arc';
-- ALTER DATABASE REGISTER LOGFILE '/u01/app/oracle/flash_recovery_area/ORCL3939/archivelog/2015_06_17/o1_mf_1_1_%u_.arc';
-- Recovery is required if any of the datafiles are restored backups,
-- or if the last shutdown was not normal or immediate.
RECOVER DATABASE USING BACKUP CONTROLFILE
-- Database can now be opened zeroing the online logs.
ALTER DATABASE OPEN RESETLOGS;
-- Commands to add tempfiles to temporary tablespaces.
-- Online tempfiles have complete space information.
-- Other tempfiles may require adjustment.
ALTER TABLESPACE TEMP ADD TEMPFILE '/u01/app/oracle/oradata/orcl3939/temp01.dbf'
SIZE 2526M REUSE AUTOEXTEND ON NEXT 655360 MAXSIZE 32767M;
ALTER TABLESPACE TEMP_WANG ADD TEMPFILE '/u01/app/oracle/oradata/orcl3939/temp_wang.dbf'
SIZE 31457280 REUSE AUTOEXTEND OFF;
-- End of tempfile additions.
--
上面紅色字型已經交代了了什麼時候該用resetlogs和noresetlogs建立。如果當前資料庫的REDO LOG都可用時,可以通過noresetlogs參數重建控制檔案,此時oracle可以通過記錄檔中讀取redo資訊,記錄到控制檔案中,由於redo中記錄的資訊足以重演所有提交成功的事務,所有最終能夠實現完全恢複,成功開啟資料庫,此時的資料庫就如斷電一樣之後的執行個體恢複,資料沒有損失,重做日誌可以繼續向前寫入。
但是oracle認為在resetlogs方式下,當前的記錄檔已經損失,那麼就意味著oracle可能丟失提交成功的資料,恢複將是一次不完全的介質恢複,resetlogs會強制清空或者重建線上記錄檔。
完成恢複後需要以resetlogs方式開啟資料庫的幾種常見情況:
1.在執行了不完全恢複之後
2.在使用了備份的控制檔案進行恢複後
3.使用帶有resetlogs選項建立的控制檔案恢複之後
是個小知識點,希望和大家共勉!