在以前的文章《Oracle Restart啓動數據庫實例故障一例》(http://space.itpub.net/17203031/viewspace-774622)中,筆者解決了一個因爲使用create pfile from spfile引發的Restart沒法啓動數據庫實例的故障。linux
嚴格的說,筆者並無徹底將其解決。主要體如今Spfile的使用和存放上。sql
一、問題簡述數據庫
Oracle Database安裝在ASM存儲的時候,默認都是使用ASM保存Spfile參數文件。與早期的pfile文件不一樣,Spfile是具備二進制格式,可以支持部分參數的動態調整。網絡
因此,咱們出現問題的時候,發現Restart的配置信息中包括了ASM中的Spfile參數內容。oracle
[oracle@SimpleLinux ~]$ srvctl config database -d ora11gapp
Database unique name: ora11gide
Database name:spa
Oracle home: /u01/app/oracle/product/11.2.0/db_1.net
Oracle user: oracleip
Spfile: +DATA/ORA11G/spfileora11g.ora
Domain:
Start options: open
Stop options: immediate
Database role: PRIMARY
Management policy: AUTOMATIC
Database instance: ora11g
Disk Groups: DATA,RECO
Services:
咱們以前的修復方法,就是將spfile內容置空,讓數據庫實例啓動使用默認路徑$ORACLE_HOME/dbs的spfile和pfile參數進行檢索。
SQL> show parameter spfile
NAME TYPE VALUE
------------------------------------ ----------- ------------------------------
spfile string /u01/app/oracle/product/11.2.0
/db_1/dbs/spfileora11g.ora
可是此時,咱們在ASM路徑上是存在spfile上的。
ASMCMD> pwd
+DATA/ORA11G
ASMCMD> ls
CONTROLFILE/
DATAFILE/
ONLINELOG/
PARAMETERFILE/
TEMPFILE/
spfileora11g.ora
在這種狀況下,若是配置了ASM目錄的spfile啓動標誌,啓動Restart會報錯。
[oracle@SimpleLinux ~]$ srvctl modify database -d ora11g -p +DATA/ora11g/spfileora11g.ora
[oracle@SimpleLinux ~]$ srvctl start database -d ora11g
PRCR-1079 : Failed to start resource ora.ora11g.db
CRS-5010: Update of configuration file "/u01/app/oracle/product/11.2.0/db_1/dbs/initora11g.ora" failed: details at "(:CLSN00014:)" in "/u01/app/grid/product/11.2.0/grid/log/simplelinux/agent/ohasd/oraagent_grid/oraagent_grid.log"
CRS-5017: The resource action "ora.ora11g.db start" encountered the following error:
CRS-5010: Update of configuration file "/u01/app/oracle/product/11.2.0/db_1/dbs/initora11g.ora" failed: details at "(:CLSN00014:)" in "/u01/app/grid/product/11.2.0/grid/log/simplelinux/agent/ohasd/oraagent_grid/oraagent_grid.log"
. For details refer to "(:CLSN00107:)" in "/u01/app/grid/product/11.2.0/grid/log/simplelinux/agent/ohasd/oraagent_grid/oraagent_grid.log".
CRS-2674: Start of 'ora.ora11g.db' on 'simplelinux' failed
二、分析和思考
一塊兒冷靜想一想~
Pfile和spfile是參數文件經歷的兩個階段。在umount階段,Oracle是經過參數$ORACLE_HOME和$ORACLE_SID進行目錄定位,定位到$ORACLE_HOME/dbs或者$ORACLE_HOME/database,到裏面尋找制定規則的參數文件。
Oracle首先會去尋找Spfile,以後纔會去找Pfile。咱們經過create spfile和create pfile能夠實現二者的轉化。
一個比較常見的問題案例是:若是咱們把啓動參數改錯了,啓動不了了,那麼怎麼辦?標準的作法是經過create pfile from spfile,拿到一個文本格式的參數pfile。在裏面修改啓動參數,糾正錯誤。啓動時候,使用startup pfile=xxx使用「指定的pfile」啓動數據庫實例,再經過create spfile from pfile將變化固化下來。
Oracle Restart提供的配置參數spfile實際上是很詭異的。從直觀上看,好像是有startup數據庫實例,後面能夠本身去指定參數文件,相似於startup spfile=xxx的做用。可是實際上,startup是不支持spfile這樣的參數的。
若是這個參數是用於指定,那麼在Restart啓動的時候咱們已經設置爭取的spfile位置,指定位置上面也有文件。可是根本沒有效果,Oracle仍是尋找參數文件。
那麼,就只有一種可能性:即便Oracle使用Restart啓動,也不是依靠指定的spfile,仍是按照原有的規則運行。
網絡上有一種方法,說的是若是咱們須要指定一個spfile啓動文件的時候,應該怎麼作。答案是創建一個空的pfile文件,裏面直接指定SPFILE參數的文件位置。
綜合幾種思路,咱們能夠設想到Spfile保存在ASM裏面,同時讓Restart和sqlplus啓動時候能夠訪問到ASM Spfile的方法。
三、配置ASM上SPFILE啓動
首先是建立出ASM上的spfile。注意:建立spfile的時候必定是從pfile建立,因此須要轉換一下。
SQL> startup pfile=/u01/app/oracle/product/11.2.0/db_1/dbs/initora11g.ora
ORACLE instance started.
Total System Global Area 263639040 bytes
Fixed Size 1344312 bytes
Variable Size 134221000 bytes
Database Buffers 125829120 bytes
Redo Buffers 2244608 bytes
Database mounted.
Database opened.
SQL> show parameter spfile
NAME TYPE VALUE
------------------------------------ ----------- ------------------------------
spfile string
SQL> create spfile='+DATA/ORA11G/spfileora11g.ora' from pfile;
File created.
此時,咱們在ASM裏面能夠看到生成的spfile二進制文件。
ASMCMD> ls -l
Type Redund Striped Time Sys Name
Y CONTROLFILE/
Y DATAFILE/
Y ONLINELOG/
Y PARAMETERFILE/
Y TEMPFILE/
N spfileora11g.ora => +DATA/ORA11G/PARAMETERFILE/spfile.267.829130539
第二部是建立維護一個「轉發」參數文件。
SQL> shutdown immediate;
Database closed.
Database dismounted.
ORACLE instance shut down.
[oracle@SimpleLinux ~]$ cd $ORACLE_HOME
[oracle@SimpleLinux db_1]$ cd dbs
[oracle@SimpleLinux dbs]$ ls -l
total 28
-rw-rw---- 1 oracle asmadmin 1544 Sep 12 12:58 hc_ora11g.dat
-rw-r--r-- 1 oracle oinstall 2851 May 15 2009 init.ora
-rwxr-x--- 1 oracle oinstall 959 Oct 18 09:51 initora11g.ora
-rwxrwx--- 1 oracle oinstall 887 Sep 29 09:31 initora11g.ora.bk
-rw-r----- 1 oracle asmadmin 24 Sep 12 12:58 lkORA11G
-rw-r----- 1 oracle oinstall 1536 Sep 12 13:11 orapwora11g
-rw-r----- 1 oracle asmadmin 2560 Oct 18 09:57 spfileora11g.ora
在裏面要完成兩件事情,一個是將dbs目錄下面的spfile刪除。由於依據Oracle啓動的原則,是先找spfile,以後再找pfile。第二件是修改文本參數文件,做爲轉發。
[oracle@SimpleLinux dbs]$ mv spfileora11g.ora spfileora11g.ora.bk
[oracle@SimpleLinux dbs]$ cat initora11g.ora
SPFILE='+DATA/ora11g/spfileora11g.ora’ –注意:不能包括*前綴或者SID前綴
[oracle@SimpleLinux dbs]$ ls -l
total 28
-rw-rw---- 1 oracle asmadmin 1544 Sep 12 12:58 hc_ora11g.dat
-rw-r--r-- 1 oracle oinstall 2851 May 15 2009 init.ora
-rwxr-x--- 1 oracle oinstall 41 Oct 18 10:07 initora11g.ora
-rwxrwx--- 1 oracle oinstall 887 Sep 29 09:31 initora11g.ora.bk
-rw-r----- 1 oracle asmadmin 24 Sep 12 12:58 lkORA11G
-rw-r----- 1 oracle oinstall 1536 Sep 12 13:11 orapwora11g
-rw-r----- 1 oracle asmadmin 2560 Oct 18 09:57 spfileora11g.ora.bk
使用srvctl關閉和啓動數據庫。
[oracle@SimpleLinux dbs]$ srvctl start database -d ora11g
[oracle@SimpleLinux dbs]$ srvctl config database -d ora11g
Database unique name: ora11g
Database name:
Oracle home: /u01/app/oracle/product/11.2.0/db_1
Oracle user: oracle
Spfile: +DATA/ora11g/spfileora11g.ora
Domain:
Start options: open
Stop options: immediate
Database role: PRIMARY
Management policy: AUTOMATIC
Database instance: ora11g
Disk Groups: DATA,RECO
Services:
[oracle@SimpleLinux dbs]$ srvctl status database -d ora11g
Database is running.
數據庫中,spfile參數被設置爲ASM路徑。
SQL> show parameter spfile;
NAME TYPE VALUE
------------------------------------ ----------- ------------------------------
spfile string +DATA/ora11g/spfileora11g.ora
故障完全解決。
四、結論
綜合上面的實驗,咱們能夠看到ASM下Spfile使用的方法。ASM下的Spfile並非拋棄原有的啓動規則,而是藉助原有的pfile進行了目標轉接。以後筆者查看MOS中的對應方案,官方推薦的也是這樣的作法。
這樣就須要一個前提,就是dbs或者database目錄中不能包括spfile。若是包括了,Oracle設置的轉接機制就被替換掉了。
另外一個問題是咱們一直看到的錯誤提示信息,提示參數文件initora11g.ora格式不能識別。筆者的理解是,原始的文件是筆者使用create pfile from spfile建立出來的,默認的SPFILE=XXX的內容被覆蓋。而Oracle Restart不能識別這種非轉接內容文件,因此報錯。