Oracle 启动用到了初始化参数,通常我们都可以在sqlplus里用show parameter 来获得。而Oracle为了debug 或者解决一些特殊的问题,还提供了一些以“_”开头的隐含参数。 网络上有一些script可以让我们轻松检查这些隐含参数. 但是,有没有想过,我们可以直接在sqlplus 用show parameter 来获取这些隐含参数呢?
答案是
可以的。
下面,我将演示一下如何用sqlplus 里的 show parameter来直接查看Oracle隐含参数.
1。首先,我们先要知道,sqlplus怎样通过show parameter获得参数的。通过sql_trace的方式可以发现。
sqlplus serol/luo
alter session set sql_trace=true;
show parameter optimizer
NAME TYPE VALUE
------------------------------------ -------------------------------- ------------------------------
------------------------------------ -------------------------------- ------------------------------
optimizer_dynamic_sampling integer 1
optimizer_features_enable string 9.2.0.1
optimizer_index_caching integer 0
optimizer_index_cost_adj integer 1
optimizer_max_permutations integer 2000
optimizer_mode string RULE
optimizer_features_enable string 9.2.0.1
optimizer_index_caching integer 0
optimizer_index_cost_adj integer 1
optimizer_max_permutations integer 2000
optimizer_mode string RULE
exit
到udump底下找到trace文件,里面的最主要的语句是:
SELECT NAME name_col_plus_show_param,DECODE(TYPE,1,'boolean',2,'string',3,'integer',4,'file',6,'big
integer','unknown') TYPE,VALUE value_col_plus_show_param FROM V$PARAMETER WHERE UPPER(NAME) LIKE UPP
ER('%optimizer%') ORDER BY name_col_plus_show_param,ROWNUM
integer','unknown') TYPE,VALUE value_col_plus_show_param FROM V$PARAMETER WHERE UPPER(NAME) LIKE UPP
ER('%optimizer%') ORDER BY name_col_plus_show_param,ROWNUM
可以看到,sqlplus的show parameter实际上就是查询
V$PARAMETER .
2. 看看 v$parameter的定义。
SELECT * FROM v$fixed_view_definition
WHERE view_name = 'V$PARAMETER';
WHERE view_name = 'V$PARAMETER';
select NUM , NAME , TYPE , VALUE , ISDEFAULT , ISSES_MODIFIABLE , ISSYS_MODIFIABLE , ISMODIFIED , ISADJUSTED , DESCRIPTION, UPDATE_COMMENT from GV$PARAMETER where inst_id = USERENV('Instance')
SELECT * FROM v$fixed_view_definition
WHERE view_name = 'GV$PARAMETER';
WHERE view_name = 'GV$PARAMETER';
select x.inst_id,x.indx+1,ksppinm,ksppity,ksppstvl,ksppstdf,
decode(bitand(ksppiflg/256,1),1,'TRUE','FALSE'),
decode(bitand(ksppiflg/65536,3),1,'IMMEDIATE',2,'DEFERRED',
3,'IMMEDIATE','FALSE'), decode(bitand(ksppstvf,7),1,'MODIFIED',4,'SYSTEM_MOD','FALSE'),
decode(bitand(ksppstvf,2),2,'TRUE','FALSE'), ksppdesc, ksppstcmnt
from x$ksppi x, x$ksppcv y
where (x.indx = y.indx) and ( (translate(ksppinm,'_','#') not like '#%') or (ksppstdf = 'FALSE') )
decode(bitand(ksppiflg/256,1),1,'TRUE','FALSE'),
decode(bitand(ksppiflg/65536,3),1,'IMMEDIATE',2,'DEFERRED',
3,'IMMEDIATE','FALSE'), decode(bitand(ksppstvf,7),1,'MODIFIED',4,'SYSTEM_MOD','FALSE'),
decode(bitand(ksppstvf,2),2,'TRUE','FALSE'), ksppdesc, ksppstcmnt
from x$ksppi x, x$ksppcv y
where (x.indx = y.indx) and ( (translate(ksppinm,'_','#') not like '#%') or (ksppstdf = 'FALSE') )
看到上面最关键的
(translate(ksppinm,'_','#') not like '#%')的条件了吗?,就是它把开头为"_" 的隐含参数给过滤掉了。当然,ksppstdf = 'FALSE' 的条件是为了保证如果已经手动改过隐含参数,show parameter还会显示改隐含参数
3。我们可以伪造一个v$parameter, 去掉过滤"_"的条件,就可以大功告成了。
不过,毕竟是改动系统的内部设置,大家一定要小心为上。
一定要以一个仅用于数据库管理,不会参加任何程序活动的管理性数据库用户来伪造这个v$parameter,以免发生意外。而且,最好是在测试环境中玩,而不要跑到生产环境里面。下面假设这个用户名为:rollingpig.
以sys 登陆
connect / as sysdba
create view
my_v$parameter_with_hidden (NUM,NAME , TYPE , Value , ISDEFAULT , ISSES_MODIFIABLE , ISSYS_MODIFIABLE ,ISMODIFIED , ISADJUSTED, DESCRIPTION, UPDATE_COMMENT)
as
select x.indx+1,ksppinm,ksppity,ksppstvl,ksppstdf,
decode(bitand(ksppiflg/256,1),1,'TRUE','FALSE'),
decode(bitand(ksppiflg/65536,3),1,'IMMEDIATE',2,'DEFERRED',
3,'IMMEDIATE','FALSE'), decode(bitand(ksppstvf,7),1,'MODIFIED',4,'SYSTEM_MOD','FALSE'),
decode(bitand(ksppstvf,2),2,'TRUE','FALSE'), ksppdesc, ksppstcmnt
from x$ksppi x, x$ksppcv y
where (x.indx = y.indx);
decode(bitand(ksppiflg/256,1),1,'TRUE','FALSE'),
decode(bitand(ksppiflg/65536,3),1,'IMMEDIATE',2,'DEFERRED',
3,'IMMEDIATE','FALSE'), decode(bitand(ksppstvf,7),1,'MODIFIED',4,'SYSTEM_MOD','FALSE'),
decode(bitand(ksppstvf,2),2,'TRUE','FALSE'), ksppdesc, ksppstcmnt
from x$ksppi x, x$ksppcv y
where (x.indx = y.indx);
grant select on
my_v$parameter_with_hidden to rollingpig;
以 rollingpig 用户连接,创建同义词:
create synonym v$parameter for sys.
my_v$parameter_with_hidden ;
4。大功告成,测试一下吧
以rollingpig 用户登陆:
show parameter optimizer
SQL> show parameter optimizer
NAME TYPE VALUE
------------------------------------ -------------------------------- ------------------------------
_optimizer_adjust_for_nulls boolean TRUE
_optimizer_choose_permutation integer 0
_optimizer_cost_model string CHOOSE
_optimizer_degree integer 0
_optimizer_dyn_smp_blks integer 32
_optimizer_join_sel_sanity_check boolean FALSE
_optimizer_mode_force boolean TRUE
_optimizer_new_join_card_computation boolean TRUE
_optimizer_percent_parallel integer 101
_optimizer_search_limit integer 5
_optimizer_skip_scan_enabled boolean TRUE
_optimizer_sortmerge_join_enabled boolean TRUE
_optimizer_system_stats_usage integer 0
_optimizer_undo_changes boolean FALSE
_optimizer_undo_cost_change string 9.2.0.1
optimizer_dynamic_sampling integer 1
optimizer_features_enable string 9.2.0.1
optimizer_index_caching integer 0
optimizer_index_cost_adj integer 1
optimizer_max_permutations integer 2000
optimizer_mode string RULE
------------------------------------ -------------------------------- ------------------------------
_optimizer_adjust_for_nulls boolean TRUE
_optimizer_choose_permutation integer 0
_optimizer_cost_model string CHOOSE
_optimizer_degree integer 0
_optimizer_dyn_smp_blks integer 32
_optimizer_join_sel_sanity_check boolean FALSE
_optimizer_mode_force boolean TRUE
_optimizer_new_join_card_computation boolean TRUE
_optimizer_percent_parallel integer 101
_optimizer_search_limit integer 5
_optimizer_skip_scan_enabled boolean TRUE
_optimizer_sortmerge_join_enabled boolean TRUE
_optimizer_system_stats_usage integer 0
_optimizer_undo_changes boolean FALSE
_optimizer_undo_cost_change string 9.2.0.1
optimizer_dynamic_sampling integer 1
optimizer_features_enable string 9.2.0.1
optimizer_index_caching integer 0
optimizer_index_cost_adj integer 1
optimizer_max_permutations integer 2000
optimizer_mode string RULE
以"_"开头的隐含参数一个给跑出来了,optimizer开头的还真不少 :D
还有一些明显是测试用的hidden parameter
SQL> show parameter test
NAME TYPE VALUE
------------------------------------ -------------------------------- ------------------------------
_ipc_test_failover integer 0
_ipc_test_mult_nets integer 0
_test_ksusigskip integer 5
_test_param_1 integer 25
_test_param_2 string
_test_param_3 string
_test_param_4 string
_test_param_5 integer 25
_test_param_6 big integer 0
------------------------------------ -------------------------------- ------------------------------
_ipc_test_failover integer 0
_ipc_test_mult_nets integer 0
_test_ksusigskip integer 5
_test_param_1 integer 25
_test_param_2 string
_test_param_3 string
_test_param_4 string
_test_param_5 integer 25
_test_param_6 big integer 0
最后重申一点:
是在测试环境中玩,不要跑到生产环境里面中玩哦……
本文转自 牛海彬 51CTO博客,原文链接:http://blog.51cto.com/newhappy/76993,如需转载请自行联系原作者