當 Oracle 實例啟動時,它從初始化參數文件中讀取參數進行實例初始化,最小化初始化參數文件只需要指定參數 DB_NAME 的值,所有其他參數有默認值。
初始化參數文件可以是只讀(靜態)的文本文件 (pfile),或是讀/寫(動態)的二進制文件 (spfile),二進制參數文件被稱為服務器參數文件(Server Parameter File)。
pfile 可以用記事本進行直接修改,且必須重啟才能生效。spfile 須用 alter system 命令來進行修改,生效的時限和作用域由修改命令的參數 scope 來決定。
如:alter system set job_queue_processed=50 scope=memory;
SCOPE Clause |
Description |
SCOPE = SPFILE |
The change is applied in the server parameter file only. The effect is as follows:
This is the only SCOPE specification allowed for static parameters. |
SCOPE = MEMORY |
The change is applied in memory only. The effect is as follows:
For static parameters, this specification is not allowed. |
SCOPE = BOTH |
The change is applied in both the server parameter file and memory. The effect is as follows:
For static parameters, this specification is not allowed. |
實例啟動初始化參數文件查找順序:spfileORACLE_SID.ora -> spfile.ora -> initORACLE_SID.ora
可以通過 show parameter spfile 或者 select value from v$parameter where name = 'spfile' 命令查看服務器參數文件的位置,如果啟動用的是 pfile,則 spfile 值為空。
[oracle@rac1 dbs]$ ls -hl total 6.8M -rw-r----- 1 oracle oinstall 1.6K Aug 28 11:56 hc_byisdb.dat -rw-r----- 1 oracle oinstall 13K May 3 2001 initdw.ora -rw-r----- 1 oracle oinstall 8.2K Sep 11 1998 init.ora.bak -rw-r----- 1 oracle oinstall 24 Aug 28 11:58 lkBYISDB -rw-r----- 1 oracle oinstall 1.5K Sep 2 10:44 orapwbyisdb -rw-r----- 1 oracle oinstall 6.8M Aug 29 04:13 snapcf_byisdb.f -rw-r----- 1 oracle oinstall 3.5K Sep 5 10:11 spfilebyisdb.ora
當前只有服務器初始化參數文件 spfilebyisdb.ora,下面再生成兩個參數文件,一個是服務器參數文件 spfile.ora,另外一個是靜態參數文件 pfile, 看三個參數文件並存的時候,看實例啟動時優先使用哪個文件作為初始化參數文件?
SQL> create pfile from spfile 2 / File created. [oracle@rac1 dbs]$ cp spfilebyisdb.ora spfile.ora [oracle@rac1 dbs]$ ls -hl total 6.8M -rw-r----- 1 oracle oinstall 1.6K Aug 28 11:56 hc_byisdb.dat -rw-r--r-- 1 oracle oinstall 1.2K Sep 5 10:12 initbyisdb.ora -rw-r----- 1 oracle oinstall 13K May 3 2001 initdw.ora -rw-r----- 1 oracle oinstall 8.2K Sep 11 1998 init.ora.bak -rw-r----- 1 oracle oinstall 24 Aug 28 11:58 lkBYISDB -rw-r----- 1 oracle oinstall 1.5K Sep 2 10:44 orapwbyisdb -rw-r----- 1 oracle oinstall 6.8M Aug 29 04:13 snapcf_byisdb.f -rw-r----- 1 oracle oinstall 3.5K Sep 5 10:11 spfilebyisdb.ora -rw-r----- 1 oracle oinstall 3.5K Sep 5 10:16 spfile.ora
可以看到實例正常啟動,使用的初始化參數文件為 spfilebyisdb.ora。
SQL> shutdown immediate Database closed. Database dismounted. ORACLE instance shut down. SQL> startup ORACLE instance started. Total System Global Area 285212672 bytes Fixed Size 1218968 bytes Variable Size 79693416 bytes Database Buffers 197132288 bytes Redo Buffers 7168000 bytes Database mounted. Database opened. SQL> show parameter spfile NAME TYPE VALUE ------------------------------------ ----------- ------------------------------ spfile string /u01/app/oracle/product/10.2.0 /db_1/dbs/spfilebyisdb.ora SQL>
模仿spfilebyisdb.ora不存在,可以看到,實例正常啟動,使用的初始化參數文件為:spfile.ora
[oracle@rac1 dbs]$ mv spfilebyisdb.ora spfilebyisdb.ora.bak SQL> shutdown immediate Database closed. Database dismounted. ORACLE instance shut down. SQL> startup ORACLE instance started. Total System Global Area 285212672 bytes Fixed Size 1218968 bytes Variable Size 79693416 bytes Database Buffers 197132288 bytes Redo Buffers 7168000 bytes Database mounted. Database opened. SQL>show parameter spfile NAME TYPE VALUE ------------------------------------ ----------- ------------------------------ spfile string /u01/app/oracle/product/10.2.0 /db_1/dbs/spfile.ora SQL>
模仿spfile.ora也不存在,可以看到實例還是可以正常啟動,此時的參數 spfile 為空,表明沒有用到服務器參數文件,而是用到靜態參數文件 pfile 即 initbyisdb.ora。
[oracle@rac1 dbs]$ mv spfile.ora spfile.ora.bak SQL> shutdown immediate Database closed. Database dismounted. ORACLE instance shut down. SQL> startup ORACLE instance started. Total System Global Area 285212672 bytes Fixed Size 1218968 bytes Variable Size 79693416 bytes Database Buffers 197132288 bytes Redo Buffers 7168000 bytes Database mounted. Database opened. SQL> show parameter spfile NAME TYPE VALUE ------------------------------------ ----------- ------------------------------ spfile string
模仿initbyisdb.ora參數文件也不存在,只剩下它的副本init.ora文件。
[oracle@rac1 dbs]$ cp initbyisdb.ora init.ora [oracle@rac1 dbs]$ mv initbyisdb.ora initbyisdb.ora.bak [oracle@rac1 dbs]$ ls -hl total 6.9M -rw-r----- 1 oracle oinstall 1.6K Aug 28 11:56 hc_byisdb.dat -rw-r--r-- 1 oracle oinstall 1.2K Sep 5 10:12 initbyisdb.ora.bak -rw-r----- 1 oracle oinstall 13K May 3 2001 initdw.ora -rw-r--r-- 1 oracle oinstall 1.2K Sep 5 10:31 init.ora -rw-r----- 1 oracle oinstall 8.2K Sep 11 1998 init.ora.bak -rw-r----- 1 oracle oinstall 24 Aug 28 11:58 lkBYISDB -rw-r----- 1 oracle oinstall 1.5K Sep 2 10:44 orapwbyisdb -rw-r----- 1 oracle oinstall 6.8M Aug 29 04:13 snapcf_byisdb.f -rw-r----- 1 oracle oinstall 3.5K Sep 5 10:21 spfilebyisdb.ora.bak -rw-r----- 1 oracle oinstall 3.5K Sep 5 10:24 spfile.ora.bak SQL> shutdown immediate Database closed. Database dismounted. ORACLE instance shut down. SQL> startup ORA-01078: failure in processing system parameters LRM-00109: could not open parameter file '/u01/app/oracle/product/10.2.0/db_1/dbs/initbyisdb.ora' SQL>
此時只保留了靜態參數文件 pfile 的副本 init.ora,重啟實例報錯,說明最后找的參數文件為 initbyisdb.ora,即 initORACLE_SID.ora,這個跟 Oracle 聯機文檔描述的相吻合。在網上看到說當前面三個參數文件不存在的時候,最后會找 init.ora 參數文件,所以就動手試驗了一下,得出結論是不會找 init.ora 參數文件。
Oracle 聯機文檔描述:
In the platform-specific default location, Oracle Database locates your initialization parameter file by examining file names in the following order:
spfile
ORACLE_SID
.ora
spfile.ora
init
ORACLE_SID
.ora