Oracle中的參數文件是一個包含一系列參數以及參數對應值的操作系統文件。它們是在數據庫實例啟動第一個階段時候加載的,
決定了數據庫的物理 結構、內存、數據庫的限制及系統大量的默認值、數據庫的各種物理屬性、指定數據庫控制文件名和路徑等信息,
是進行數據庫設計和性能調優的重要文件。可以分為兩種類型,3個文件:
(關於實例和service 請參考 https://www.cnblogs.com/aozhejin/p/15991629.html)
1、pfile: 初始化參數文件(Initialization Parameters Files)
pfile是啥呢,pfile的全名就是parameter file,參數文件。
pfile是一個可編輯的文本文件,主要內容就是數據庫的配置參數,包括內存配置、數據庫名、sessions、processes等。
pfile默認路徑(windows):/u01/app/oracle/product/11.2.0/db1_s/dbs/initSID.ora
Oracle 9i之前,ORACLE一直采用pfile方式存儲初始化參數,
pfile 默認的名稱為“init+實例sid.ora”文件路徑:/u01/app/oracle/product/11.2.0/db1_s/dbs
這是一個文本文件,可以用任何文本編輯工具打開。
我們可以直接使用 指定pfile文件啟動第一階段數據庫
sql>startup pfile=/u01/app/oracle/product/11.2.0/db1_s/dbs/init.ora.10152018183435 //通過這個指定這個參數文件就可以啟動這個數據庫了
2、spfile:服務器參數文件(Server Parameter Files)
從Oracle 9i開始,Oracle引入了Spfile文件,spfile 默認的名稱為“spfile+例程名.ora”文件路徑:/u01/app/oracle/product/11.2.0/db_1/dbs/
spfile以后,數據庫默認就是讀取spfile的配置啟動和初始化參數 ,加載參數到內存中
以二進制文本形式存在,不能用vi編輯器對其中參數進行修改,只能通過SQL命令在線修改。
我們在創建oracle的數據庫的時候,可以通過模版文件生成spfile文件.
創建服務器參數文件(spfile),指定 init$ORACLE_SID.ora
sql> create spfile from pfile='/u01/app/oracle/product/11.2.0/db_1/dbs/initfp.ora';
File created.
//生成的spfile名稱為 spfile$ORACLE_SID.spfile 即spfilefp.spfile
Oracle 9i以前,Oracle是經過pfile啟動和初始化數據庫。在9i以后,默認經過加載spfile來啟動和初始化數據庫。
3、怎么查看數據庫是經過spfile啟動的仍是pfile
在SQL命令窗口,輸入show parameter spfile,若是結果顯示spfile的文件路徑,即為經過spfile啟動的,若是沒有,就是pfile。
//我這里是采樣的,oracle集群的
SQL> show parameter spfile
NAME TYPE VALUE
------------------------------------ ----------- ------------------------------
spfile string +DATA/hty/parameterfile/spfilehty.ora //文件放在了asm磁盤上,也可以不放在asm上
4、init.ora: 是pfile文件的例子,可設置,可不設置
[oracle@sh02 db_1]$ cat /u01/app/oracle/product/11.2.0/db_1/dbs/init.ora # # $Header: rdbms/admin/init.ora /main/23 2009/05/15 13:35:38 ysarig Exp $ # # Copyright (c) 1991, 1997, 1998 by Oracle Corporation # NAME # init.ora # FUNCTION # NOTES # MODIFIED # ysarig 05/14/09 - Updating compatible to 11.2 # ysarig 08/13/07 - Fixing the sample for 11g # atsukerm 08/06/98 - fix for 8.1. # hpiao 06/05/97 - fix for 803 # glavash 05/12/97 - add oracle_trace_enable comment # hpiao 04/22/97 - remove ifile=, events=, etc. # alingelb 09/19/94 - remove vms-specific stuff # dpawson 07/07/93 - add more comments regarded archive start # maporter 10/29/92 - Add vms_sga_use_gblpagfile=TRUE # jloaiza 03/07/92 - change ALPHA to BETA # danderso 02/26/92 - change db_block_cache_protect to _db_block_cache_p # ghallmar 02/03/92 - db_directory -> db_domain # maporter 01/12/92 - merge changes from branch 1.8.308.1 # maporter 12/21/91 - bug 76493: Add control_files parameter # wbridge 12/03/91 - use of %c in archive format is discouraged # ghallmar 12/02/91 - add global_names=true, db_directory=us.acme.com # thayes 11/27/91 - Change default for cache_clone # jloaiza 08/13/91 - merge changes from branch 1.7.100.1 # jloaiza 07/31/91 - add debug stuff # rlim 04/29/91 - removal of char_is_varchar2 # Bridge 03/12/91 - log_allocation no longer exists # Wijaya 02/05/91 - remove obsolete parameters # ############################################################################## # Example INIT.ORA file # # This file is provided by Oracle Corporation to help you start by providing # a starting point to customize your RDBMS installation for your site. # # NOTE: The values that are used in this file are only intended to be used # as a starting point. You may want to adjust/tune those values to your # specific hardware and needs. You may also consider using Database # Configuration Assistant tool (DBCA) to create INIT file and to size your # initial set of tablespaces based on the user input. ############################################################################### # Change '<ORACLE_BASE>' to point to the oracle base (the one you specify at # install time) db_name='ORCL' memory_target=1G processes = 150 audit_file_dest='<ORACLE_BASE>/admin/orcl/adump' audit_trail ='db' db_block_size=8192 db_domain='' db_recovery_file_dest='<ORACLE_BASE>/flash_recovery_area' db_recovery_file_dest_size=2G diagnostic_dest='<ORACLE_BASE>' dispatchers='(PROTOCOL=TCP) (SERVICE=ORCLXDB)' open_cursors=300 remote_login_passwordfile='EXCLUSIVE' undo_tablespace='UNDOTBS1' # You may want to ensure that control files are created on separate physical # devices control_files = (ora_control1, ora_control2) compatible ='11.2.0'
參考: https://www.cnblogs.com/aozhejin/p/16008873.html
關於啟動文件查找順序問題。
用startup(默認)啟動的順序,oracle分為三個階段啟動,在第一個階段使用這個參數文件即
pfile為文本文件,可以用文本編輯器編輯,需要手工維護。
spfile為二進制文件,不能直接編輯,由實例維護
1、startup啟動數據庫
[oracle@sh02 dbs]$ echo $ORACLE_HOME /u01/app/oracle/product/11.2.0/db_1
//那么默認路徑就是:/u01/app/oracle/product/11.2.0/db_1/dbs/
2、直接startup(當你使用進入數據庫,要啟動時)
[oracle@sh02 dbs]$ echo $ORACLE_HOME
/u01/app/oracle/product/11.2.0/db_1
[oracle@sh02 dbs]$ sqlplus / as sysdba
SQL*Plus: Release 11.2.0.4.0 Production on Tue Mar 15 17:01:33 2022
Copyright (c) 1982, 2013, Oracle. All rights reserved.
Connected to:
Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit Production
With the Partitioning, Real Application Clusters, Automatic Storage Management, OLAP,
Data Mining and Real Application Testing options
SQL>startup //后面不加任何參數啟動,這個時候回車,下面就是查找順序
1、直接在默認路徑下查找spfileSID.ora --(spfile) 如果沒有再查找 spfile.ora 2、直接在默認路徑下查找spfile.ora 如果沒有再查找initSID.ora 3、直接在默認路徑下查找initSID.ora --(pfile) 如果還沒有 就會報錯…… 你也可以直接使用startup pfile="文件路徑"的方式啟動。
3、指定的pfile啟動: SQL>startup pfile=$ORACLE_HOME/dbs/initSID.ora 4、使用spfile啟動,編輯一下pfile文件example.ora SQL>spfile=$ORACLE_HOME/dbs/spfileSID.ora 再用startup pfile=$ORACLE_HOME/dbs/example.ora啟動即可。
5、先用命令創建一個spfile
sql> create spfile from pfile='/u01/app/oracle/product/11.2.0/db_1/dbs/initfp.ora';
File created.
sql> startup
這里說下Oracle啟動時的三個階段
1、nomount(數據庫未裝載)
SQL> startup nomount; ORACLE instance started. Total System Global Area 167387136 bytes Fixed Size 1343668 bytes Variable Size 150998860 bytes Database Buffers 12582912 bytes Redo Buffers 2461696 bytes
2、mount(數據庫完成裝載)
SQL> startup mount; ORACLE instance started. Total System Global Area 167387136 bytes Fixed Size 1343668 bytes Variable Size 150998860 bytes Database Buffers 12582912 bytes Redo Buffers 2461696 bytes Database mounted.
3、open(數據庫打開)
SQL> startup open ORACLE instance started. Total System Global Area 167387136 bytes Fixed Size 1343668 bytes Variable Size 150998860 bytes Database Buffers 12582912 bytes Redo Buffers 2461696 bytes Database mounted. Database opened.
Oracle打開數據文件和重做日志文件,才能對外(所有有效用戶)提供數據庫服務。
第一個階段就是nomount階段,這個階段做了以下幾個步驟:
1、在安裝默認路徑上搜索spfile,如果沒有找到的話,就讀取pfile。
2、讀取文件中的參數來確定初始化參數的值。根據參數值來分配SGA。
3、然后開啟Oracle的后台進程。打開alert log和trace file,根據合理的語法,顯示地將參數設定值寫入到alert log中。
其中第一步參數文件的搜索順序是: spfile<sid>.ora==>spfile.ora==>init<sid>.ora 也就是說首先會搜索本地的spfile<sid>.ora文件,如果沒有的話,搜索本地的spfile.ora,如果還沒有的話,就搜索init<sid>.ora文件。
需要注意的是,如果是Oracle RAC的話,只會搜索本地的參數文件,不會去搜索asm中的參數文件. 在單機的情況下,這個順序是沒有問題的,但是在RAC的情況下,spfile是要放在asm中的,也就是說要讀取asm中的spfile。
要實現這一目的,就要在init<sid>.ora文件中配置spfile的路徑,事實上在剛剛搭建完Oraclel 11g RAC的時候,init<sid>.ora的內容如下所示,
並且在$ORACLE_HOME/dbs下也沒有spfile<sid>.ora和spfile.ora文件。這樣就能保證讀取的是asm中的參數文件了。
查看spfile.ora位置(spfile.ora每個實例必然要存在)
[oracle@shf02 ~]$ echo $ORACLE_SID htstandby2 [oracle@shfp02 ~]$ sqlplus / as sysdba SQL*Plus: Release 11.2.0.4.0 Production on Tue Mar 15 14:13:03 2022 Copyright (c) 1982, 2013, Oracle. All rights reserved. Connected to: Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit Production With the Partitioning, Real Application Clusters, Automatic Storage Management, OLAP, Data Mining and Real Application Testing options
方法一 SQL> SELECT NAME, VALUE, DISPLAY_VALUE FROM V$PARAMETER WHERE NAME ='spfile'; NAME -------------------------------------------------------------------------------- VALUE -------------------------------------------------------------------------------- DISPLAY_VALUE -------------------------------------------------------------------------------- spfile +DATA/hty/parameterfile/spfilehty.ora //存放位置是在asm中 +DATA/hty/parameterfile/spfilehty.ora
方法二
SQL> Show parameter spfile
NAME TYPE VALUE
------------------------------------ ----------- ------------------------------
spfile string +DATA/hty/parameterfile/spfilehty.ora ##spfile+實例名.ora