The following two scripts, official sources:
https://github.com/liangjingbin99/shouhuo/tree/master/%E7%AC%AC05%E7%AB%A0
1. Find an unused bind variables in SQL
The method of the book, a table is built, it is more similar to the SQL unused bind variables, like parts replaced by @, and then extract the same packet, in order to identify unused binding of the SQL variables, as follows,
drop table t_bind_sql purge;
create table t_bind_sql as select sql_text,module from v$sqlarea;
alter table t_bind_sql add sql_text_wo_constants varchar2(1000);
create or replace function
remove_constants( p_query in varchar2 ) return varchar2
as
l_query long;
l_char varchar2(10);
l_in_quotes boolean default FALSE;
begin
for i in 1 .. length( p_query )
loop
l_char := substr(p_query,i,1);
if ( l_char = '''' and l_in_quotes )
then
l_in_quotes := FALSE;
elsif ( l_char = '''' and NOT l_in_quotes )
then
l_in_quotes := TRUE;
l_query := l_query || '''#';
end if;
if ( NOT l_in_quotes ) then
l_query := l_query || l_char;
end if;
end loop;
l_query := translate( l_query, '0123456789', '@@@@@@@@@@' );
for i in 0 .. 8 loop
l_query := replace( l_query, lpad('@',10-i,'@'), '@' );
l_query := replace( l_query, lpad(' ',10-i,' '), ' ' );
end loop;
return upper(l_query);
end;
/
update t_bind_sql set sql_text_wo_constants = remove_constants(sql_text);
commit;
Next, the following manner can be quickly positioned:
SET LINESIZE 266
COL sql_text_wo_constants the format A30
COL Module1 the format A30
COL the format the CNT 999999
SELECT sql_text_wo_constants, Module1, COUNT (*) the CNT
from t_bind_sql group by sql_text_wo_constants,module
having count(*) > 100 order by 3 desc;
Results of the,
When we do SQL audit, in another way, according to v $ sql in exact_matching_signature and force_matching_signature, to determine whether the use of bind variables,
select a.username,
t.sql_text,
to_char(t.force_matching_signature) as force_matching_signature,
count(*) as counts
from v$sql t, all_users a
where t.force_matching_signature > 0 and
t.parsing_user_id = a.user_id and
t.force_matching_signature <> t.exact_matching_signature
group by t.force_matching_signature, t.sql_text, a.username
having count(*) > 20
order by count(*) desc;
2. Determine the peak of database scripts
This script can regularly check the dimensions of the system, to determine the peak point in time the database has played a guiding role.
The official script there is a little mistake, it should be a typo, you can see that running, I updated edition,
https://github.com/bisal-liu/oracle/blob/master/tools/monitor_database.sql
The results are in accordance with the hours saved, including DB Time, REDO amount of logic to read (/ s), the physical read (/ s), the execution count (/ s), parsing the number (/ s), hard parse times (/ s ), volume (/ s), the basic outline of the report is the AWR and content Load Profile section, in fact, from the SQL view, is the statistics from dba_hist_snapshot, instructions are available from AWR snapshot library,
History article:
"" Harvest, more than SQL optimization "- the tuning information in a key generation script learning"
"" Harvest, more than SQL optimization "- Get the Plan of Implementation of the comparative
method" ----------------
Copyright: Original article is CSDN blogger "bisal", and follow CC 4.0 BY-SA copyright agreement, reproduced, please attach the original source link and this statement.
Original link: https: //blog.csdn.net/bisal/article/details/88840385