ACCEPTMySchemaPROMPT'Enter schema to be analysed: '
settermoff
setfeedbackoff
droptableanalyze_strut_commands
createtableanalyze_strut_commands(
line_idnumber,
sql_textvarchar2(2000));
droptablefrag_stats_all
createtablefrag_stats_allas
select *
fromindex_stats
where1 = 2;
settermon
promptcreatingvalidationscripts ...
settermoff
declare
cursorind_curIS
selectowner
, index_name
fromdba_indexeswhereowner=upper('&&MySchema')
orderbyowner
, index_name;
l_sql_textvarchar2(500);
l_curr_line_idnumber(38) := NULL;
begin
declare
functionwrite_out(
p_line_idINNUMBER,
p_sql_textINVARCHAR2)returnNUMBER
is
l_line_idnumber(38) := null;
begin
insertintoanalyze_strut_commands
values(p_line_id,p_sql_text);
commit;
l_line_id := p_line_id + 1;
return(l_line_id);
endwrite_out;
begin
l_curr_line_id := write_out(1,'-- start');
forind_recinind_curLOOP
--
-- Firs get the prompts
--
l_sql_text := 'prompt ... processing index '||
ind_rec.owner||
'.'||
ind_rec.index_name||
' ...';
l_curr_line_id := write_out(l_curr_line_id,l_sql_text);
--
-- Second get the analyze commands
--
l_sql_text := 'analyze index '||
ind_rec.owner||
'.'||
ind_rec.index_name||
' validate structure;';
l_curr_line_id := write_out(l_curr_line_id,l_sql_text);
--
-- Third get the current statistics before it gets overwritten
--
l_sql_text := 'insert into frag_stats_all select * from index_stats;';
l_curr_line_id := write_out(l_curr_line_id,l_sql_text);
endloop;
--
-- commit the whole thing
--
l_curr_line_id := write_out(l_curr_line_id,'commit;');
end;
end;
/
setpages0
colsql_textformata132
selectsql_textfromanalyze_strut_commands
orderbyline_id
spoolind.tmp
/
spooloff
settermon
promptrunningvalidationscripts ...
@ind.tmp
droptableanalyze_strut_commands
/
!rmind.tmp
setpauseon;
pausePressanykeytoreviewtheresults
setpauseoff
SETVERIFYOFF
SETFEEDBACKOFF
COLnameHEA'Index Name'FORa30
COLdel_lf_rowsHEAd'Deleted|Leaf Rows'FOR99999999
COLlf_rows_usedHEA'Used|Leaf Rows'FOR99999999
COLratioHEAd'% Deleted|Leaf Rows'FOR999.99999
SETVERIFYON
SETFEEDBACKON
SELECT
name, del_lf_rows, lf_rows - del_lf_rowslf_rows_used,
DECODE(lf_rows,0,0,TO_CHAR(del_lf_rows / (lf_rows)*100,'999.99999'))ratio
FROM
frag_stats_all
ORDERBY
4
/
↧
Script to get the details about Index Fragmentation
↧