控制文件(control file)是一個(gè)相當(dāng)小的文件(最多能增長(zhǎng)到64M左右),其中包含Oracle需要的其他文件的一個(gè)目錄。參數(shù)文件告知實(shí)例控制文件的位置,控制文件則告知示例數(shù)據(jù)庫(kù)和在線重做日志文件的位置??刂莆募€告知了Oracle其他一些事情,如已發(fā)生檢查點(diǎn)的有關(guān)信息、數(shù)據(jù)庫(kù)名(必須和db_name參數(shù)匹配)、創(chuàng)建數(shù)據(jù)庫(kù)的時(shí)間戳、歸檔重做日志的歷史(有時(shí)這會(huì)讓控制文件變大)、RMAN信息等。
控制文件應(yīng)該通過(guò)硬件(RAID)多路保存,如果不支持鏡像,則要通過(guò)Oracle多路保存。應(yīng)該有不止一個(gè)副本,而且它們應(yīng)該保存在不同的磁盤(pán)上,以防止萬(wàn)一出現(xiàn)磁盤(pán)故障而丟失控制文件。丟失控制文件并不是致命的,但是會(huì)使恢復(fù)變得困難很多。
如果丟失了所有的控制文件并且沒(méi)有任何的備份,我們可以通過(guò)重建控制文件來(lái)打開(kāi)數(shù)據(jù)庫(kù)。其中,重建控制文件至少需要以下信息:
1.數(shù)據(jù)庫(kù)名
2.字符集
3.數(shù)據(jù)文件名稱
4.初始化參數(shù),包括MAXLOGFILES、MAXLOGMEMBERS、MAXDATAFILES、MAXINSTANCES、MAXLOGHISTORY等;
創(chuàng)新互聯(lián)成都網(wǎng)站建設(shè)按需網(wǎng)站開(kāi)發(fā),是成都網(wǎng)站維護(hù)公司,為成都玻璃貼膜提供網(wǎng)站建設(shè)服務(wù),有成熟的網(wǎng)站定制合作流程,提供網(wǎng)站定制設(shè)計(jì)服務(wù):原型圖制作、網(wǎng)站創(chuàng)意設(shè)計(jì)、前端HTML5制作、后臺(tái)程序開(kāi)發(fā)等。成都網(wǎng)站營(yíng)銷(xiāo)推廣熱線:18982081108
我們?cè)贠racle11g中進(jìn)行測(cè)試。
點(diǎn)擊( 此處 )折疊或打開(kāi)
SQL
>
SQL > select * from v$version ;
BANNER
--------------------------------------------------------------------------------
Oracle Database 11g Enterprise Edition Release 11 . 2 . . 3 . 0 - Production
PL / SQL Release 11 . 2 . . 3 . 0 - Production
CORE 11 . 2 . . 3 . 0 Production
TNS for Linux : Version 11 . 2 . . 3 . 0 - Production
NLSRTL Version 11 . 2 . . 3 . 0 - Production
SQL >
1.通過(guò)查詢control_files初始化參數(shù),獲取控制文件路徑;
點(diǎn)擊( 此處 )折疊或打開(kāi)
SQL
>
SQL > show parameter control_files
NAME TYPE VALUE
------------------------------------ ----------- ------------------------------
control_files string / u01 / app / oracle / oradata / HOEGH /
control01 . ctl , / u01 / app / oracle
/ oradata / HOEGH / control02 . ctl
SQL >
2.然后,使用rm命令刪除控制文件;
點(diǎn)擊( 此處 )折疊或打開(kāi)
[
oracle
@
HOEGH
~
]
$
rm
/
u01
/
app
/
oracle
/
oradata
/
HOEGH
/
control01
.
ctl
[ oracle @ HOEGH ~ ] $ rm / u01 / app / oracle / oradata / HOEGH / control02 . ctl
[ oracle @ HOEGH ~ ] $
3.此時(shí),強(qiáng)制關(guān)閉數(shù)據(jù)庫(kù),然后重啟數(shù)據(jù)庫(kù),報(bào)ORA-00205錯(cuò)誤。需要注意的是,此時(shí)執(zhí)行shutdown immediate命令,數(shù)據(jù)庫(kù)無(wú)法正常關(guān)閉,只能關(guān)閉到mounted狀態(tài);需要使用shutdown abort命令強(qiáng)制關(guān)閉數(shù)據(jù)庫(kù)。
點(diǎn)擊( 此處 )折疊或打開(kāi)
SQL
>
SQL > shutdown immediate
Database closed .
ORA - 00210 : cannot open the specified control file
ORA - 00202 : control file : \ '/u01/app/oracle/oradata/HOEGH/control01.ctl\'
ORA - 27041 : unable to open file
Linux Error : 2 : No such file or directory
Additional information : 3
SQL > select status from v$instance ;
STATUS
------------
MOUNTED
SQL >
SQL > shutdown abort
ORACLE instance shut down .
SQL >
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
ORA - 00205 : error in identifying control file , check alert log for more info
SQL >
首先生成文本格式的參數(shù)文件;
點(diǎn)擊( 此處 )折疊或打開(kāi)
SQL
>
SQL > create pfile from spfile ;
File created .
SQL >
打開(kāi)參數(shù)文件,查看db_name參數(shù)值,即為數(shù)據(jù)庫(kù)名稱。
點(diǎn)擊( 此處 )折疊或打開(kāi)
[
oracle
@
hoegh dbs
]
$
cat initHOEGH
.
ora
HOEGH . __db_cache_size = 419430400
HOEGH . __java_pool_size = 4194304
HOEGH . __large_pool_size = 4194304
HOEGH . __oracle_base = \ '/u01/app/oracle\' # ORACLE_BASE set from environment
HOEGH . __pga_aggregate_target = 377487360
HOEGH . __sga_target = 566231040
HOEGH . __shared_io_pool_size =
HOEGH . __shared_pool_size = 130023424
HOEGH . __streams_pool_size =
* . audit_file_dest = \ '/u01/app/oracle/admin/HOEGH/adump\'
* . audit_trail = \ 'db\'
* . compatible = \ '11.2.0.0.0\'
* . control_files = \ '/u01/app/oracle/oradata/HOEGH/control01.ctl\' , \ '/u01/app/oracle/oradata/HOEGH/control02.ctl\'
* . db_block_size = 8192
* . db_domain = \ '\'
* . db_name = \ 'HOEGH\'
* . diagnostic_dest = \ '/u01/app/oracle\'
* . dispatchers = \ '(PROTOCOL=TCP) (SERVICE=HOEGHXDB)\'
* . memory_max_target = 943718400
* . memory_target = 943718400
* . open_cursors = 300
* . processes = 150
* . remote_login_passwordfile = \ 'EXCLUSIVE\'
* . undo_tablespace = \ 'UNDOTBS1\'
[ oracle @ hoegh dbs ] $
由于需要執(zhí)行查詢語(yǔ)句select userenv('language') from dual;來(lái)獲取字符集,因此需要將數(shù)據(jù)庫(kù)啟動(dòng)到nomount狀態(tài)。
點(diǎn)擊( 此處 )折疊或打開(kāi)
SQL
>
SQL > startup nomount
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
SQL >
SQL > select userenv ( \ 'language\' ) from dual ;
USERENV ( \ 'LANGUAGE\' )
----------------------------------------------------
AMERICAN_AMERICA . US7ASCII
SQL >
SQL >
通過(guò)ls命令獲取數(shù)據(jù)文件列表。
點(diǎn)擊( 此處 )折疊或打開(kāi)
[
oracle
@
hoegh HOEGH
]
$
ls
-
lh
total 1 . 8G
- rw - r ----- 1 oracle oinstall 314M May 30 11:07 example01.dbf
- rw - r ----- 1 oracle oinstall 51M May 30 11:07 redo01.log
- rw - r ----- 1 oracle oinstall 51M May 30 11:07 redo02.log
- rw - r ----- 1 oracle oinstall 51M May 30 11:07 redo03.log
- rw - r ----- 1 oracle oinstall 541M May 30 11:07 sysaux01.dbf
- rw - r ----- 1 oracle oinstall 721M May 30 11:07 system01.dbf
- rw - r ----- 1 oracle oinstall 30M Oct 13 2014 temp01.dbf
- rw - r ----- 1 oracle oinstall 96M May 30 11:07 undotbs01.dbf
- rw - r ----- 1 oracle oinstall 5.1M May 30 11:07 users01.dbf
[ oracle @ hoegh HOEGH ] $
這樣,創(chuàng)建控制文件所需的基本信息都已經(jīng)有了,我們來(lái)生成創(chuàng)建控制文件腳本。
點(diǎn)擊( 此處 )折疊或打開(kāi)
STARTUP
NOMOUNT
CREATE CONTROLFILE REUSE DATABASE \ "HOEGH\" NORESETLOGS ARCHIVELOG
MAXLOGFILES 5
MAXLOGMEMBERS 3
MAXDATAFILES 100
MAXINSTANCES 1
MAXLOGHISTORY 226
LOGFILE
GROUP 1 \ '/u01/app/oracle/oradata/HOEGH/redo01.log\' SIZE 50M ,
GROUP 2 \ '/u01/app/oracle/oradata/HOEGH/redo02.log\' SIZE 50M ,
GROUP 3 \ '/u01/app/oracle/oradata/HOEGH/redo03.log\' SIZE 50M
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\' ,
\ '/u01/app/oracle/oradata/HOEGH/temp01.dbf\'
CHARACTER SET US7ASCII
;
需要注意的是,在執(zhí)行上述創(chuàng)建腳本時(shí)會(huì)報(bào)錯(cuò),系統(tǒng)提示臨時(shí)文件不屬于數(shù)據(jù)文件,如下所示:
點(diǎn)擊( 此處 )折疊或打開(kāi)
SQL
>
@
/
u01
/
app
/
oracle
/
oradata
/
HOEGH
/
CreateControlFile
.
sql
ORA - 01081 : cannot start already - running ORACLE - shut it down first
CREATE CONTROLFILE REUSE DATABASE \ "HOEGH\" NORESETLOGS ARCHIVELOG
*
ERROR at line 1 :
ORA - 01503 : CREATE CONTROLFILE failed
ORA - 01160 : file is not a data file
ORA - 01110 : data file : \ '/u01/app/oracle/oradata/HOEGH/temp01.dbf\'
SQL >
修改腳本并重新執(zhí)行,重建控制文件后,數(shù)據(jù)庫(kù)會(huì)打開(kāi)到mount狀態(tài)。
點(diǎn)擊( 此處 )折疊或打開(kāi)
SQL
>
SQL > @ / u01 / app / oracle / oradata / HOEGH / CreateControlFile . sql
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
Control file created .
SQL >
SQL > select status from v$instance ;
STATUS
------------
MOUNTED
SQL >
在打開(kāi)數(shù)據(jù)庫(kù)時(shí),會(huì)報(bào)錯(cuò),提示system01數(shù)據(jù)文件需要執(zhí)行介質(zhì)恢復(fù),我們執(zhí)行recover database即可。
點(diǎn)擊( 此處 )折疊或打開(kāi)
SQL
>
SQL > alater database open ;
SP2 - 0734 : unknown command beginning \ "alater dat...\" - rest of line ignored .
SQL >
SQL > alter database open ;
alter database open
*
ERROR at line 1 :
ORA - 01113 : file 1 needs media recovery
ORA - 01110 : data file 1 : \ '/u01/app/oracle/oradata/HOEGH/system01.dbf\'
SQL >
SQL > recover database ;
Media recovery complete .
SQL >
SQL > alter database open ;
Database altered .
SQL >
SQL > select * from v$version ;
BANNER
--------------------------------------------------------------------------------
Oracle Database 11g Enterprise Edition Release 11 . 2 . . 3 . 0 - Production
PL / SQL Release 11 . 2 . . 3 . 0 - Production
CORE 11 . 2 . . 3 . 0 Production
TNS for Linux : Version 11 . 2 . . 3 . 0 - Production
NLSRTL Version 11 . 2 . . 3 . 0 - Production
SQL >
SQL> select tablespace_name from dba_tablespaces;
TABLESPACE_NAME
------------------------------
SYSTEM
SYSAUX
UNDOTBS1
TEMP
USERS
EXAMPLE
6 rows selected.
SQL>
下面總結(jié)一下重建控制文件的步驟:
1.獲取數(shù)據(jù)庫(kù)名;
2.獲取字符集名;
3.獲取數(shù)據(jù)文件名;
4.重建控制文件;
5.執(zhí)行介質(zhì)恢復(fù);
6.打開(kāi)數(shù)據(jù)庫(kù)。
hoegh
15.05.30
-- The End --
來(lái)自 “ ITPUB博客 ” ,鏈接:http://blog.itpub.net/30162081/viewspace-1677995/,如需轉(zhuǎn)載,請(qǐng)注明出處,否則將追究法律責(zé)任。