ORACLE database startup parameter files pfile and spfile (transfer)

 

Turn one:

First, explain that the SID is the instance ID of the Oracle database, which is used to uniquely identify an instance (usually an Oracle database). 
1. The pfile file is the startup parameter file before Oracle8i (it can also be found in 9i, 10g, and 11g after that). It exists in the form of text,
     and the parameters can be modified with the vi editor. The file format is init.ora or initSID.ora; 
     the file location is: there is an init.ora.xxxxxxxxxxx file in the 10.0.2\admin\instance name\pfile\ folder, and the following xxxxxxxxxxx is the timestamp.
2, spfile is used in versions after Oracle9i and exists in binary text, and
   the parameters cannot be modified with vi editor.
   The file format is spfileSID.ora (spfile.ora is a parameter file common to all instances).
    (1) If you want to modify the spfile file, you can use the SQL language when the database is running: 
  SQL> ALTER SYSTEM SET PARAMETER = 'VALUES'; to modify. 
  ALTER SYSTEM also has options: SCOPE. The SCOPE parameter has three optional values: MEMORY , SPFILE , BOTH
  MEMORY: only change the current instance running
  SPFILE: only change the setting of SPFILE
  BOTH: after changing the instance and SPFILE
     using spfile, all parameter changes can be written to the spfile (as long as the scope is defined =spfile or both):
      SQL> ALTER SYSTEM SET PARAMETER = 'VALUES' SCOPE=SPFILE; 
  (2) If it is inconvenient to use SQL statements to operate spfile, you can first pass SQL statements: 
  SQL> CREATE Spfile FROM pfile; This method converts spfile in binary text form Convert it to pfile format in text form, and then use the vi editor to modify the parameters intuitively to achieve the purpose of convenience.
      After the modification is completed, the pfile format in text form can be converted back to spfile in binary text form through a statement:
  SQL> CREATE pfile FROM Spfile; 
      (3) Spfile corrects the problem of pfile management confusion. In a multi-node environment, pfile There will be multiple images, and the latest image needs to be tracked at startup. spfile guarantees that each server startup is consistent, pfile may cause inconsistent startup. Because pfile can be started on the client side.
3. spfile can dynamically modify parameters when the database is running, some do not need to restart the database, and special ones need to be restarted to take effect.
However, pfile cannot dynamically modify database parameters. After text editing, the database must be restarted
4. The search order at startup is:
spfile.ora > spfile.ora > init.ora (that is, spfile takes precedence over pfile, and this instance setting takes precedence over global setting )
can also specify which file to use at startup: 
SQL>startup pfile='Your_Pfile.ora'
SQL>startup spfile='\product\11.1.0\db_1\database\SPFILE_SINKA.ORA' force

Turn two:

Before 9i, Oracle used pfile to store initialization parameter configuration. These parameters were read when the instance was started. Any modification needs to restart the instance to take effect; using spfile you can use ALTER SYSTEM or ALTER SESSION to dynamically modify those parameters that can be modified dynamically , any changes take effect immediately, and you can choose whether to apply the changes only to the current instance or to the spfile at the same time. This allows any modification of spfile to be done on the command line, and we can completely say goodbye to manually modifying the initialization parameter document, which greatly reduces the occurrence of human errors.
SPFILE is a binary file that can be backed up with RMAN, so that Oracle actually includes the parameter file into the backup and recovery management.
In addition to the need for a PFILE to start the database for the first time (and then to be able to create an SPFILE based on the PFILE), we can no longer need a PFILE, and ORACLE strongly recommends using the spfile to apply its new features to store and maintain the initialization parameter configuration.

一. 创建SPFILE
缺省的,ORACLE 使用PFILE 启动数据库,SPFILE 必须由PFILE 创建,新创建的SPFILE在下一次启动数据库时生效,CREATE SPFILE 需要SYSDBA 或SYSOPER 的权限:
语法如下:
CREATE SPFILE[=’SPFILE-NAME’] FROM PFILE[=’PFILE-NAME’]
例:
SQL> create spfile from pfile;
缺省的,spfile 创建到系统缺省目录
(Unix: $ORACLE_HOME/dbs; NT: $ORACLE_HOME\database)
假如SPFILE 已存在,那么创建会返回以下错误:
SQL> create spfile from pfile;
create spfile from pfile
*
ERROR 位于第1 行:
ORA-32002: 无法创建已由例程使用的SPFILE,这也能够用来判断当前是否使用了SPFILE 文档。
然而意外的时,Oracle 并没有向其他文档相同,在运行期间保持锁定,让我们作以下试验:
SQL> host rename SPFILEEYGLEN.ORA SPFILEEYGLEN.ORA.BAK
SQL> alter system set db_cache_size=24M scope=both;
系统已更改。
SQL> host dir *.ora
驱动器E 中的卷是Doc
卷的序列号是980C-8EFF
E:\Oracle\Ora9iR2\database 的目录
2003-02-10 14:35 2,048 PWDeyglen.ORA
1 个文档2,048 字节
0 个目录150,347,776 可用字节
SQL> alter system set db_cache_size=24M scope=spfile;
alter system set db_cache_size=24M scope=spfile
*
ERROR 位于第1 行:
ORA-27041: 无法打开文档
OSD-04002: 无法打开文档
O/S-Error: (OS 2) 系统很难找到指定的文档。
SQL> host rename SPFILEEYGLEN.ORA.BAK SPFILEEYGLEN.ORA
SQL> alter system set db_cache_size=24M scope=spfile;
系统已更改。
SQL>
估计Oracle 以后会想办法来锁定这个文档。

