oracle三个重要参数文件:pfile和spfile和init.ora

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

 

 

posted @ 2022-03-14 16:12  jinzi  阅读(7651)  评论(0编辑  收藏  举报