วันอังคารที่ 1 เมษายน พ.ศ. 2551

อยากรู้ว่า Oracle Database ใช้spfile หรือไม่

ตอบง่ายๆ ว่านี่ไง
SQL> show parameter spfile;

NAME TYPE VALUE
------------------------------------ ----------- ------------------------------
spfile string +DATA/testdb/spfiletestdb.ora

จากนั้นก็เกิดคำถามว่ามีวิธีอื่นอีกไหมละนี่
มีครับ เราสามารถเช็คได้ที่ V$SPPARAMETER View ตัวนี้เลยครับ

Column Datatype Description
SID VARCHAR2(80) SID for which the parameter is defined
NAME VARCHAR2(80) Name of the parameter
VALUE VARCHAR2(255) Parameter value (null if a server parameter file was not used to start the instance)
DISPLAY_VALUE VARCHAR2(255) Parameter value in a user-friendly format. For example, if the VALUE column shows the value 262144 for a big integer parameter, then the DISPLAY_VALUE column will show the value 256K.
ISSPECIFIED VARCHAR2(6) Indicates whether the parameter was specified in the server parameter file (TRUE) or not (FALSE)
ORDINAL NUMBER Position (ordinal number) of the parameter value (0 if a server parameter file was not used to start the instance). Useful only for parameters whose values are lists of strings.
UPDATE_COMMENT VARCHAR2(255) Comments associated with the most recent update (null if a server parameter file was not used to start the instance)

V$SPPARAMETER จะบอกข้อมูลเกี่ยวกับ spfile, แล้วจะใช้ไม่ใช้ spfile ตอน startup database นี่ ดูที่ ISSPECIFIED .

ตัวอย่าง query

SQL> select isspecified, count(*) from v$spparameter group by
isspecified;

ISSPEC COUNT(*)
------ ----------
TRUE 40
FALSE 254

ผลลัพธ์คือใช้ spfile ครับ
ทำไมละครับ ก็เพราะว่ามี บางค่าใน view มี ISSPECIFIED = TRUE
แล้วถ้าไม่ใช้ละ

SQL> shutdown immediate;

Database closed.
Database dismounted.
ORACLE instance shut down.

SQL> startup pfile=/tmp/pfile;
ORACLE instance started.

Total System Global Area 1703624704 bytes
Fixed Size 2145064 bytes
Variable Size 1291846872 bytes
Database Buffers 402653184 bytes
Redo Buffers 6979584 bytes
Database mounted.
Database opened.

SQL> select isspecified, count(*) from v$spparameter group by
isspecified;

ISSPEC COUNT(*)
------ ----------
FALSE 289
ไม่มี TRUE ตรงนี้เลยไม่ใช้ spfile ครับ

---> กลับไปใช้ spfile:

SQL> shutdown immediate;
Database closed.
Database dismounted.
ORACLE instance shut down.
SQL> startup;
ORACLE instance started.

Total System Global Area 1703624704 bytes
Fixed Size 2145064 bytes
Variable Size 1291846872 bytes
Database Buffers 402653184 bytes
Redo Buffers 6979584 bytes
Database mounted.
Database opened.

SQL> select isspecified, count(*) from v$spparameter group by
isspecified; 2

ISSPEC COUNT(*)
------ ----------
TRUE 40
FALSE 254

หรือนี่เลยครับ

SQL> select decode(count(*), 1, 'spfile', 'pfile' )
from v$spparameter
where rownum=1
and isspecified='TRUE';

DECODE
------
spfile



Enjoy!