用过Oracle的朋友都知道,现在绝大部分Oracle数据库使用的是基于服务器的参数文件。对于查询当前数据库实例级别,system级别,session级别参数的具体设置有些时候很容易混淆。本文主要介绍了Oracle数据库参数使用的相关视图(V$PARAMETER,V$PARAMETER2,V$SYSTEM_PARAMETER,V$SYSTEM_PARAMETER2,V$SPPARAMETER),以及通过查询Oracle视图来获得不同情形下的参数值并进行对比。
1、对比有关参数视图 a、V$PARAMETER displays information about the initialization parameters that are currently in effect for the session. A new session inherits parameter values from the instance-wide values displayed by the V$SYSTEM_PARAMETER view. 显示的是基于当前session级别生效的初始化参数,新的session会从实例范围派生一些参数值(在视图V$SYSTEM_PARAMETER2呈现) 视图下的几个重要列(下面的几个视图中也存在这个几个列,类同) ISSES_MODIFIABLE: 表明当前参数是否够基于session级别进行修改(ALTER SESSION (TRUE) or not (FALSE)) ISSYS_MODIFIABLE: 表明当前参数是否够基于system级别进行修改(ALTER SYSTEM)以及改变生效的情形 IMMEDIATE,立即生效(不考虑是否用pfile或spfile启动); DEFERRED,延迟生效,后续新的session中有效(不考虑是否用pfile或spfile启动); FALSE,参数不能被修改,除非使用了spfile参数文件启动,后续新的session中有效 ISINSTANCE_MODIFIABLE:是否为实例级别可修改参数(ALTER SYSTEm),主要是考虑RAC环境 为TRUE,表明该参数可以不同于其他实例 为FALSE,表名该参数在所有实例中必须使用相同的值
b、V$PARAMETER2 displays information about the initialization parameters that are currently in effect for the session, with each list parameter value appearing as a row in the view. A new session inherits parameter values from the instance-wide values displayed in the V$SYSTEM_PARAMETER2 view. 显示的是基于当前session级别生效的初始化参数,新的session会从实例范围派生一些参数(在视图V$SYSTEM_PARAMETER2呈现) 注意,这个视图对于存在多个参数值的参数,在这个视图中分为多行进行列出 如control_files在视图V$PARAMETER呈现为一行,且有2个值,则在V$PARAMETER2中显示为2行 Presenting the list parameter values in this format enables you to quickly determine the values for a list parameter. For example, if a parameter value is a, b, then the V$PARAMETER view does not tell you if the parameter has two values (both a and b) or one value (a, b). V$PARAMETER2 makes the distinction between the list parameter values clear.
c、V$SYSTEM_PARAMETER V$SYSTEM_PARAMETER displays information about the initialization parameters that are currently in effect for the instance. A new session inherits parameter values from the instance-wide values. 显示的是基于实例级别参数的相关信息,新的session同样会从实例级别进行派生
d、V$SYSTEM_PARAMETER2 V$SYSTEM_PARAMETER2 displays information about the initialization parameters that are currently in effect for the instance, with each list parameter value appearing as a row in the view. A new session inherits parameter values from the instance-wide values. 与V$PARAMETER,V$PARAMETER2相类似,V$SYSTEM_PARAMETER2用于展示实例级别且一个参数有多个值分多行列出的情形
e、V$SPPARAMETER displays information about the contents of the server parameter file. If a server parameter file was not used to start the instance, then each row of the view will contain FALSE in the ISSPECIFIED column. 这个视图列出的是基于服务器参数文件中的参数信息,如果没有使用服务器参数文件启动实例,则视图中每一行ISSPECIFIED列的值为FALSE
2、示例演示参数视图
a、查看session级别的参数
--基于session级别可以直接使用show parameter 方式
--演示环境
scott@USBO> select * from v$version where rownum<2;
BANNER
-------------------------------------------------------------------------------
Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - Production
scott@USBO> show parameter cursor_shar
NAME TYPE VALUE
------------------------------------ --------------------------------- ------------------------------
cursor_sharing string EXACT
scott@USBO> select name,value,isses_modifiable,issys_modifiable,isinstance_modifiable
2 from v$parameter where name='cursor_sharing';
NAME VALUE ISSES_MODIFIABL ISSYS_MODIFIABLE ISINSTANCE_MODI
------------------------------ --------------- --------------- --------------------------- ---------------
cursor_sharing EXACT TRUE IMMEDIATE TRUE
scott@USBO> alter session set cursor_sharing='SIMILAR'; --->上面的查询可知session级别为true,即可修改
Session altered.
scott@USBO> show parameter cursor_shar -->再次查看,修改已经生效
NAME TYPE VALUE
------------------------------------ --------------------------------- ------------------------------
cursor_sharing string SIMILAR
b、查看基于实例级别的参数
--基于实例级别的参数需要通过V$SYSTEM_PARAMETER访问
scott@USBO> select name,value from v$system_parameter where name='cursor_sharing';
NAME VALUE
------------------------------ ---------------
cursor_sharing EXACT --->可以看到此时的值依旧是exact,并没有受到之前修改的影响
scott@USBO> alter system set cursor_sharing='FORCE'; --->将参数cursor_sharing进行基于系统级别进行修改
System altered.
scott@USBO> show parameter cursor_sharing --->此时可以看到当前session级别该参数从system级别派生
NAME TYPE VALUE
------------------------------------ --------------------------------- ------------------------------
cursor_sharing string FORCE
scott@USBO> alter session set cursor_sharing='EXACT'; --->再次基于session级别进行修改
Session altered.
scott@USBO> show parameter cursor_shar --->此时查询到session的值变为EXACT,那system级别呢?肯定是FORCE,大家自行验证
NAME TYPE VALUE
------------------------------------ --------------------------------- ------------------------------
cursor_sharing string EXACT
c、演示v$parameter与v$parameter2的差异
scott@USBO> show parameter control_files;
NAME TYPE VALUE
------------------------------------ --------------------------------- ------------------------------
control_files string /u03/database/usbo/oradata/con
trol01.ctl, /u03/database/usbo
/oradata/control02.ctl
scott@USBO> select name,value from v$parameter where name='control_files';
NAME VALUE
------------------------------ ------------------------------------------------------------
control_files /u03/database/usbo/oradata/control01.ctl, /u03/database/usbo
/oradata/control02.ctl
--查询v$parameter2时,对于存在多个参数值的参数,在这个视图中分为多行进行列出,如下
--对于v$system_parameter与v$system_parameter2存在类似的情形,不再演示
scott@USBO> select name,value from v$parameter2 where name='control_files';
NAME VALUE
------------------------------ ------------------------------------------------------------
control_files /u03/database/usbo/oradata/control01.ctl
control_files /u03/database/usbo/oradata/control02.ctl
d、关于v$spparameter
--该视图可以用于判断当前数据库使用的是pfile还是spfile来启动
scott@USBO> select distinct isspecified from v$spparameter;
ISSPECIFIED
------------------
TRUE --->第一个值为TRUE,spfile启动
FALSE
goex_admin@MFTST> select distinct isspecified from v$spparameter;
ISSPEC
------
FALSE --->为false,pfile文件启动数据库
goex_admin@MFTST> select name,value from v$spparameter where name='control_files';
NAME VALUE
------------------------- ------------------------------------------------------------
control_files --->由于为pfile启动,所以查询不到任何信息
goex_admin@MFTST> select count(*) from v$spparameter where isspecified='TRUE';
COUNT(*)
---------- --->列isspecified没有一个值为TRUE,同样是因为使用了pfile
0
对于spfile启动下的v$spparameter,对于存在多个参数值的参数,在这个视图中也分为多行进行列出
scott@USBO> select name,value from v$spparameter where name='control_files';
NAME VALUE
------------------------------ ------------------------------------------------------------
control_files /u03/database/usbo/oradata/control01.ctl
control_files /u03/database/usbo/oradata/control02.ctl
3、小结 a、对于Oracle数据库参数文件存在多个视图可以查询其值(v$paraemter,v$parameter2,v$system_parameter,v$system_parameter2,v$spparameter); b、v$paraemter,v$parameter2视图主要是查询基于session级别的参数的相关信息,v$parameter2对于同一个参数多个值分多行的形式展开; c、v$system_parameter,v$system_parameter2是查询基于system,实例级别的参数的相关信息,v$system_parameter2同样用于一个参数多值分行展开; d、注意理解参数的几个不同级别session,system,instance级别,instance级别主要对多实例情形(RAC),有时候sytem与instance会混用; e、v$spparameter主要是针对服务器参数文件有效即spfile,同时也可以用于检查当前使用了pfile还是spfile方式启动。