Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
Document Détails
Account LDC
Current Version
Revision History
Date of Reviewed
Version Description Author Approved By
Revision By
Here are Some of the Queries to keep Handy for troubleshooting when we have high load issues and
need to capture all details as mentioned below.
This version will help in finding the table with STALE stats AND gives you the command to collect the
stale stats for (Table without partition & Table with Partitions).
uptime
2) Get Active query with high number of sessions and running long time by looking at
max(last_call_et) , Target for SQLID with high number of sessions first and secondly
max(last_call_et)
3) All waits for the issue Query – check for latches which causes system slowness
Or
From History – if above does not work
SELECT SQL_TEXT FROM DBA_HIST_SQLTEXT WHERE SQL_ID='&sqlid';
5) Get Query current statistics like current plan, buffer gets / Version count / no of executions /
Invalidations
SELECT
sql_id,plan_hash_value,hash_value,buffer_gets,DISK_READS,rows_processed,executions,elapse
d_Time / (1000000 * decode(executions,0,1, executions) ) etime_per_exec,
LOADS,INVALIDATIONS,PARSE_CALLS,LOADED_VERSIONS,VERSION_COUNT,(cpu_time/1000000
)/60 "CPU time In Mins"
FROM v$sqlarea
WHERE sql_id = '&SQL_ID';
OR
SELECT
sql_id,plan_hash_value,hash_value,buffer_gets,DISK_READS,rows_processed,executions,elapse
d_Time / (1000000 * decode(executions,0,1, executions) ) etime_per_exec,
LOADS,INVALIDATIONS,PARSE_CALLS,LOADED_VERSIONS,(cpu_time/1000000)/60 "CPU time In
Mins"
FROM v$sql
WHERE sql_id = '&SQL_ID';
6) Monitor the SQLID if it’s completed successfully or completed with error ,below shows SQL
start time and what Plan value was used.
BEGIN
FOR r IN (SELECT address,
hash_value
FROM v$sqlarea
WHERE sql_id ='&SQL_ID')
LOOP
sys.dbms_shared_pool.purge(r.address || ',' || r.hash_value, 'C');
END LOOP;
END;
/
(b) Copy the required plan to text file plan.txt to find required tables/indexes used by the query
as below.
(c) Find tables from plan.txt : !cat plan.txt |grep -i table|cut -d'|' -f4|sort|uniq|awk '{print
"["$1"[,"}' |sed "s/\[/\'/g"
Find indexes from plan.txt : !cat plan.txt |grep -i index|cut -d'|' -f4|sort|uniq |awk
'{print "["$1"[,"}' |sed "s/\[/\'/g"
OR
(d) Now use the table name and index names to check stats update time and if they are Stale
12) Gather Stats for the Stale Tables ,below will generate commands to collect stats
Note : if table have partitions, then they need to separately collect stats, so select the below
command accordingly.
select 'exec
DBMS_STATS.GATHER_TABLE_STATS(ownname=>'''||OWNER||''',tabname=>'''||TABLE_NAME
||''',estimate_percent=>dbms_stats.auto_sample_size,degree=>'||DECODE(TRUNC(DECODE(NV
L(num_rows,0),0,1,num_rows)/250000),0,1,4)||',cascade=>TRUE);' output
from dba_tab_statistics
where upper(owner)=upper('EUSFV4_TELUSP')
and TABLE_NAME in
(
'JBM_MSG_REF',
'JBM_MSG'
)
AND STALE_STATS='YES'
and PARTITION_NAME is null
order by table_name;
select
INDEX_OWNER,INDEX_NAME,PARTITION_NAME,SUBPARTITION_COUNT,LAST_ANALYZED,STAT
US from dba_ind_partitions where INDEX_OWNER=upper('&owner') and status <> 'USABLE';
@$ORACLE_HOME/rdbms/admin/sqltrpt.sql
(a)
set long 1000000000
set pages 0
spool sqlmon.html
select
DBMS_SQLTUNE.REPORT_SQL_MONITOR(sql_id=>'&sqlid',session_id=>&SID,session_serial=>&SRLN
O,type=>'HTML') as report
from dual;
spool off
(A) History
set linesize 200
col VALUE format a30
col BEGIN_INTERVAL_TIME for a30
col PARAMETER_NAME for a18
set line 200
select p.SNAP_ID,t.BEGIN_INTERVAL_TIME,p.PARAMETER_NAME,p.VALUE/1024/1024 "MB"
,p.VALUE/1024/1024/1024 "GB"
from DBA_HIST_PARAMETER p,DBA_HIST_SNAPSHOT t
where p.SNAP_ID=t.SNAP_ID
and p.PARAMETER_NAME in ('db_cache_size','shared_pool_size')
order by p.SNAP_ID,p.PARAMETER_NAME;
The output from the script is shown below. The values range from ten percent of the current size to
double the current size of the db_cache_size.
Estd Phys Estd Phys
Cache Size (meg) Buffers Read Factor Reads
---------------- ------------ ----------- -------------------
1,536 189,384 8.97 592,735,205,16
10% Size
3,072 378,768 7.41 489,705,479,65
4,608 568,152 5.87 388,170,249,59
6,144 757,536 4.70 310,600,273,49
7,680 946,920 3.72 246,154,829,53
9,216 1,136,304 2.94 193,988,318,54
10,752 1,325,688 2.30 151,783,912,70
12,288 1,515,072 1.79 118,600,852,23
13,824 1,704,456 1.41 93,101,898,84
15,360 1,893,840 1.11 73,482,050,46
16,128 1,988,532 1.00 66,095,324,29
Current Size = 15744 MB => from above step B
16,896 2,083,224 .89 58,648,599,72
18,432 2,272,608 .72 47,531,212,36
19,968 2,461,992 .59 39,291,898,81
21,504 2,651,376 .51 33,384,465,72
23,040 2,840,760 .44 29,018,921,05
24,576 3,030,144 .39 25,837,395,19
26,112 3,219,528 .35 23,435,255,12
27,648 3,408,912 .33 21,585,740,14
29,184 3,598,296 .30 20,112,622,31
30,720 3,787,680 .29 18,881,183,78
<== 2x size
21 rows selected.
From the above listing, it is clear that increasing the db_cache_size from 16,128
MB to 16,896 MB would result in approximately 744,672,457 less physical reads.
http://www.toadworld.com/platforms/oracle/w/wiki/619.monitoring-pga-in-10g.aspx
NAME In MB In
GB
---------------------------------------------------------------- ---------- -------
---
aggregate PGA target
parameter 20480 20 show
parameter pga
aggregate PGA auto
target 17229.93 16.83
total PGA
inuse 1398.87 1.37
total PGA
allocated 2587.91 2.53
check advisory below
Cache hit
As a rule of thumb, the PGA cache hit percentage should be higher than 60%
NAME VALUE
---------------------------------------- --------------------
over allocation count 0
extra bytes read/written 6,704,489,669,632
cache hit percentage 99
14 rows selected.
In our example, values of more than 5120MB are useless, because there is no increase in the
ESTD_PGA_CACHE_HIT_PERCENTAGE field even if we increase the PGA size (we have already reached 100
percent, so using more memory won't get a further performance increase).
Shared Pool Size (MB) Size Factor Estimated Hits in Library Cache Estimate of LC
Size Estimate of objects in LC
--------------------- ----------- ------------------------------- -----------------
-- -------------------------
28,160 .898 69,864,719 1,8
22 99,988
30,080 .9592 81,836,886 3,7
41 179,461
30,208 .9633 81,985,740 3,8
69 185,248
30,336 .9673 82,126,659 3,9
97 189,291
30,464 .9714 82,261,653 4,1
25 192,902
30,592 .9755 82,392,730 4,2
53 197,185
30,720 .9796 82,520,736 4,3
81 199,909
30,848 .9837 82,655,962 4,5
09 202,193
30,976 .9878 82,796,661 4,6
37 204,447
31,104 .9918 82,927,747 4,7
65 206,867
31,232 .9959 83,053,927 4,8
93 209,801
31,360 1 83,888,119 5,0
21 213,067
31,488 1.0041 89,962,222 5,1
49 217,208
31,616 1.0082 90,073,373 5,2
77 221,543
31,744 1.0122 90,186,362 5,4
05 224,817
31,872 1.0163 90,295,508 5,5
33 228,517
32,000 1.0204 90,403,624 5,6
61 231,185
32,128 1.0245 90,507,787 5,7
89 234,425
32,256 1.0286 90,608,720 5,9
17 238,489
32,384 1.0327 90,708,166 6,0
45 243,556
32,512 1.0367 90,805,539 6,1
73 249,408
34,560 1.102 92,182,844 8,2
20 350,413
37,760 1.2041 93,605,210 11,4
19 433,775
40,960 1.3061 94,550,985 14,6
18 522,518
44,160 1.4082 95,268,724 17,8
18 639,147
47,360 1.5102 95,781,636 21,0
18 816,789
50,560 1.6122 96,098,928 24,2
18 920,414
53,760 1.7143 96,341,747 27,4
18 1,044,496
56,960 1.8163 96,574,858 30,6
18 1,142,128
60,160 1.9184 96,825,961 33,8
18 1,188,217
63,360 2.0204 97,072,213 37,0
18 1,257,187
31 rows selected.
http://www.oracle.com/technetwork/issue-archive/2012/12-nov/o62dba-1741123.html
Bind Peeking
Values of bind variable inspected on hard parse
Subsequent executions use the same plan
If selective value first, subsequent executions may use innapropriate index
If non selective value first, subsequent executions may full scan
Set _optim_peek_user_binds to FALSE