Initialization Parameter files: PFILEs vs. SPFILEs

本文为转载:

网址:http://www.orafaq.com/node/5

      http://www.cnblogs.com/jacktu/archive/2008/02/27/1083232.html

声明:如果本文侵犯了您的权益,请及时告知,本人将即刻停止侵权行为.

针对Oracle数据库熊,分为

单实例体系结构:关系型数据库管理系统-RDBMS(relational database management system)

分布式系统体系结构:具有代表性的是实时应用集群-RAC(Real Application Cluster) ,多个实例打开一个数据库.

名词解释:OEM-Oracle Enterprise Manager

Oracle控制器中的网址:EM-Enterprise Manager.

---------------------------------------------------------

When an Oracle Instance is started, the characteristics of the Instance are established by parameters specified within the initialization parameter file. These initialization parameters are either stored in a PFILE or SPFILE. SPFILEs are available in Oracle 9i and above. All prior releases of Oracle are using PFILEs.

SPFILEs provide the following advantages over PFILEs:

  • An SPFILE can be backed-up with RMAN (RMAN cannot backup PFILEs)
  • Reduce human errors. The SPFILE is maintained by the server. Parameters are checked before changes are accepted.:减少人为的损坏
  • Eliminate configuration problems (no need to have a local PFILE if you want to start Oracle from a remote machine)消除了配置问题
  • Easy to find - stored in a central location,更容易查找:
    1 SELECT * FROM v$parameter t WHERE t.name LIKE 'pfile%';
    2 --
    3 Show/sho Parameter pfile

What is the difference between a PFILE and SPFILE:

A PFILE is a static, client-side text file that must be updated with a standard text editor like "notepad" or "vi". This file normally reside on the server, however, you need a local copy if you want to start Oracle from a remote machine. DBA's commonly refer to this file as the INIT.ORA file.

An SPFILE (Server Parameter File), on the other hand, is a persistent server-side binary file that can only be modified with the "ALTER SYSTEM SET" command. (Spfile文件是一个持久化的服务端的二进制文件。只可以通过ALTER SYSTEM SET来进行修改,)This means you no longer need a local copy of the pfile to start the database from a remote machine. Editing an SPFILE will corrupt it, and you will not be able to start your database anymore.(当修改了Spfile文件,将破坏了它,将不可以启动数据库。)

How will I know if my database is using a PFILE or SPFILE:

查看系统是以pfile还是spfile启动

Execute the following query to see if your database was started with a PFILE or SPFILE:

SQL> SELECT DECODE(value, NULL, 'PFILE', 'SPFILE') "Init File Type" 
       FROM sys.v_$parameter WHERE name = 'spfile';

   也可以通过:

     

1 Select isspecified,count(*) from v$spparameter group by isspecified;

 如果isspecified(默认值)里有true,表明用spfile进行了指定配置
 如果全为false,则表明用pfile启动

You can also use the V$SPPARAMETER view to check if you are using a PFILE or not: if the "value" column is NULL for all parameters, you are using a PFILE.

Viewing Parameters Settings:

One can view parameter values using one of the following methods (regardless if they were set via PFILE or SPFILE):

Sfile相关的视图:

  • The "SHOW PARAMETERS" command from SQL*Plus (i.e.: SHOW PARAMETERS timed_statistics)
  • V$PARAMETER view - display the currently in effect parameter values
  • V$PARAMETER2 view - display the currently in effect parameter values, but "List Values" are shown in multiple rows
  • V$SPPARAMETER view - display the current contents of the server parameter file.
  • 各个参数默认值的视图:v$parameter_valid_values
    他介绍了各个参数的默认值的情况,以及当年的默认值。

Starting a database with a PFILE or SPFILE:

Oracle searches for a suitable initialization parameter file in the following order:

  • Try to use the spfile${ORACLE_SID}.ora file in $ORACLE_HOME/dbs (Unix) or ORACLE_HOME/database (Windows)
  • Try to use the spfile.ora file in $ORACLE_HOME/dbs (Unix) or ORACLE_HOME/database (Windows)
  • Try to use the init${ORACLE_SID}.ora file in $ORACLE_HOME/dbs (Unix) or ORACLE_HOME/database (Windows)