二. 使用SPFILE
重新启动数据库,使用startup 命令,Oralce 将会按照以下顺序在缺省目录中搜索参数文档:
a. spfile${ORACLE_SID}.ora
缺省目录UNIX: ${ORACLE_HOME}/dbs/
NT: ${ORACLE_HOME}\database
b. spfile.ora
缺省目录UNIX: ${ORACLE_HOME}/dbs/
NT: ${ORACLE_HOME}\database
c. init${ORACLESID}.ora
缺省目录UNIX: ${ORACLE_HOME}/dbs/
NT: ${ORACLE_HOME}\database or
${ORACLE_HOME}\admin\db_name\pfile\
创建了spfile,重新启动数据库,Oracle 会按顺序搜索以上目录,spfile 就会自动生效。

三. 使用pfile/spfile 启动数据库
假如您想使用pfile 启动数据库,您能够在启动时指定pfile 或删除spfile.
SQL> startup pfile='E:\Oracle\admin\eyglen\pfile\init.ora';
您不能以同样的方式指定spfile,但是能够创建一个包含spfile 参数的pfile 文档,指向spfile.
SPFILE 是个自Oracle9i 引入的初始化参数,类似于IFILE 参数。SPFILE 参数用于定义非缺省路径的spfile 文档。
您能够在PFILE 链接到SPFILE 文档,同时在PFILE 中定义其他参数,假如参数重复配置,后读取的参数将取代先前的配置。
PFILE 参数的使用,例如:
这是我们使用SPFILE 启动的榭觯?br> SQL> startup
ORACLE 例程已启动。
Total System Global Area 135338868 bytes
Fixed Size 453492 bytes
Variable Size 109051904 bytes
Database Buffers 25165824 bytes
Redo Buffers 667648 bytes
数据库装载完毕。
数据库已打开。
SQL> show parameter log_archive_start
NAME TYPE
------------------------------------ ----------------------
VALUE
------------------------------
log_archive_start boolean
TRUE
SQL> show parameter spfile
NAME TYPE
------------------------------------ ----------------------
VALUE
------------------------------
spfile string
%ORACLE_HOME%\DATABASE\SPFILE%ORACLE_SID%.ORA
SQL>
我们修改PFILE 文档内容如下:
#Pfile link to SPFILE
SPFILE= 'E:\Oracle\Ora9iR2\database\SPFILEEYGLEN.ORA'
log_archive_start = false
能够预见这个log_archive_start 参数配置将会代替SPFILE 中的配置:
SQL> startup pfile='e:\initeyglen.ora'
ORACLE 例程已启动。
Total System Global Area 135338868 bytes
Fixed Size 453492 bytes
Variable Size 109051904 bytes
Database Buffers 25165824 bytes
Redo Buffers 667648 bytes
数据库装载完毕。
数据库已打开。
SQL> show parameter spfile
NAME TYPE
------------------------------------ ----------------------
VALUE
------------------------------
spfile string
E:\Oracle\Ora9iR2\database\SPFILEEYGLEN.ORA
SQL> show parameter log_archive_start
NAME TYPE
------------------------------------ ----------------------
VALUE
------------------------------
log_archive_start boolean
FALSE
然后我们能够使用ALTER SYSTEM 方式将修改固定到SPFILE.
SQL> alter system set log_archive_start=false scope=spfile;
系统已更改。
所以您也能够通过如上方式在启动时修改初始化参数。比我们在本文最后介绍的导入导出方法要简便的多。

