Oracle的参数文件:pfile和spfile


1、pfile和spfile

Oracle中的参数文件是一个包含一系列参数以及参数对应值的操作系统文件。它们是在数据库实例启动时候加载的,决定了数据库的物理 结构、内存、数据库的限制及系统大量的默认值、数据库的各种物理属性、指定数据库控制文件名和路径等信息,是进行数据库设计和性能调优的重要文件。可以分为两种类型:

pfile: 初始化参数文件(Initialization Parameters Files),Oracle 9i之前,ORACLE一直采用pfile方式存储初始化参数,pfile 默认的名称为“init+例程名.ora”文件路径:/data/app/oracle/product/12.1.0/dbhome_1/dbs,这是一个文本文件,可以用任何文本编辑工具打开。

spfile:服务器参数文件(Server Parameter Files),从Oracle 9i开始,Oracle引入了Spfile文件,spfile 默认的名称为“spfile+例程名.ora”文件路径:/data/app/oracle/product/12.1.0/dbhome_1/dbs  以二进制文本形式存在,不能用vi编辑器对其中参数进行修改,只能通过SQL命令在线修改。

从操作系统上可以看到这两者的区别,初始化参数文件为ASCII文本文件,Spfile为数据文件。

[oracle@xqzt ~]$ cd /data/app/oracle/product/12.1.0/dbhome_1/dbs/
[oracle@xqzt dbs]$ ls
hc_orcl.dat init.ora lkORCL orapworcl spfileorcl.ora
[oracle@xqzt dbs]$ file init.ora
init.ora: ASCII English text
[oracle@xqzt dbs]$ file spfileorcl.ora
spfileorcl.ora: data
[oracle@xqzt dbs]$

2、使用spfile的好处

1、spfile改正了pfile管理混乱的问题,在多结点的环境里,pfile会有多个image,启动时候需要跟踪最新的image。这是个烦琐的过程。用spfile以后,所有参数改变都写到spfile里面(只要定义scope=spfile或both),参数配置有个权威的来源。

2、9i以前一般都是要备份pfile后再来做参数的修改,而且pfile的修改必须重启实例才能生效。非常的不方便;在9i以后的spfile就可以同通过命令修改指定的参数了,而且有很多参数都不用重启数据库,能够在线生效,这个在线生效的参数会随着数据库的版本增高而增加。如果参数修改有问题数据库起不来了可以在 nomount状态下创建成pfile再修改回来即可。)

3、如何查看Spfile与pfile的目录位置?

方法一:

SQL> SELECT NAME, VALUE, DISPLAY_VALUE FROM V$PARAMETER WHERE NAME ='spfile';

NAME
--------------------------------------------------------------------------------
VALUE
--------------------------------------------------------------------------------
DISPLAY_VALUE
--------------------------------------------------------------------------------
spfile
/data/app/oracle/product/12.1.0/dbhome_1/dbs/spfileorcl.ora
/data/app/oracle/product/12.1.0/dbhome_1/dbs/spfileorcl.ora

方法二: Show parameter spfile

4、判断Oracle启动时使用spfile还是pfile?

1、 通过v$spparameter视图

使用spfile启动数据库,我们可以看到查询出来的结果是spfile

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

DECODE
------
spfile

2、 通过查看spfile、pfile参数

系统当前为从spfile启动,在查看show parameter pfile和show parameter spfile 都能看到spfile参数文件的路径。

关闭数据库,从pfile启动,startup pfile='/data/app/oracle/product/12.1.0/dbhome_1/dbs/initorcl.ora';  再次执行上述的两个语句

我们在这里可以很明显的发现,使用pfile启动的数据库,我们无论是查看show parameter pfile还是show parameter spfile 都无法看到pfile参数文件的路径。

5、pfile和spfile的互相创建

create spfile[='xxxxx'] from pfile[='xxxx'];

create pfile[='xxxxx'] from spfile[='xxxx'];

SQL> create pfile from spfile ;

File created.

SQL>

通过spfile创建pfile文件(此时会在$ORACLE_HOME/dbs目录下生成pfile:initorcl.ora),当然你也可以指定参数文件的位置。

[oracle@xqzt dbs]$ pwd
/data/app/oracle/product/12.1.0/dbhome_1/dbs
[oracle@xqzt dbs]$ ls
hc_orcl.dat  lkORCL    spfileorcl.ora
init.ora    initorcl.ora  orapworcl 

6、使用pfile/spfile 启动数据库

1、startup 启动次序 spfile优先于pfile。查找文件的顺序是 spfileSID.ora-〉spfile.ora-〉initSID.ora-〉init.ora(spfile优先于pfile)。

