一、pfile与spfile的概念和区别
概念:
Oracle中的参数文件是一个包含一系列参数以及参数对应值的操作系统文件,可以分为两种类型。它们是在数据库实例启动时候加载的,决定了数据库的物理结构、内存、数据库的限制及系统大量的默认值、数据库的各种物理属性、指定数据库控制文件名和路径等信息,是进行数据库设计和性能调优的重要文件。
初始化参数文件(Initialization Parameters Files),Oracle 9i之前,Oracle一直采用pfile方式存储初始化参数,该文件为文本文件。
服务器参数文件(Server Parameter Files),从Oracle 9i开始,Oracle引入了spfile文件,该文件为二进制格式,不能通过手工修改。
区别:
1:pfile是文本文件的,而spfile是二进制格式的。pfile文件可以用文本编辑器打开手工配置、而spfile不行,只能通过SQL命令在线修改。从操作系统上可以看到这两者的区别,pfile文件为ASCII文本文件,spfile为数据文件。
[oracle@localhost trace]$ cd $ORACLE_HOME/dbs
[oracle@localhost dbs]$ ls
hc_orcl.dat init.ora initorcl.ora lkORCL orapworcl spfileorcl.ora
[oracle@localhost dbs]$ file initorcl.ora
initorcl.ora: ASCII text
[oracle@localhost dbs]$ file spfileorcl.ora
spfileorcl.ora: data
2:spfile的修改是可以通过SQL命令在线修改,不再需要通过手工修改,对于动态参数所有更改可以立即生效,而PFILE的修改必须重启实例才能生效。
3:手动创建数据库而不是通过dbca,则开始创建数据库时,只能定义pfile。
二、如何判断Oracle使用哪种模式启动呢? 可以使用下面5种方法查看(推荐使用前面两种):
1、show parameter pfile
2、show parameter spfile
注:如果数据库使用spfile参数文件,那么用show parameter pfile与 show parameter spfile的结果一致,如果数据库使用pfile参数文件,那么上面命令得到的结果都是空。
3、使用v$spparameter视图查看
SQL> select decode(count(*),1,'spfile','pfile') from v$spparameter where rownum=1 and isspecified = 'true';
4、查询动态视图v$parameter,如果values值为非空,则是spfile启动,否则是pfile。
select name,value,display_value from v$parameter where name ='spfile';
5、通过alert日志查看
[oracle@localhost ~]$ sqlplus / as sysdba
SQL*Plus: Release 11.2.0.3.0 Production on Fri Jun 8 02:56:54 2018
Copyright (c) 1982, 2011, Oracle. All rights reserved.
Connected to:
Oracle Database 11g Enterprise Edition Release 11.2.0.3.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
SQL> show parameter pfile;
NAME TYPE VALUE
------------------------------------ ----------- ------------------------------
spfile string /oracle/app/oracle/product/11.
2.0/db_1/dbs/spfileorcl.ora
SQL> show parameter spfile;
NAME TYPE VALUE
------------------------------------ ----------- ------------------------------
spfile string /oracle/app/oracle/product/11.
2.0/db_1/dbs/spfileorcl.ora
SQL> select decode(count(*),1,'spfile','pfile') from v$spparameter where rownum=1 and isspecified = 'true';
DECODE
------
spfile
SQL> select name,value,display_value from v$parameter where name ='pfile';
no rows selected
SQL> select name,value,display_value from v$parameter where name ='spfile';
NAME
--------------------------------------------------------------------------------
VALUE
----------------------------------------------------------------------------------------------------
DISPLAY_VALUE
----------------------------------------------------------------------------------------------------
spfile
/oracle/app/oracle/product/11.2.0/db_1/dbs/spfileorcl.ora
/oracle/app/oracle/product/11.2.0/db_1/dbs/spfileorcl.ora
SQL>
SQL> show parameter dump;
NAME TYPE VALUE
------------------------------------ ----------- ------------------------------
background_core_dump string partial
background_dump_dest string /oracle/app/oracle/diag/rdbms/
orcl/orcl/trace #alert_orcl.log路径
core_dump_dest string /oracle/app/oracle/diag/rdbms/
orcl/orcl/cdump
max_dump_file_size string unlimited
shadow_core_dump string partial
user_dump_dest string /oracle/app/oracle/diag/rdbms/
orcl/orcl/trace
SQL> exit
Disconnected from Oracle Database 11g Enterprise Edition Release 11.2.0.3.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
[oracle@localhost ~]$ cd /oracle/app/oracle/diag/rdbms/orcl/orcl/trace
[oracle@localhost trace]$ ls | grep alert
alert_orcl.log
[oracle@localhost trace]$ cat alert_orcl.log | grep spfile
#由查看结果可知Oracle是使用spfile启动的
spfile.png
三、使用pfile启动Oracle(默认是spfile启动的)
[oracle@localhost ~]$ sqlplus / as sysdba
SQL*Plus: Release 11.2.0.3.0 Production on Fri Jun 8 03:54:03 2018
Copyright (c) 1982, 2011, Oracle. All rights reserved.
Connected to:
Oracle Database 11g Enterprise Edition Release 11.2.0.3.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
SQL> show parameter spfile;
#Oracle默认使用spfile启动
NAME TYPE VALUE
------------------------------------ ----------- ------------------------------
spfile string /oracle/app/oracle/product/11.
2.0/db_1/dbs/spfileorcl.ora
SQL> show parameter pfile;
NAME TYPE VALUE
------------------------------------ ----------- ------------------------------
spfile string /oracle/app/oracle/product/11.
2.0/db_1/dbs/spfileorcl.ora
SQL> shutdown immediate;
Database closed.
Database dismounted.
ORACLE instance shut down.
SQL> create pfile from spfile;
File created.
#这条命令执行成功后,会在$ORACLE_HOME/dbs下面生成pfile文件initorcl.ora
SQL> startup pfile='$ORACLE_HOME/dbs/initorcl.ora';
#通过pfile启动Oracle,启动命令也可以用;startup pfile='/oracle/app/oracle/product/11.2.0/db_1/dbs/initorcl.ora';
ORACLE instance started.
Total System Global Area 1603411968 bytes
Fixed Size 2228784 bytes
Variable Size 939527632 bytes
Database Buffers 654311424 bytes
Redo Buffers 7344128 bytes
Database mounted.
Database opened.
测试:
SQL> show parameter pfile;
NAME TYPE VALUE
------------------------------------ ----------- ------------------------------
spfile string
SQL> show parameter spfile;
NAME TYPE VALUE
------------------------------------ ----------- ------------------------------
spfile string
SQL> select decode(count(*),1,'spfile','pfile') from v$spparameter where rownum=1 and isspecified = 'true';
DECODE
------
pfile
SQL> select name,value,display_value from v$parameter where name ='pfile';
no rows selected
SQL> select name,value,display_value from v$parameter where name ='spfile';
NAME
--------------------------------------------------------------------------------
VALUE
----------------------------------------------------------------------------------------------------
DISPLAY_VALUE
----------------------------------------------------------------------------------------------------
spfile
SQL> show parameter dump;
NAME TYPE VALUE
------------------------------------ ----------- ------------------------------
background_core_dump string partial
background_dump_dest string /oracle/app/oracle/diag/rdbms/
orcl/orcl/trace
core_dump_dest string /oracle/app/oracle/diag/rdbms/
orcl/orcl/cdump
max_dump_file_size string unlimited
shadow_core_dump string partial
user_dump_dest string /oracle/app/oracle/diag/rdbms/
orcl/orcl/trace
SQL> exit
Disconnected from Oracle Database 11g Enterprise Edition Release 11.2.0.3.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
[oracle@localhost ~]$ cd /oracle/app/oracle/diag/rdbms/orcl/orcl/trace
[oracle@localhost trace]$ ls | grep alert
alert_orcl.log
[oracle@localhost trace]$ cat alert_orcl.log
#由查看结果可知Oracle是使用pfile启动的
pfile.png
网友评论