One can override the default location by specifying the PFILE parameter at database startup:

SQL> STARTUP PFILE='/oradata/spfileORCL.ora'

Note that there is not an equivalent "STARTUP SPFILE=" command. One can only use the above option with SPFILE's if the PFILE you point to (in the example above), contains a single 'SPFILE=' parameter pointing to the SPFILE that should be used. Example:

SPFILE=/path/to/spfile

Changing SPFILE parameter values:

While a PFILE can be edited with any text editor, the SPFILE is a binary file. The "ALTER SYSTEM SET" and "ALTER SYSTEM RESET" commands can be used to change parameter values in an SPFILE. Look at these examples:

SQL> ALTER SYSTEM SET open_cursors=300 SCOPE=SPFILE;

SQL> ALTER SYSTEM SET timed_statistics=TRUE
	COMMENT='Changed by Frank on 1 June 2003'
	SCOPE=BOTH
 	SID='*';

The SCOPE parameter can be set to SPFILE, MEMORY or BOTH:

- MEMORY: Set for the current instance only. This is the default behaviour if a PFILE was used at STARTUP.

- SPFILE: update the SPFILE, the parameter will take effect with next database startup

- BOTH: affect the current instance and persist to the SPFILE. This is the default behaviour if an SPFILE was used at STARTUP.
The COMMENT parameter (optional) specifies a user remark.

The SID parameter (optional; only used with RAC) indicates the instance for which the parameter applies (Default is *: all Instances).

Use the following syntax to set parameters that take multiple (a list of) values:

SQL> ALTER SYSTEM SET utl_file_dir='/tmp/','/oradata','/home/' SCOPE=SPFILE;

Use this syntax to set unsupported initialization parameters (obviously only when Oracle Support instructs you to set it):

SQL> ALTER SYSTEM SET "_allow_read_only_corruption"=TRUE SCOPE=SPFILE;

Execute one of the following command to remove a parameter from the SPFILE:

SQL> ALTER SYSTEM RESET timed_statistics SCOPE=SPFILE SID=‘*’;
SQL> ALTER SYSTEM SET timed_statistics = '' SCOPE=SPFILE;

Converting between PFILES and SPFILES:

One can easily migrate from a PFILE to SPFILE or vice versa. Execute the following commands from a user with SYSDBA or SYSOPER privileges:

SQL> CREATE PFILE FROM SPFILE; 
SQL> CREATE SPFILE FROM PFILE;

One can also specify a non-default location for either (or both) the PFILE and SPFILE parameters. Look at this example:

SQL> CREATE SPFILE='/oradata/spfileORCL.ora' from PFILE='/oradata/initORCL.ora';

Here is an alternative procedure for changing SPFILE parameter values using the above method:

  • Export the SPFILE with: CREATE PFILE=‘pfilename’ FROM SPFILE = ‘spfilename’;
  • Edit the resulting PFILE with a text editor
  • Shutdown and startup the database with the PFILE option: STARTUP PFILE=filename
  • Recreate the SPFILE with: CREATE SPFILE=‘spfilename’ FROM PFILE=‘pfilename’;
  • On the next startup, use STARTUP without the PFILE parameter and the new SPFILE will be used.

Parameter File Backups:

RMAN (Oracle's Recovery Manager) will backup the SPFILE with the database control file if setting "CONFIGURE CONTROLFILE AUTOBACKUP" is ON (the default is OFF). PFILEs cannot be backed-up with RMAN. Look at this example:

RMAN> CONFIGURE CONTROLFILE AUTOBACKUP ON;

Use the following RMAN command to restore an SPFILE:

RMAN> RESTORE CONTROLFILE FROM AUTOBACKUP;

--------END

原文地址:https://www.cnblogs.com/caroline/p/2548751.html