alter system backup controlfile to trace內容詳解

wisdomone1發表於2010-04-13
---下面透過alter system backup controlfile to trace抽取的控制檔案源本,講得很不錯

-- 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.
--
-----註解:重建控制控制檔案分為兩種型別:noresetlogs和resetlogs。
-----      二者區別:前者主要用於所在線上日誌可以用,後者相反,就是線上日誌不可用














--     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.---重建後rman所有使用的資料就不能用了,所以馬上進行備份方為安全
-- 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   ---這個是說,mount了重建的控制檔案之後,如下sql會把資料庫載入到一個合適的保護模式(dg)
-- statement will place the database in the appropriate
-- protection mode:
--  ALTER DATABASE SET STANDBY DATABASE TO MAXIMIZE PERFORMANCE


--重建控制檔案資料庫在nomount狀態下
STARTUP NOMOUNT


----重建控制檔案
CREATE CONTROLFILE REUSE DATABASE "ONLY" NORESETLOGS  ARCHIVELOG
    MAXLOGFILES 192
    MAXLOGMEMBERS 3
    MAXDATAFILES 1024
    MAXINSTANCES 32
    MAXLOGHISTORY 292
LOGFILE
  GROUP 1 '+ASM1/only/redo01.log'  SIZE 50M,
  GROUP 2 '+ASM1/only/redo02.log'  SIZE 50M,
  GROUP 3 '+ASM1/only/redo03.log'  SIZE 50M,
  GROUP 4 '+ASM1/only/redo04.log'  SIZE 50M
-- STANDBY LOGFILE
DATAFILE
  '+ASM1/only/system01.dbf',
  '+ASM1/only/undotbs01.dbf',
  '+ASM1/only/sysaux01.dbf',
  '+ASM1/only/users01.dbf',
  '+ASM1/only/undotbs02.dbf'
CHARACTER SET WE8ISO8859P1
;




----下列講的啥,呵呵。一些重建化身表的命令,log名字以下必須改變到磁碟已存在的檔案上;每個分支的任何一個log file,用它們可以重建化身記錄,
-- 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 '+ASM1/only/1_1_562360180.dbf';
-- ALTER DATABASE REGISTER LOGFILE '+ASM1/only/1_1_716018174.dbf';



---如果資料檔案使用了用來還原的備份,也可能是上次關機沒用採用常規normal或immediate方式;此時需要你對此進行恢復;
-- Recovery is required if any of the datafiles are restored backups,
-- or if the last shutdown was not normal or immediate.
RECOVER DATABASE




----執行完以上命令,馬上進行線上日誌的全部歸檔並進行一個新的日誌切換
-- All logs need archiving and a log switch is needed.
ALTER SYSTEM ARCHIVE LOG ALL;



---這下資料庫可以正常開啟了
-- 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 '+ASM1/only/temp01.dbf'
     SIZE 20971520  REUSE AUTOEXTEND ON NEXT 655360  MAXSIZE 32767M;
-- End of tempfile additions.
--







---這是第二種型別,resetlogs,在生產中這種非常多的。就是線上日誌也損壞了(可能是介質損壞)

--     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 "ONLY" RESETLOGS  ARCHIVELOG
    MAXLOGFILES 192
    MAXLOGMEMBERS 3
    MAXDATAFILES 1024
    MAXINSTANCES 32
    MAXLOGHISTORY 292
LOGFILE
  GROUP 1 '+ASM1/only/redo01.log'  SIZE 50M,
  GROUP 2 '+ASM1/only/redo02.log'  SIZE 50M
-- STANDBY LOGFILE
DATAFILE
  '+ASM1/only/system01.dbf',
  '+ASM1/only/undotbs01.dbf',
  '+ASM1/only/sysaux01.dbf',
  '+ASM1/only/users01.dbf',
  '+ASM1/only/undotbs02.dbf'
CHARACTER SET WE8ISO8859P1
;
-- 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 '+ASM1/only/1_1_562360180.dbf';
-- ALTER DATABASE REGISTER LOGFILE '+ASM1/only/1_1_716018174.dbf';
-- Recovery is required if any of the datafiles are restored backups,
-- or if the last shutdown was not normal or immediate.



------以上為我何沒有一句句註解,作用同noresetlogs是一樣的,故未再作註解,請看下面,這是重頭戲




-----利用備份的控制檔案恢復資料庫
RECOVER DATABASE USING BACKUP CONTROLFILE


---建立thread 2對應的日誌檔案(重用),請注意reuse
-- Create log files for threads other than thread one.
ALTER DATABASE ADD LOGFILE THREAD 2
  GROUP 3 '+ASM1/only/redo03.log' SIZE 50M REUSE,
  GROUP 4 '+ASM1/only/redo04.log' SIZE 50M REUSE;


---現在資料庫可能開啟了,但線上日誌內容全部是新的,也就是說裡面是空的
-- Database can now be opened zeroing the online logs.
ALTER DATABASE OPEN RESETLOGS;


---下面同noresetlogs一樣,不再註解
-- Commands to add tempfiles to temporary tablespaces.
-- Online tempfiles have complete space information.
-- Other tempfiles may require adjustment.
ALTER TABLESPACE TEMP ADD TEMPFILE '+ASM1/only/temp01.dbf'
     SIZE 20971520  REUSE AUTOEXTEND ON NEXT 655360  MAXSIZE 32767M;
-- End of tempfile additions.

來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/9240380/viewspace-659625/,如需轉載,請註明出處,否則將追究法律責任。

相關文章