Sunteți pe pagina 1din 9

Title Using SPFILE and INIT.

ORA

Author Petra Knöbl (petra.knoebel@trivadis.com)

Info Technical Background Info (March 2002)

Source Trivadis NF9I Course and NF9i Techno Circle

Introduction

Oracle9i allows more and more parameters to be changed on-the-fly without having to
restart the database. Consequently, the DBA has to remember, more and more often, to
change the parameter file accordingly before the next restart of the database. Oracle9i
enables dynamically altered parameters to be simultaneously written to the parameter file
using server parameter files (SPFILE) so that changes are consistent with ALTER SYSTEM.

SPFILE and INIT.ORA


Up to version 8i, Oracle traditionally stored initialization parameters in a text file
INIT.ORA (PFILE). With Oracle9i, server parameter files (SPFILE) can also be used. An
SPFILE can be regarded as a repository for initialization parameters which is located on the
database server.

SPFILEs are small binary files that cannot be edited. Editing SPFILEs corrupts the file and
either the instance fails to start or an active instance may crash.

^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^G^@^@^@^@^B...
@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@
*.db_block_size=8192
*.db_domain='ttc.trivadis.com'
*.db_file_multiblock_read_count=16
*.db_files=1022
*.db_name='TVD901A'
...
*. means: all instances of this database system. This is also valid syntax in conventional
INIT.ORA files. This is particularly interesting for Real Application Cluster (RAC) – see
below for more information.

At database startup, if no PFILE is specified at the OS-dependent default location


($ORACLE_HOME/dbs under UNIX, $ORACLE_HOME\database under NT), the startup
command searches for:
1. spfile${ORACLE_SID}.ora
2. spfile.ora
3. init${ORACLE_SID}.ora
Of course, the option of explicitly specifying a PFILE is still available.
SQL> connect sys/manager as sysdba
Connected to an idle instance.
SQL> startup pfile=/u00/app/oracle/admin/TVD901A/pfile/initTVD901A.ora
ORACLE instance started.

Total System Global Area 172967504 bytes


...
SQL>

However, a SPFILE cannot be specified for STARTUP with PFILE :


SQL> startup pfile='/u00/app/oracle/admin/TVD901A/pfile/spfileTVD901A.ora'
LRM-00101: unknown parameter name 's044'
ORA-01078: failure in processing system parameters

To facilitate this, the best option is to create a conventional INIT.ORA with default name:
Š init${ORACLE_SID}.ora
This file only contains the path of the SPFILE:
SPFILE = c:\oracle\admin\db1\pfile\spfileDB1.ora

Create SPFILE

A SPFILE is initially created from a conventional text initialization parameters file (PFILE,
INIT.ORA). This can be carried out without a started instance. SYSDBA or SYSOPER
privileges are required to create the SPFILE.

If SPFILE is available at the default location, STARTUP uses this SPFILE if no PFILE is
specified.
Creating an SPFILE from a PFILE at the default location:
SQL> CREATE SPFILE
2 FROM PFILE='/u00/app/oracle/admin/TVD901A/pfile/initTVD901A.ora';
File created.
SQL>

Creating an SPFILE from a PFILE at the non-default location:


SQL> CREATE SPFILE='/u00/app/oracle/admin/TVD901A/pfile/spfileTVD901A.ora'
2 FROM PFILE='/u00/app/oracle/admin/TVD901A/pfile/initTVD901A.ora';
File created.
SQL>

Oracle recommends using the default location (eases administration-). Trivadis


recommends storing parameter files outside the software directory (OFA).

The best solution is to create a (conventional) INIT.ORA with default name in the default
location, which contains only the path to the SPFILE (see above).

Working with links, if necessary, on UNIX:


sqlplus "/ as sysdba"
startup
create spfile='/u00/app/oracle/admin/TDBT901A/pfile/spfileTVD901A.ora' from
pfile='/u00/app/oracle/admin/SID/pfile/initTVD901A.ora';
shutdown immediate
exit
cd $ORACLE_HOME/dbs
ln -s /u00/app/oracle/admin/TDBT901A/pfile/spfileTVD901A.ora .
sqlplus "/ as sysdba"
startup

Backing up an SPFILE

The CREATE PFILE command can be used to back up an SPFILE:


SQL> CREATE PFILE='/u00/app/oracle/admin/TVD901A/pfile/bck_init.ora'
2 FROM SPFILE;
File created.
SQL>

This creates a directly usable INIT.ORA file:


*.background_dump_dest='/u00/app/oracle/admin/TVD901A/bdump'
*.compatible='9.0.1'
*.control_file_record_keep_time=90
*.core_dump_dest='/u00/app/oracle/admin/TVD901A/cdump'

It is definitely a good idea to always keep a PFILE as a backup of an SPFILE so that a new
SPFILE can be created from the PFILE in the “worst case scenario”. The creation of a PFILE
backup copy from an SPFILE can be automated in the nightly backup job or in a STARTUP
trigger, for example:

SQL> CREATE OR REPLACE TRIGGER copy_spfile