2、startup pfile='文件目录'      使用pfile启动,则需指定完整路径,或删除spfile.

SQL> startup pfile='/data/app/oracle/product/12.1.0/dbhome_1/dbs/initorcl.ora';

ORACLE instance started.

Total System Global Area 2466250752 bytes

Fixed Size 2927384 bytes

Variable Size 1426064616 bytes

Database Buffers 1023410176 bytes

Redo Buffers 13848576 bytes

Database mounted.

Database opened.

SQL>

3、 如果在数据库的$ORACLE_HOME/dbs/目录下既有spfile又有pfile,使用spfile启动数据库,不需要指定参数文件路径(因为数据库会优先选择spfile启动),

4、 如果参数文件不在$ORACLE_HOME/dbs/目录下,无论是通过spfile或pfile启动均需要指定完整路径。

7、spfile参数的三种scope:

1. scope=spfile: 对参数的修改记录在服务器初始化参数文件中,修改后的参数在下次启动DB时生效。适用于动态和静态初始化参数。

2. scope=memory: 对参数的修改记录在內存中,对于动态初始化参数的修改立即生效。在重启DB后会丟失,会复原为修改前的参数值。

3. scope=both:  对参数的修改会同时记录在服务器参数文件和內存中,对于动态参数立即生效,对静态参数不能用这个选项

参数类型

spfile

memory

both

静态参数

可以,重启服务器生效

不可以

不可以

动态参数

可以,重启服务器生效

可以,立即生效,重启服务失效

可以,立即生效,重启服务器仍然有效果

如果使用了服务器参数文件,则在执行alter system语句时,scope=both是default的选项。

如果沒有使用服务器参数文件,而在执行alter system语句时指定scope=spfile|both都会出错。

8、修改参数例子

scope=both: 对于动态参数立即生效 

 

SQL> show parameter pga;

NAME                                  TYPE              VALUE

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

pga_aggregate_limit big                  integer            2G

pga_aggregate_target big                integer          500M

SQL> alter system set pga_aggregate_target = 600m scope=both;


System altered.


SQL> show parameter pga;


NAME                                    TYPE                VALUE

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

pga_aggregate_limit big                integer                2G

pga_aggregate_target big              integer                600M

 

 

对静态参数不能使用scope=both

 

SQL>  alter system set processes = 100 scope=both;
 alter system set processes = 100 scope=both
                  *
ERROR at line 1:
ORA-02095: specified initialization parameter cannot be modified


SQL>

 

静态参数 scope=spfile 修改完后重启数据库能生效

 

SQL> show parameter processes


NAME                                    TYPE                VALUE

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

aq_tm_processes                        integer                1

db_writer_processes                    integer                1

gcs_server_processes                    integer                0

global_txn_processes                    integer                1

job_queue_processes                    integer                1000

log_archive_max_processes              integer                4

processes                              integer                300

SQL> alter system set processes = 100 scope=spfile;


System altered.


SQL> shutdown immediate

Database closed.

Database dismounted.

ORACLE instance shut down.

SQL> startup

ORACLE instance started.

Total System Global Area 2466250752 bytes

Fixed Size 2927384 bytes

Variable Size 1358955752 bytes

Database Buffers 1090519040 bytes

Redo Buffers 13848576 bytes

Database mounted.

Database opened.

SQL> show parameter processes


NAME                                    TYPE                VALUE

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

aq_tm_processes                        integer                1

db_writer_processes                    integer                1

gcs_server_processes                  integer                0

global_txn_processes                  integer                1

job_queue_processes                    integer                1000

log_archive_max_processes              integer                4

processes                              integer                100

 

scope=memory  对于动态参数,可以实现立即生效,下次启动失效。

SQL> alter system set pga_aggregate_target = 600m scope=memory;

System altered.

SQL>

如果使用的是pfile,则无法通过命令进行修改,会报ORA-02095或32001错误。

 

SQL> startup pfile='/data/app/oracle/product/12.1.0/dbhome_1/dbs/initorcl.ora';

ORACLE instance started.

Total System Global Area 2466250752 bytes

Fixed Size 2927384 bytes

Variable Size 1426064616 bytes

Database Buffers 1023410176 bytes

Redo Buffers 13848576 bytes

Database mounted.

Database opened.

SQL> alter system set processes = 100;

alter system set processes = 100

*

ERROR at line 1:

ORA-02095: specified initialization parameter cannot be modified

SQL> alter system set processes = 100 scope=spfile;

alter system set processes = 100 scope=spfile

*

