[20221101]完善gts.sql指令碼.txt
[20221101]完善gts.sql指令碼.txt
--//原始的tpt gts.sql指令碼 ,使用的是method_opt=>'FOR TABLE FOR ALL COLUMNS SIZE 1',實際上導致我在分析生產系統時清除了一些欄位
--//的直方圖資訊,導致出現嚴重效能問題.我修改為method_opt=>'FOR TABLE FOR ALL COLUMNS SIZE REPEAT'.
--//而且對方版本僅僅分析當前schema下的表,我決定嘗試做一些改動更加靈活一些.
$ cat gts.sql
-- Copyright 2018 Tanel Poder. All rights reserved. More info at
-- Licensed under the Apache License, Version 2.0. See LICENSE.txt for terms & conditions.
set verify off
set termout off
column xx format a60 new_value xx
column xy format a60 new_value xy
select decode(upper('&&2'),'','REPEAT','R','REPEAT','A','AUTO','&&2') xx from dual;
select decode(upper('&&3'),'','NULL','AUTO','sys.dbms_stats.auto_sample_size','A','sys.dbms_stats.auto_sample_size','&&3') xy from dual;
column v_owner new_value v_owner
column v_table new_value v_table
select
upper(CASE
WHEN INSTR('&1','.') > 0 THEN
SUBSTR('&1',INSTR('&1','.')+1)
ELSE
'&1'
END
) v_table,
nvl(upper(CASE WHEN INSTR('&1','.') > 0 THEN
UPPER(SUBSTR('&1',1,INSTR('&1','.')-1))
ELSE
user
END),user) v_owner
from dual;
set termout on
prompt
prompt @ gts table_name <method_opt> <estimate_percent>
prompt method_opt accept R or r => REPEAT , A or a => auto
prompt estimate_percent accept "" => NULL , AUTO or A or auto or a=> sys.dbms_stats.auto_sample_size
prompt flush database monitoring info;
prompt execute dbms_stats.flush_database_monitoring_info;
prompt
prompt lock and unlock
prompt execute sys.dbms_stats.lock_table_stats (ownname => 'v_owner',tabname => 'v_table');
prompt execute sys.dbms_stats.unlock_table_stats (ownname => 'v_owner',tabname => 'v_table');
prompt
prompt estimate_percent : sys.dbms_stats.auto_sample_size n 1-100
prompt block_sample : false true
prompt method_opt : for all columns size [auto|repeat|1-254]
prompt method_opt : for all hidden columns size repeat
prompt method_opt : for all columns size 1 for columns xx size 254
prompt methid_opt : for all indexed columns size repeat
prompt
prompt cascade : true false
prompt
prompt No_Invalidate : false true dbms_stats.auto_invalidate
prompt
prompt delete table stats
prompt execute sys.dbms_stats.delete_table_stats ('&v_owner', '&v_table',cascade_columns=> false,cascade_indexes=> false,cascade_parts=>false,no_invalidate=> false);
prompt
prompt Gather Table Statistics for table &1....
prompt exec dbms_stats.gather_table_stats('&v_owner', '&v_table', estimate_percent => &xy, method_opt=>'FOR TABLE FOR ALL COLUMNS SIZE &xx', cascade=>true, no_invalidate=>false);
prompt if lock table &1, add force=>true.
prompt
pause press ctrl+c cancel, enter continue...
exec dbms_stats.gather_table_stats('&v_owner', '&v_table', estimate_percent => &xy, method_opt=>'FOR TABLE FOR ALL COLUMNS SIZE &xx', cascade=>true, no_invalidate=>false);
column xx clear
column xy clear
--//這樣可以完全不使用gtsh.sql指令碼.測試例子如下:
@gts emp 1 ''
@gts emp R 100
@gts emp R ''
@gts emp repeat ''
@gts emp auto ''
@gts emp 254 ''
@gts emp 1024 ''
@gts scott.emp 1 ''
@gts scott.emp "1 for columns sal size 14" a
@gts emp 2048 ''
@gts emp 2049 ''
SCOTT@test01p> @gts1 emp 2049
Gather Table Statistics for table emp...
exec dbms_stats.gather_table_stats('SCOTT', 'EMP', null, method_opt=>'FOR TABLE FOR ALL COLUMNS SIZE 2049', cascade=>true, no_invalidate=>false)
press ctrl+c cancel, enter continue...
BEGIN dbms_stats.gather_table_stats('SCOTT', 'EMP', null, method_opt=>'FOR TABLE FOR ALL COLUMNS SIZE 2049', cascade=>true, no_invalidate=>false); END;
*
ERROR at line 1:
ORA-20000: Cannot parse for clause: FOR TABLE FOR ALL COLUMNS SIZE 2049
ORA-06512: at "SYS.DBMS_STATS", line 36873
ORA-06512: at "SYS.DBMS_STATS", line 36507
ORA-06512: at "SYS.DBMS_STATS", line 35428
ORA-06512: at "SYS.DBMS_STATS", line 21023
ORA-06512: at "SYS.DBMS_STATS", line 35009
ORA-06512: at "SYS.DBMS_STATS", line 36230
ORA-06512: at "SYS.DBMS_STATS", line 36716
ORA-06512: at line 1
--//目前12c以上版本可以支援2048 bucket.
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/267265/viewspace-2921613/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- [20221101]完善descz.sql指令碼.txtSQL指令碼
- [20220217]完善tpt gts.sql指令碼.txtSQL指令碼
- [20210506]完善tix指令碼.txt指令碼
- [20201202]完善sosi指令碼.txt指令碼
- [20210623]完善清除aud指令碼.txt指令碼
- [20231117]完善ashtt.sql指令碼.txtSQL指令碼
- [20211230]完善sql_id指令碼.txtSQL指令碼
- [20211122]完善descx.sql指令碼.txtSQL指令碼
- [20221012]完善spsw.sql指令碼.txtSQL指令碼
- [20221010]完善descz.sql指令碼.txtSQL指令碼
- [20230203]完善awr.sql指令碼.txtSQL指令碼
- [20230123]完善curheapz.sql指令碼.txtSQL指令碼
- [20210407]完善ti.sql指令碼.txtSQL指令碼
- [20210125]完善hide.sql指令碼.txtIDESQL指令碼
- [20191111]完善bind_cap.sql指令碼.txtSQL指令碼
- [20220510]完善tpt expandz.sql指令碼.txtSQL指令碼
- [20211202]完善d_buffer.sql指令碼.txtSQL指令碼
- [20211129]完善tpt tablist.sql指令碼.txtSQL指令碼
- [20211130]完善tpt t.sql指令碼.txtSQL指令碼
- [20211129]完善tpt killi.sql指令碼.txtSQL指令碼
- [20211126]完善tpt pr.sql指令碼.txtSQL指令碼
- [20230414]完善seg2.sql指令碼.txtSQL指令碼
- [20230210]建立完善swcnm.sql指令碼.txtSQL指令碼
- [20221208]完善bind_cap.sql指令碼.txtSQL指令碼
- [20220311]完善ash_wait_chains指令碼.txtAI指令碼
- [20220309]完善shp4.sql指令碼.txtSQL指令碼
- [20231025]完善tpt的trans.sql指令碼.txtSQL指令碼
- [20241114]建立完善ext_kglob.sh指令碼.txt指令碼
- [20220111]完善tpt ashash_index_helper指令碼.txtIndex指令碼
- [20220323]完善tpt get_trace.sql指令碼.txtSQL指令碼
- [20220823]完善tpt的ashtop.sql指令碼.txtSQL指令碼
- [20221208]完善bind_cap_awr.sql指令碼.txtSQL指令碼
- [20190416]完善shared latch測試指令碼2.txt指令碼
- [20220129]完善tpt ash ash_index_helperx指令碼.txtIndex指令碼
- [20211111]補充完善ash_wait_chains指令碼.txtAI指令碼
- [20230302]建立完善tpt o2.sql指令碼.txtSQL指令碼
- [20230203]建立完善sp1x.sql指令碼.txtSQL指令碼
- [20220519]完善tpt dash_wait_chains2.sql指令碼.txtAISQL指令碼