四. 修改参数
能够通过ALTER SYSTEM 或导入导出来更改SPFILE 的内容。
ALTER SYSTEM 增加了一个新选项:SCOPE。SCOPE 参数有三个可选值:
MEMORY ,SPFILE , BOTH
MEMORY:只改变当前实例运行
SPFILE:只改变SPFILE 的配置
BOTH:改变实例及SPFILE
1. SCOPE=MEMORY
SQL> show parameter timed_statistics
NAME TYPE
------------------------------------ ----------------------
VALUE
------------------------------
timed_statistics boolean
TRUE
SQL> ALTER SYSTEM SET timed_statistics=FALSE SCOPE=MEMORY;
系统已更改。
SQL> show parameter timed_statistics
NAME TYPE
------------------------------------ ----------------------
VALUE
------------------------------
timed_statistics boolean
FALSE
SQL> shutdown immediate
数据库已关闭。
已卸载数据库。
ORACLE 例程已关闭。
SQL> startup
ORACLE 例程已启动。
Total System Global Area 135338868 bytes
Fixed Size 453492 bytes
Variable Size 109051904 bytes
Database Buffers 25165824 bytes
Redo Buffers 667648 bytes
数据库装载完毕。
数据库已打开。
SQL> show parameter timed_statistics
NAME TYPE
------------------------------------ ----------------------
VALUE
------------------------------
timed_statistics boolean
TRUE
2. SCOPE=SPFILE
SQL> show parameter timed_statistics
NAME TYPE
------------------------------------ ----------------------
VALUE
------------------------------
timed_statistics boolean
TRUE
SQL> ALTER SYSTEM SET timed_statistics=FALSE SCOPE=SPFILE;
系统已更改。
SQL> show parameter timed_statistics
NAME TYPE
------------------------------------ ----------------------
VALUE
------------------------------
timed_statistics boolean
TRUE
SQL> shutdown immediate
数据库已关闭。
已卸载数据库。
ORACLE 例程已关闭。
SQL> startup
ORACLE 例程已启动。
Total System Global Area 135338868 bytes
Fixed Size 453492 bytes
Variable Size 109051904 bytes
Database Buffers 25165824 bytes
Redo Buffers 667648 bytes
数据库装载完毕。
数据库已打开。
SQL> show parameter timed_statistics
NAME TYPE
------------------------------------ ----------------------
VALUE
------------------------------
timed_statistics boolean
FALSE
SQL>
3. SCOPE = BOTH
使用BOTH 选项实际上等同于不带参数的ALTER SYSTEM 语句。
注意:假如修改静态参数,那么需要指定SPFILE 参数,否则将会报错。
SQL> show parameter timed_statistics
NAME TYPE
------------------------------------ ----------------------
VALUE
------------------------------
timed_statistics boolean
FALSE
SQL> ALTER SYSTEM SET timed_statistics=TRUE SCOPE=BOTH;
系统已更改。
SQL> show parameter timed_statistics
NAME TYPE
------------------------------------ ----------------------
VALUE
------------------------------
timed_statistics boolean
TRUE
SQL> shutdown immediate
数据库已关闭。
已卸载数据库。
ORACLE 例程已关闭。
SQL> startup
ORACLE 例程已启动。
Total System Global Area 135338868 bytes
Fixed Size 453492 bytes
Variable Size 109051904 bytes
Database Buffers 25165824 bytes
Redo Buffers 667648 bytes
数据库装载完毕。
数据库已打开。
SQL> show parameter timed_statistics
NAME TYPE
------------------------------------ ----------------------
VALUE
------------------------------
timed_statistics boolean
TRUE
SQL> ALTER SYSTEM SET sql_trace=FALSE SCOPE=BOTH;
ALTER SYSTEM SET sql_trace=FALSE SCOPE=BOTH
*
ERROR 位于第1 行:
ORA-02095: 无法修改指定的初始化参数
SQL> ALTER SYSTEM SET sql_trace=FALSE SCOPE=SPFILE;
系统已更改。
4.您也能够在数据库shutdown 时创建和修改spfile,例如:
SQL> show sga
Total System Global Area 135338868 bytes
Fixed Size 453492 bytes
Variable Size 109051904 bytes
Database Buffers 25165824 bytes
Redo Buffers 667648 bytes
SQL> shutdown immediate
数据库已关闭。
已卸载数据库。
ORACLE 例程已关闭。
SQL> create pfile from spfile;
文档已创建。
SQL> create spfile from pfile;
文档已创建。
SQL>

五. 是否使用了spfile
判断是否使用了SPFILE,能够使用以下方法:
1.查询v$parameter 动态视图,假如以下查询返回空值,那么您在使用pfile.
SQL> SELECT name,value FROM v$parameter WHERE name='spfile';
NAME
------------------------------------------------------------------
VALUE
------------------------------------------------------------------
spfile
%ORACLE_HOME%\DATABASE\SPFILE%ORACLE_SID%.ORA
2.或您能够使用SHOW 命令来显示参数配置,假如以下结果value 列返回空值,那么说明您在使用pfile:
SQL> SHOW PARAMETER spfile
NAME TYPE
------------------------------------ ----------------------
VALUE
------------------------------
spfile string
%ORACLE_HOME%\DATABASE\SPFILE%ORACLE_SID%.ORA
3.查询v$spparameter 视图
假如以下查询返回0 值,表示您在使用pfile,否则表明您使用的是spfile:
SQL> SELECT COUNT(*) FROM v$spparameter WHERE value IS NOT NULL;
COUNT(*)

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326314672&siteId=291194637