|
|
This is the simplest form of the CREATE SPFILE statement. It creates a spfile in the default directory (O/S dependant, usually $ORACLE_HOME/dbs/ on unix platforms) from the pfile located in the default directory. The file is named spfile$ORACLE_SID.ora. If a spfile already exists in the destination directory, it is over written, however if it's in use by the instance, then it returns the following error:SQL> CREATE SPFILE FROM PFILE;
The following CREATE SPFILE creates a spfile in a non-default location from a pfile located in a non-default location; if the path in the SPFILE or PFILE clause is not specified, Oracle uses the default directory as the path.SQL> CREATE SPFILE FROM PFILE; CREATE SPFILE FROM PFILE * ERROR at line 1: ORA-32002: cannot create SPFILE already being used by the instance
SQL> CREATE SPFILE='d:\spfile_mydb.ora' FROM 2 PFILE='d:\oemrep\admin\initOEMREP.ora';
Bug: After an spfile is created when
you shutdown the database to startup again, you'll encounter an error,
which makes you log in again and then use the STARTUP command. Look at the
test scenario below:
Version: This bug exists inSQL> CREATE SPFILE='d:\spfile_mydb.ora' FROM 2 PFILE='d:\oemrep\admin\initOEMREP.ora'; File created. SQL> shutdown immediate; Database closed. Database dismounted. ORACLE instance shut down. SQL> startup ORA-03113: end-of-file on communication channel Oracle9i Enterprise Edition Release 9.0.1.1.1 - Production version.Workaround: All you have to do is reconnect as SYSDBA and use the STARTUP command, until a patch is available. |
You cannot start the database by specifying spfile in place of pfile in the previous command - Oracle does not allow this. Optionally, you can create a pfile containing SPFILE parameter in it that will be pointing to the location of the spfile as explained below.SQL> startup pfile='d:\spfile_mydb.ora';
A new initialization parameter called the SPFILE was introduced in Oracle9i. This is similar to the IFILE parameter that is used as a pointer to a non-default pfile. The SPFILE parameter is used to specify the path of spfile located in a non-default location. This is useful when your spfile is not located in the default location. This can also be used in conjunction with other parameters in the pfile, i.e. you may specify the location of the spfile and add some more parameters to the pfile. However, the pfile is read sequentially; if you duplicate a parameter in the spfile and the pfile, then the parameter value that is read last will take precedence over others. Look at the following scenario:
You set timed_statistics=true in the pfile and timed_statistics=false in the spfile
Now if you specify the SPFILE parameter at the beginning of the pfile, then TIMED_STATISTICS=FALSE is read first from the spfile and later it goes on reading the TIMED_STATISTICS=TRUE specified in the pfile which takes precedence.#Contents of the pfile SPFILE='d:\oemrep\admin\initOEMREP.ora' TIMED_STATISTICS=TRUE
The ALTER SYSTEM statement has a new option called the SCOPE, which can have three values, which are explained below.
SQL> SHOW PARAMETER timed_statistics NAME TYPE VALUE ------------------------------------ ----------- --------- timed_statistics boolean FALSE SQL> ALTER SYSTEM SET timed_statistics=TRUE SCOPE=MEMORY; System altered. SQL> SHOW PARAMETER timed_statistics NAME TYPE VALUE ------------------------------------ ----------- --------- timed_statistics boolean TRUE SQL> startup FORCE ORACLE instance started. Total System Global Area 63729356 bytes Fixed Size 282316 bytes Variable Size 46137344 bytes Database Buffers 16777216 bytes Redo Buffers 532480 bytes Database mounted. Database opened. SQL> SHOW PARAMETER timed_statistics NAME TYPE VALUE ------------------------------------ ----------- --------- timed_statistics boolean FALSE
SQL> SHOW PARAMETER timed_statistics NAME TYPE VALUE ------------------------------------ ----------- --------- timed_statistics boolean FALSE SQL> ALTER SYSTEM SET timed_statistics=TRUE SCOPE=SPFILE; System altered. SQL> SHOW PARAMETER timed_statistics NAME TYPE VALUE ------------------------------------ ----------- --------- timed_statistics boolean FALSE SQL> STARTUP FORCE ORACLE instance started. Total System Global Area 63729356 bytes Fixed Size 282316 bytes Variable Size 46137344 bytes Database Buffers 16777216 bytes Redo Buffers 532480 bytes Database mounted. Database opened. SQL> SHOW PARAMETER timed_statistics NAME TYPE VALUE ------------------------------------ ----------- --------- timed_statistics boolean TRUE
SQL> SHOW PARAMETER audit_trail
NAME TYPE VALUE
------------------------------------ ----------- ---------------
audit_trail string NONE
SQL> ALTER SYSTEM SET audit_trail=DB SCOPE=BOTH;
ALTER SYSTEM SET audit_trail=DB SCOPE=BOTH
*
ERROR at line 1:
ORA-02095: specified initialization parameter cannot be modified
SQL> ALTER SYSTEM SET audit_trail=DB SCOPE=SPFILE;
System altered.
SQL> ALTER SYSTEM SET timed_statistics=FALSE SCOPE=SPFILE; System altered. SQL> SELECT name, value FROM v$parameter 2 WHERE name='timed_statistics'; NAME VALUE -------------------- --------------------- timed_statistics TRUE SQL> SELECT name, value FROM v$spparameter 2 WHERE name='timed_statistics'; NAME VALUE -------------------- --------------------- timed_statistics FALSE
Alternatively, use the following query, which returns NULL in the value column if you are using pfile and not spfile:SQL> SELECT name, value FROM v$parameter 2 WHERE name = 'spfile'; NAME VALUE ---------- -------------------------------------------------- spfile %ORACLE_HOME%\DATABASE\SPFILE%ORACLE_SID%.ORA
On the other hand, you may check for the count of the following query; if the count is non-zero then the instance is using a spfile, and if the count is zero then it is using a pfile:SQL> SHOW PARAMETER spfile NAME TYPE VALUE ------- ------- ------------------------------ spfile string %ORACLE_HOME%\DATABASE\SPFILE%ORACLE_SID%.ORA
SQL> SELECT COUNT(*) FROM v$spparameter WHERE value IS NOT NULL;
The pfile is created at the path specified in the PFILE option. Now you edit the pfile as you wish and start the database using this file.SQL> CREATE PFILE='d:\init.ora' FROM SPFILE; File created. SQL> SHUTDOWN; Database closed. Database dismounted. ORACLE instance shut down.
Create the new spfile from the pfile (it is created in the default location).SQL> STARTUP PFILE='d:\init.ora' ORACLE instance started. Total System Global Area 63729356 bytes Fixed Size 282316 bytes Variable Size 46137344 bytes Database Buffers 16777216 bytes Redo Buffers 532480 bytes Database mounted. Database opened.
Restart the database to start using the newly created spfile.SQL> CREATE SPFILE FROM PFILE='d:\init.ora'; File created.
SQL> STARTUP FORCE ORACLE instance started. Total System Global Area 63729356 bytes Fixed Size 282316 bytes Variable Size 46137344 bytes Database Buffers 16777216 bytes Redo Buffers 532480 bytes Database mounted. Database opened.
Tip: Adding comments to the spfileWhen you create an spfile from a pfile, Comments, which are specified in the pfile, are ignored and not stored in the new spfile. Export an spfile to a pfile and open it, you'll see the result. However, there is a workaround here comments added on the same line of the parameter are not omitted. Look at the following example: #This is set to FALSE
timed_statistics=FALSE
The comment specified above would be omitted at the time of spfile creation. timed_statistics=FALSE #This is set to FALSEOn the other hand, this comment would be added to the spfile and will be exported into pfile at the time of spfile export. This should explain well how to add consistent comments to your spfile. |
While changing initialization parameters, values can be set to a specific instance or to all the instances. Lets assume that we are running an RAC with two instances PROD and SALES to change the TIMED_STATISTICS parameter to true for SALES instance you do the following:
To set the seething to all the instancesSQL> ALTER SYSTEM SET timed_statistics=TRUE SID='sales'; System altered.
Oracle uses the following syntax to store parameter values belonging to different instances:SQL> ALTER SYSTEM SET timed_statistics=FALSE SID='*'; System altered.
The two values respectively correspond to the values we have set with the previous set of commands. You may optionally use the SCOPE clause to specify it to a particular instance only without storing it in the spfile.sales.TIMED_STATISTICS=TRUE *.TIMED_STATISTICS=FALSE
Happy DBA'ing
Venu G.
For ORAMASTERS Inc.