2 AFTER STARTUP ON DATABASE
3 DECLARE
4 cPath CONSTANT varchar2(80) := 'D:\oracle\admin\DB9\pfile';
5 BEGIN
6 EXECUTE IMMEDIATE
7 'create pfile='''||cPath||'\initora.'||
8 TO_CHAR(SYSDATE,'yyyymmdd_hh24mi')||''' from spfile';
9 EXCEPTION
10 WHEN others THEN NULL;
11 END;
12 /
Trigger created.
SQL>

Changes in the SPFILE

There are two options for implementing changes in the SPFILE:


1. Using the ALTER SYSTEM command
2. Using the export method
1. Changes using ALTER SYSTEM

The prerequisite is that an SPFILE was used at instance STARTUP, either directly or by an
INIT.ORA which contains the SPFILE=spfile${ORACLE_SID}.ora parameter.
When using SPFILEs, the ALTER SYSTEM command can be used to consistently change
parameters in the SPFILE (which was used at startup), if desired.

A SCOPE can be specified with ALTER SYSTEM:


Š MEMORY (default, if a conventional INIT.ORA was used at STARTUP)

Š SPFILE

Š BOTH (default if an SPFILE was used at STARTUP)


SQL> CONNECT / AS SYSDBA
Connected.
SQL> ALTER SYSTEM SET shared_pool_size = 48M SCOPE=BOTH;
System altered.
SQL>

Only the SCOPE=SPFILE can be used for static parameters. The change becomes effective
at the next STARTUP:
SQL> CONNECT / AS SYSDBA
Connected.
SQL> ALTER SYSTEM SET db_block_buffers = 20000 SCOPE=SPFILE;
System altered.
SQL>

Comments can be specified for changes, which can then be viewed both in the SPFILE and
in the attribute UPDATE_COMMENT of V$PARAMETER and V$SPPARAMETER.
SQL> ALTER SYSTEM SET timed_statistics=TRUE
2 COMMENT='DB-Review by Trivadis' SCOPE=BOTH;
System altered.
SQL>

Parameters can be deleted from the SPFILE as follows:


SQL> ALTER SYSTEM RESET sort_area_size SCOPE=SPFILE SID='*';
System altered.
SQL>
This does not work for multi-line parameters. (Only the first line is deleted and the
instance then no longer starts!) In a case like this, the parameter must first be set to ’’ and
then deleted.

Complex parameters can be specified as follows:


SQL> ALTER SYSTEM SET
2 log_archive_dest_3='LOCATION=/u01/oracle/arc',MANDATORY,'REOPEN=2'
3 COMMENT='Added 3rd destination 23.06.2001' SCOPE=SPFILE;
System altered.
SQL>

Undocumented parameters can be similarly set:


SQL> ALTER SYSTEM SET "_collect_undo_stats"=FALSE SCOPE=SPFILE;
System altered.
SQL>

2. Export method

The content of the SPFILE must be imported to a PFILE:


SQL> CREATE PFILE='initDB1test.ora' FROM SPFILE;
File created.
SQL>

Now the parameter values can be changed in the PFILE.


Then the SPFILE must be recreated by the altered ‘initDB1test.ora’ PFILE:
SQL> CREATE SPFILE 'spfileDB1.ora'
2 FROM PFILE='initDB1test.ora';
File created.
SQL>

Was an SPFILE used at STARTUP and, if so, which one?

The V$PARAMETER view displays whether an SPFILE was used at STARTUP, and if so,
which one:
SQL> select name, value from v$parameter where name='spfile'
NAME VALUE
--------------- ----------------------------------------
spfile C:\oracle\admin\db9\pfile\spfiledb9.ora
SQL>

The SPFILE parameter is displayed in the alert${ORACLE_SID}.log file if the instance was
started with an init${ORACLE_SID}.ora file, which refers to an SPFILE. If the SPFILE
parameter is not displayed in the alert${ORACLE_SID}.log file, either a default SPFILE or
PFILE (conventional INIT.ORA) was used at STARTUP.

Under NT, it must be taken into account that an automatic database start with the
ORA_<sidname>_AUTOSTART=TRUE and ORA_<sidname>_PFILE=<full path to the
PFILE> registry entries corresponds to a STARTUP PFILE=xxx at the command level. The
SPFILE is not used if the database is started automatically. If the database is now started
from the command line and if an SPFILE exists, other parameters may have been included
when starting the database.
This can be avoided by deleting the registry entry or by creating an INIT.ORA which only
contains the PATH to the SPFILE.
Displaying parameters

Parameters can be displayed with:


Š OEM (Oracle Enterprise Manager)

Š SHOW PARAMETER in SQL*Plus

Š CREATE PFILE=

Š display SPFILE directly (but do not change...)

Š V$PARAMETER(2): current parameters

Š V$SPPARAMETER: parameters in the SPFILE


Trivadis script (ssinipar.sql), which can be downloaded from www.trivadis.com (together
with our other freeware scripts which have been migrated to Oracle9i) is available to
determine the parameters (including the undocumented ones).

OEM Support

OEM supports SPFILEs and PFILEs.


Shared SPFILEs

An SPFILE can be used for several instances with RAC (Real Application Cluster, formerly
Oracle Parallel Server). The SPFILE is stored on a raw device for this purpose.
Instance-specific parameters are specified with the instance name as prefix:
prod1.instance_name = 'PROD1'
prod2.instance_name = 'PROD2'
*.db_name = 'PROD'
prod1.sort_area_size = 1048576
prod2.sort_area_size = 524288

Conclusion

Consistent changes can now be implemented without vi, Notepad, etc. Furthermore, now
by using an SPFILE within the database, it is possible to establish which parameter file was
used at STARTUP.
SPFILE usage is already supported in OEM. Another positive feature is the option of being
able to use a single SPFILE for RAC.
The only danger with the SPFILE is the possibility of confusing which file was used at
database STARTUP.
It would be desirable for the DBA to have a trigger that would go off at ALTER SYSTEM so
that a history of the changes to the system could be tracked.
If you would like to know more about the new features of Oracle9i, we would be happy to
welcome you to one of our Oracle9i courses (NF9i, AI9-A and AI9-B).

Petra Knöbl

Trivadis AG e-mail: petra.knoebl@trivadis.com


Cityforum im Eichsfeld Tel: ++49 6142 210 18 0
Ferdinand-Stuttmann-Str. 13 Fax: ++49 6142 210 18 29
D-65428 Rüsselsheim Internet: http://www.trivadis.com

S-ar putea să vă placă și