ERROR at line 1:

ORA-32001: write to SPFILE requested but no SPFILE is in use

SQL> alter system set processes = 100 scope=both;

alter system set processes = 100 scope=both

*

ERROR at line 1:

ORA-02095: specified initialization parameter cannot be modified

SQL> alter system set processes = 100 scope=memory;

alter system set processes = 100 scope=memory

*

ERROR at line 1:

ORA-02095: specified initialization parameter cannot be modified

 

9、参数列表:

参数:

 

# Cache and I/O    高速缓存和 I/O
###########################################
db_block_size=8192  指定数据块大小为8KB
db_cache_size=33554432    指定数据缓冲区为32MB,该值越大,可以减少对数据库文件的I/O次数,提高效率
db_file_multiblock_read_count=16
###########################################

# Cursors and Library Cache  游标和库高速缓存
###########################################
open_cursors=300  指定一个会话一次可以打开的游标的最大数量为300,应将该值设置得足够高,这样才能防止应用程序耗尽打开的游标
###########################################

# Database Identification  数据库标识
###########################################
db_domain=""  数据库域名为mynet,加上数据库名称db_name构成全局数据库名称
db_name=cicro  数据库名称为myoracle
###########################################

# Diagnostics and Statistics    诊断和统计
###########################################
background_dump_dest=/opt/oracle/admin/cicro/bdump  后台进程跟踪文件目录
core_dump_dest=/opt/oracle/admin/cicro/cdump        核心转储跟踪文件目录
timed_statistics=TRUE                                收集操作系统的计时信息,这些信息可被用来优化数据库和 SQL 语句
user_dump_dest=/opt/oracle/admin/cicro/udump        用户进程跟踪文件目录

###########################################
# File Configuration
control_files=("/opt/oracle/oradata/cicro/control01.ctl", "/opt/oracle/oradata/cicro/control02.ctl",

"/opt/oracle/oradata/cicro/control03.ctl")    指定控制文件的路径及文件名
###########################################

###########################################
# Instance Identification  网络注册
###########################################
instance_name=test  例程名称为test

###########################################
# Job Queues
###########################################
job_queue_processes=10

###########################################
# MTS 多线程服务器配置标识,在Oracle 9i里称为共享服务器配置
###########################################
dispatchers="(PROTOCOL=TCP) (SERVICE=testXDB)"  多线程服务器配置

###########################################
# Miscellaneous  其他
###########################################
aq_tm_processes=1
compatible=9.2.0.0.0  兼容版本9.2.0

###########################################
# Optimizer
###########################################
hash_join_enabled=TRUE
query_rewrite_enabled=FALSE
star_transformation_enabled=FALSE
db_name=cicro

###########################################

###########################################
# Pools 池
###########################################
Java_pool_size=83886080    指定Java存储池的大小为32MB,用于存储 Java 的方法、类定义和Java对象。
large_pool_size=16777216  指定大型池的大小为1MB, 用于共享服务器的会话内存、并行执行的消息缓冲区以及RMAN备份和恢复的磁盘 I/O 缓冲区。
shared_pool_size=83886080  指定共享池的大小为32MB,用于存储共享游标、存储的过程、控制结构和并行执行消息缓冲区等对象。较大的值能改善多用户系统的性能.

###########################################
# Processes and Sessions 进程和会话
###########################################
processes=150 指定可同时连接到一个Oracle Server上的操作系统用户进程的最大数量为150

###########################################
# Redo Log and Recovery  重做日志和恢复
###########################################
fast_start_mttr_target=300  指定从单个数据库例程崩溃中恢复所需的时间为300秒

###########################################
# Security and Auditing 安全与验证
###########################################
remote_login_passwordfile=EXCLUSIVE  指定操作系统或口令文件是否具有检查用户口令的权限。设置为EXCLUSIVE, 将使用数据库的口令文件对每个具有权限的用户进.

###########################################
# Sort, Hash Joins, Bitmap Indexes  排序, 散列联接, 位图索引
###########################################
pga_aggregate_target=25165824
sort_area_size=524288  指定排序区使用的最大内存量为512KB。排序完成后, 各行将返回, 并且内存将释放。增大该值可以提高大型排序的效率。

###########################################
# System Managed Undo and Rollback Segments  系统管理的撤消和回退段
###########################################
undo_management=AUTO  指定系统使用的撤消空间管理方式为SMU 方式,在SMU方式下, 撤消空间会像撤消表空间一样在外部分配.
undo_retention=10800 
undo_tablespace=UNDOTBS1  指定回滚表空间为UNDOTBS

相关内容