Oracle 11g重建控制檔案——如何獲取建立控制檔案指令碼
控制檔案對於資料庫來說是非常重要,在進行資料恢復時通常是必不可少的;丟失控制檔案並不是致命的,但是會使恢復變得困難很多。因此,dba除了多路儲存控制檔案外,還需要備份控制檔案。
備份控制檔案也有多種辦法,例如cp複製、rman自動備份等,今天給大家介紹如何獲取建立控制檔案的指令碼,這樣資料庫一旦出現意外,即使找不到可用的備份控制檔案,也能透過重建控制檔案來啟動資料庫。
Oracle提供瞭如下命令來實現這個功能:
alter database backup controlfile to trace;
備份控制檔案也有多種辦法,例如cp複製、rman自動備份等,今天給大家介紹如何獲取建立控制檔案的指令碼,這樣資料庫一旦出現意外,即使找不到可用的備份控制檔案,也能透過重建控制檔案來啟動資料庫。
Oracle提供瞭如下命令來實現這個功能:
alter database backup controlfile to trace;
1.環境準備
我們在Oracle11g中進行測試。點選(此處)摺疊或開啟
-
SQL>
-
SQL> select * from v$version;
-
-
BANNER
-
--------------------------------------------------------------------------------
-
Oracle Database 11g Enterprise Edition Release 11.2.0.3.0 - Production
-
PL/SQL Release 11.2.0.3.0 - Production
-
CORE 11.2.0.3.0 Production
-
TNS for Linux: Version 11.2.0.3.0 - Production
-
NLSRTL Version 11.2.0.3.0 - Production
-
- SQL>
2.生成trace檔案
開啟資料庫,執行‘alter database backup controlfile to trace;’語句來生成trace檔案。點選(此處)摺疊或開啟
-
[oracle@hoegh ~]$ sqlplus / as sysdba
-
-
SQL*Plus: Release 11.2.0.3.0 Production on Sat May 30 12:31:02 2015
-
-
Copyright (c) 1982, 2011, Oracle. All rights reserved.
-
-
Connected to an idle instance.
-
-
SQL>
-
SQL> startup
-
ORACLE instance started.
-
-
Total System Global Area 941600768 bytes
-
Fixed Size 1348860 bytes
-
Variable Size 515902212 bytes
-
Database Buffers 419430400 bytes
-
Redo Buffers 4919296 bytes
-
Database mounted.
-
Database opened.
-
SQL>
-
SQL>
-
SQL> alter database backup controlfile to trace;
-
-
Database altered.
-
- SQL>
3.查詢trace檔案路徑
trace檔案的路徑可以透過一個多表查詢來獲得,其中涉及v$processv、$sessionv和$mystat等三個動態檢視。點選(此處)摺疊或開啟
-
SQL>
-
SQL> select tracefile from v$process where addr in (select paddr from v$session where sid in (select sid from v$mystat));
-
-
TRACEFILE
-
--------------------------------------------------------------------------------
-
/u01/app/oracle/diag/rdbms/hoegh/HOEGH/trace/HOEGH_ora_4831.trc
-
- SQL>
4.檢視trace檔案
透過cat命令檢視trace檔案,內容如下:點選(此處)摺疊或開啟
-
Trace file /u01/app/oracle/diag/rdbms/hoegh/HOEGH/trace/HOEGH_ora_4831.trc
-
Oracle Database 11g Enterprise Edition Release 11.2.0.3.0 - Production
-
With the Partitioning, OLAP, Data Mining and Real Application Testing options
-
ORACLE_HOME = /u01/app/oracle/product/11.2.0/dbhome_1
-
System name: Linux
-
Node name: hoegh
-
Release: 2.6.18-164.el5PAE
-
Version: #1 SMP Thu Sep 3 02:28:20 EDT 2009
-
Machine: i686
-
VM name: VMWare Version: 6
-
Instance name: HOEGH
-
Redo thread mounted by this instance: 1
-
Oracle process number: 19
-
Unix process pid: 4831, image: oracle@hoegh (TNS V1-V3)
-
-
-
*** 2015-05-30 12:31:12.588
-
*** SESSION ID:(125.5) 2015-05-30 12:31:12.588
-
*** CLIENT ID:() 2015-05-30 12:31:12.588
-
*** SERVICE NAME:() 2015-05-30 12:31:12.588
-
*** MODULE NAME:(sqlplus@hoegh (TNS V1-V3)) 2015-05-30 12:31:12.588
-
*** ACTION NAME:() 2015-05-30 12:31:12.588
-
-
Successfully allocated 2 recovery slaves
-
Using 66 overflow buffers per recovery slave
-
Thread 1 checkpoint: logseq 7, block 2, scn 898139
-
cache-low rba: logseq 7, block 118
-
on-disk rba: logseq 7, block 143, scn 898639
-
start recovery at logseq 7, block 118, scn 0
-
-
*** 2015-05-30 12:31:12.690
-
Started writing zeroblks thread 1 seq 7 blocks 143-150
-
-
*** 2015-05-30 12:31:12.690
-
Completed writing zeroblks thread 1 seq 7
-
==== Redo read statistics for thread 1 ====
-
Total physical reads (from disk and memory): 4096Kb
-
-- Redo read_disk statistics --
-
Read rate (ASYNC): 12Kb in 0.08s => 0.15 Mb/sec
-
Longest record: 1Kb, moves: 0/51 (0%)
-
Change moves: 2/35 (5%), moved: 0Mb
-
Longest LWN: 4Kb, moves: 0/9 (0%), moved: 0Mb
-
Last redo scn: 0x0000.000db64e (898638)
-
----------------------------------------------
-
----- Recovery Hash Table Statistics ---------
-
Hash table buckets = 262144
-
Longest hash chain = 1
-
Average hash chain = 9/9 = 1.0
-
Max compares per lookup = 1
-
Avg compares per lookup = 29/75 = 0.4
-
----------------------------------------------
-
-
*** 2015-05-30 12:31:12.692
-
KCRA: start recovery claims for 9 data blocks
-
-
*** 2015-05-30 12:31:12.703
-
KCRA: blocks processed = 9/9, claimed = 9, eliminated = 0
-
-
*** 2015-05-30 12:31:12.704
-
Recovery of Online Redo Log: Thread 1 Group 1 Seq 7 Reading mem 0
-
-
*** 2015-05-30 12:31:12.704
-
Completed redo application of 0.00MB
-
-
*** 2015-05-30 12:31:12.709
-
Completed recovery checkpoint
-
----- Recovery Hash Table Statistics ---------
-
Hash table buckets = 262144
-
Longest hash chain = 1
-
Average hash chain = 9/9 = 1.0
-
Max compares per lookup = 1
-
Avg compares per lookup = 22/38 = 0.6
-
----------------------------------------------
-
Recovery sets nab of thread 1 seq 7 to 143 with 8 zeroblks
-
-
*** 2015-05-30 12:31:13.044
-
kwqmnich: current time:: 4: 31: 12: 0
-
kwqmnich: instance no 0 repartition flag 1
-
kwqmnich: initialized job cache structure
-
kwqinfy: Call kwqrNondurSubInstTsk
-
-
*** 2015-05-30 12:31:30.897
-
-- 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=\"HOEGH\"
-
--
-
-- 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=/u01/app/oracle/product/11.2.0/dbhome_1/dbs/arch\'
-
-- 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 \"HOEGH\" NORESETLOGS NOARCHIVELOG
-
MAXLOGFILES 16
-
MAXLOGMEMBERS 3
-
MAXDATAFILES 100
-
MAXINSTANCES 8
-
MAXLOGHISTORY 292
-
LOGFILE
-
GROUP 1 \'/u01/app/oracle/oradata/HOEGH/redo01.log\' SIZE 50M BLOCKSIZE 512,
-
GROUP 2 \'/u01/app/oracle/oradata/HOEGH/redo02.log\' SIZE 50M BLOCKSIZE 512,
-
GROUP 3 \'/u01/app/oracle/oradata/HOEGH/redo03.log\' SIZE 50M BLOCKSIZE 512
-
-- STANDBY LOGFILE
-
DATAFILE
-
\'/u01/app/oracle/oradata/HOEGH/system01.dbf\',
-
\'/u01/app/oracle/oradata/HOEGH/sysaux01.dbf\',
-
\'/u01/app/oracle/oradata/HOEGH/undotbs01.dbf\',
-
\'/u01/app/oracle/oradata/HOEGH/users01.dbf\',
-
\'/u01/app/oracle/oradata/HOEGH/example01.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/product/11.2.0/dbhome_1/dbs/arch1_1_762197622.dbf\';
-
-- ALTER DATABASE REGISTER LOGFILE \'/u01/app/oracle/product/11.2.0/dbhome_1/dbs/arch1_1_860888149.dbf\';
-
-- 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/HOEGH/temp01.dbf\'
-
SIZE 30408704 REUSE AUTOEXTEND ON NEXT 655360 MAXSIZE 32767M;
-
-- 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 \"HOEGH\" RESETLOGS NOARCHIVELOG
-
MAXLOGFILES 16
-
MAXLOGMEMBERS 3
-
MAXDATAFILES 100
-
MAXINSTANCES 8
-
MAXLOGHISTORY 292
-
LOGFILE
-
GROUP 1 \'/u01/app/oracle/oradata/HOEGH/redo01.log\' SIZE 50M BLOCKSIZE 512,
-
GROUP 2 \'/u01/app/oracle/oradata/HOEGH/redo02.log\' SIZE 50M BLOCKSIZE 512,
-
GROUP 3 \'/u01/app/oracle/oradata/HOEGH/redo03.log\' SIZE 50M BLOCKSIZE 512
-
-- STANDBY LOGFILE
-
DATAFILE
-
\'/u01/app/oracle/oradata/HOEGH/system01.dbf\',
-
\'/u01/app/oracle/oradata/HOEGH/sysaux01.dbf\',
-
\'/u01/app/oracle/oradata/HOEGH/undotbs01.dbf\',
-
\'/u01/app/oracle/oradata/HOEGH/users01.dbf\',
-
\'/u01/app/oracle/oradata/HOEGH/example01.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/product/11.2.0/dbhome_1/dbs/arch1_1_762197622.dbf\';
-
-- ALTER DATABASE REGISTER LOGFILE \'/u01/app/oracle/product/11.2.0/dbhome_1/dbs/arch1_1_860888149.dbf\';
-
-- 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/HOEGH/temp01.dbf\'
-
SIZE 30408704 REUSE AUTOEXTEND ON NEXT 655360 MAXSIZE 32767M;
-
-- End of tempfile additions.
5.NORESETLOGS VS RESETLOGS
從trace檔案可以看出,提供了兩個建立控制檔案的指令碼,分別針對兩種不同的應用場景:NORESETLOGS適用於當前redo log可用,而RESETLOGS適用於當前redo log不可用。
2.執行介質恢復RECOVER DATABASE
3.開啟資料庫ALTER DATABASE OPEN;
4.新增臨時表空間
2.執行介質恢復RECOVER DATABASE USING BACKUP CONTROLFILE
3.開啟資料庫ALTER DATABASE OPEN RESETLOGS;
4.新增臨時表空間
NORESETLOGS重建步驟
1.執行指令碼,重建控制檔案(CREATE CONTROLFILE REUSE DATABASE "HOEGH" NORESETLOGS NOARCHIVELOG......)2.執行介質恢復RECOVER DATABASE
3.開啟資料庫ALTER DATABASE OPEN;
4.新增臨時表空間
RESETLOGS重建步驟
1.執行指令碼,重建控制檔案(CREATE CONTROLFILE REUSE DATABASE "HOEGH" RESETLOGS NOARCHIVELOG......)2.執行介質恢復RECOVER DATABASE USING BACKUP CONTROLFILE
3.開啟資料庫ALTER DATABASE OPEN RESETLOGS;
4.新增臨時表空間
hoegh
15.05.30
-- The End --
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/30162081/viewspace-1678479/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- Oracle 11g 重新建立控制檔案Oracle
- Oracle 控制檔案Oracle
- oracle快速拿到重建控制檔案語句的方法二Oracle
- Controlfile 重建控制檔案 noresetlogs, resetlogs..
- ORACLE 控制檔案(Control Files)概述Oracle
- 【RMAN】Oracle中如何備份控制檔案?備份控制檔案的方式有哪幾種?Oracle
- oracle ORA-01189 ORA-01110(控制檔案建立報錯)Oracle
- Oracle 控制檔案損壞解決方案Oracle
- oracle 控制檔案及引數檔案何時自動備份Oracle
- windwos檔案控制代碼數限制
- 2.6.4 指定控制檔案
- oracle11g修改控制檔案路徑Oracle
- 如何在Shell指令碼中逐行讀取檔案指令碼
- shell指令碼技巧—建立和清空檔案指令碼
- 清除Oracle控制檔案中的歸檔資訊v$archived_logOracleHive
- 如何獲取 vue 單檔案自身原始碼路徑Vue原始碼
- Python 獲取檔案建立、訪問、修改時間Python
- 修改linux最大檔案控制程式碼數Linux
- 控制檔案損壞處理
- 【RMAN】如果控制檔案損壞那麼如何恢復?恢復控制檔案的方式有哪幾種?
- ajax上傳檔案,spring mvc獲取檔案並處理,通過頁面按鈕傳送url,由後臺控制檔案下載SpringMVC
- LIUNUX如何擷取txt檔案中的內容,並建立新檔案UX
- Oracle 密碼檔案Oracle密碼
- Powershell 如何批次獲取檔案大小的實現程式碼
- Oracle-無備份情況下,如何手動恢復控制檔案Oracle
- Java動態指令碼Groovy讀取配置檔案Java指令碼
- 【/proc/檔案淺析】另類辦法恢復資料檔案和控制檔案
- Bash 指令碼如何建立臨時檔案:mktemp 命令和 trap 命令教程指令碼
- 遞迴獲取檔案列表遞迴
- 把“點檔案”放到版本控制中
- Oracle:ASM & 密碼檔案OracleASM密碼
- Shell指令碼 | 抓取log檔案指令碼
- 如何獲取HDFS上檔案的儲存位置
- 重建共享(db或asm)密碼檔案 in Oracle 19c RAC-20220209ASM密碼Oracle
- 使用git不希望檔案被版本控制Git
- 與控制檔案有關的恢復
- 如何輕鬆歸檔檔案?2種方法輕鬆建立歸檔檔案!
- JavaScript獲取檔案字尾名JavaScript
- php獲取xml檔案內容PHPXML