Documente Academic
Documente Profesional
Documente Cultură
SELECTb.usernameusername,
a.disk_readsreads,
a.executionsexec,
a.disk_reads/DECODE(a.executions,0,1,a.executions)
rds_exec_ratio,
a.sql_textstatement
FROMv$sqlareaa,dba_usersb
WHEREa.parsing_user_id=b.user_idANDa.disk_reads>100000
ORDERBYa.disk_readsDESC
The DISK_READS column in the preceding statement can be replaced with the BUFFER_GETS column
to provide information on SQL statements requiring the largest amount of memory.
Now consider the output in a second example where there is a count of a billion-row table
(EMP3) and a count of what was originally a 130M row table (EMP2), where all of the rows in
EMP2, except the first 15 rows inserted, were deleted. Note that Oracle counts all the way
up to the high water mark (HWM) of EMP2 (it read over 800,000, 8K blocks even though all of
the data was only in 1 block). This listing would have told you something is wrong with the
query on EMP2 that needs to be addressed, given that it only has 15 rows in it (analyzing
the table will not improve this).
SELECT*
FROM(SELECTaddress,
RANK()OVER(ORDERBYbuffer_getsDESC)ASrank_bufgets,
TO_CHAR(100*ratio_to_report(buffer_gets)OVER(),
'999.99')
pct_bufgets
FROMv$sql)
WHERErank_bufgets<11;
AlternativelytogetSQL
/*Formattedon5/22/201311:15:38AM(QP5v5.115.810.9015)*/
SELECT*
FROM(SELECTsql_text,
RANK()OVER(ORDERBYbuffer_getsDESC)ASrank_bufgets,
TO_CHAR(100*ratio_to_report(buffer_gets)OVER(),
'999.99')
pct_bufgets
FROMv$sql)
WHERErank_bufgets<11;
/*Formattedon5/22/201311:23:30AM(QP5v5.115.810.9015)*/
SELECTTO_CHAR(m.end_time,'DDMONYYYYHH24:MI:SS')e_dttm,
m.intsize_csec/100ints,
s.usernameusr,
m.session_idsid,
m.session_serial_numssn,
ROUND(m.cpu)cpu100,
m.physical_readsPrds,
m.logical_readslrds,
m.hard_parseshp,
m.soft_parsessp,
m.physical_read_pctprp,
m.logical_read_pctlrp,
s.sql_id
FROMv$sessmetricm,v$sessions
WHERE(m.physical_reads>100ORm.cpu>100ORm.logical_reads>100)
ANDm.session_id=s.sid
ANDm.session_serial_num=s.serial#
ORDERBYm.physical_readsDESC,m.cpuDESC,m.logical_readsDESC
Note that in the output, the same SQL_ID appears in three different AWR snapshots. (In this
case, it was executed during the first one and is still running). You could also choose to
filter on other criteria, including cumulative or delta values for DISK_READS, BUFFER_GETS,
ROWS_PROCESSED, CPU_TIME, ELAPSED_TIME, IOWAIT, CLWAIT (cluster wait), and so on. Run a DESC
command of the view DBA_HIST_SQLSTAT to get a full list of its columns. This listing shows
different SQL_IDs at the top of the list.
To query DBA_HIST_SQLTEXT:
SELECTcommand_type,sql_text
FROMdba_hist_sqltext
WHEREsql_id='1p5gnckn8s6gv'
Selecting Query EXPLAIN PLAN from the DBA_HIST_SQL_PLAN View
The EXPLAIN PLAN for the offending SQL is also captured. You may view information about the
execution plan through the DBA_HIST_SQL_PLAN view. If you want to display the EXPLAIN PLAN,
the simplest way is to use the DBMS_XPLAN package with a statement such as this one:
select*fromtable(DBMS_XPLAN.DISPLAY_AWR('f3g2hz7dpfy1t'));
SQL> /
PLAN_TABLE_OUTPUT
-----------------------------------------------------------------------------------
SQL_ID f3g2hz7dpfy1t
--------------------
DELETE FROM FND_LOG_MESSAGES FLM WHERE FLM.LOG_SEQUENCE=:B1 AND NOT
EXISTS (SELECT NULL FROM FND_LOG_EXCEPTIONS FLE WHERE FLE.LOG_SEQUENCE
= FLM.LOG_SEQUENCE )
Plan hash value: 3090450985
----------------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
-----------------------------------------------------------------------------------
PLAN_TABLE_OUTPUT
-----------------------------------------------------------------------------------
| 0 | DELETE STATEMENT | | | | 4 (100)| |
| 1 | DELETE | FND_LOG_MESSAGES | | | | |
| 2 | NESTED LOOPS ANTI| | 1 | 184 | 4 (0)| 00:00:01 |
| 3 | INDEX RANGE SCAN| FND_LOG_MESSAGES_N5 | 1 | 177 | 4 (0)| 00:00:01 |
| 4 | INDEX RANGE SCAN| FND_LOG_EXCEPTIONS_N3 | 1 | 7 | 0 (0)| |
--------------------------------------------------------------------------------------------
select/*+richs_secret_hint*/ename,jobfromscott.empwheredeptno=10andename='CLARK'
selectename,jobfromscott.empwheredeptno=10andename='CLARK'
createindexdept_idx1onscott.emp(deptno)tablespaceusersstorage(initial20Mnext5M
pctincrease0)
dropindexdept_idx1;
createindexemp_idx1onscott.emp(deptno,ename)tablespaceusersstorage(initial20Mnext
5Mpctincrease0)
select*fromv$sqlwheresql_textlike'%deptno%'andsql_id
in('2v0ntfhzwn2xf','d5thrrkvn8wmu','21rdq0js36ag4','0varr2r8cbt8r')
selectaddressfromv$sqlareawheresql_id
in('2v0ntfhzwn2xf','d5thrrkvn8wmu','21rdq0js36ag4','0varr2r8cbt8r')
ADDRESS
00000001AE820800
00000001AB781740
00000001ADF7AAF0
00000001AE8F6EE8
selectADDRESS,HASH_VALUEfromV$SQLAREAwhereSQL_IDin
('2v0ntfhzwn2xf','d5thrrkvn8wmu','21rdq0js36ag4','0varr2r8cbt8r')
ADDRESSHASH_VALUE
execDBMS_SHARED_POOL.PURGE('00000001AE820800,1070205870','C')
execDBMS_SHARED_POOL.PURGE('00000001AB781740,3074716282','C')
execDBMS_SHARED_POOL.PURGE('00000001ADF7AAF0,1882401252','C')
execDBMS_SHARED_POOL.PURGE('00000001AE8F6EE8,3502630167','C')
selectADDRESS,HASH_VALUEfromV$SQLAREAwhereSQL_IDin
('2v0ntfhzwn2xf','d5thrrkvn8wmu','21rdq0js36ag4','0varr2r8cbt8r')
/*+ result_cache */
To check INACTIVE sessions with HIGH DISK IO
*Formattedon5/23/201312:26:10PM(QP5v5.115.810.9015)*/
SELECTp.spid,
s.username,
s.sid,
s.status,
t.disk_reads,
s.last_call_et/3600last_call_et_Hrs,
s.action,
s.program,
s.machinecli_mach,
s.processcli_process,
LPAD(t.sql_text,30)"LastSQL"
FROMgv$sessions,gv$sqlareat,v$processp
WHEREs.sql_address=t.address
ANDs.sql_hash_value=t.hash_value
ANDp.addr=s.paddr
ANDt.disk_reads>5000
ANDs.status='INACTIVE'
ANDs.process='1234'
SELECTp.spid,
s.sid,
s.processcli_process,
s.status,
t.disk_reads,
s.last_call_et/3600last_call_et_Hrs,
s.action,
s.program,
LPAD(t.sql_text,30)"LastSQL"
FROMv$sessions,v$sqlareat,v$processp
WHEREs.sql_address=t.address
ANDs.sql_hash_value=t.hash_value
ANDp.addr=s.paddr
ANDt.disk_reads>10000
ORDERBYt.disk_readsDESC;
select event,count(event) "LATCH_COUNT" from v$session_wait having count(event)> 2 and event like '%latch%' group by
event;
COMPREHENSIVE
Oracle 11g Automatic SQL Tuning
Oracle Database 10g introduced the SQL Tuning Advisor to help DBAs and developers improve
the performance of SQL statements. The Automatic SQL Tuning Advisor includes statistics
analysis, SQL profiling, access path analysis, and SQL structure analysis, and can be
performed through the SQL Tuning Advisor. The SQL Tuning Advisor uses input from the ADDM,
from resource-intensive SQL statements captured by the AWR, from the cursor cache, or from
SQL Tuning Sets. Oracle 11g has extended the SQL Tuning Advisor by adding additional
features such as SQL Replay, Automatic SQL Tuning, SQL Statistics Management, and SQL Plan
Management. Since this chapter is focused on query tuning, Ill describe how to pass
specific SQL to the SQL Tuning Advisor in the form of a SQL Tuning Set, and then Ill cover
11gs Automatic SQL Tuning Advisor and SQL Performance Analysis (SQL Replay).The Oracle
recommended interface for the SQL Tuning Advisor is Oracle Enterprise Manager (see Chapter
5), but you can use the APIs via the command line in SQL*Plus. I cover the command-line
session so you can better understand the analysis procedure for a single query. This section
is only a small glance into the functionality of the SQL Tuning Advisor. You also have the
capability to create SQL Tuning Sets and SQL profiles as well as the ability to transport
SQL Tuning Sets from one database to another.
Troubleshooting BUFFER BUSY WAITS
Note:
This wait indicates that there are some buffers in the buffer cache that multiple processes
are attempting to access concurrently. Query V$WAITSTAT for the wait statistics for each
class of buffer. Common buffer classes that have buffer busy waits include data block,
segment header, undo header, and undo block.
TYPE_OF_SEGMENT_CONTENDED_FOR
SELECT class, count FROM V$WAITSTAT WHERE count > 0 ORDER BY count DESC;
SELECT count(*), event FROM v$session_wait WHERE wait_time = 0 AND event NOT IN ('smon
timer','pmon timer','rdbms ipc message','SQL*Net message from client') GROUP BY event ORDER
BY 1
DESC;
To find Wait event Most of the time the session waited for
Wait events
Sessions having Wait Event "sql*net message from client" from more than 1Hour
select s.sid,s.process,S.STATUS,s.program,s.module,s.sql_hash_value,s.last_call_et/3600
Last_Call_Et_HRS
from v$session s, v$session_Wait w
where w.sid=s.sid and w.event='SQL*Net message from client'
and s.module='&Module_name'
order by 6 desc;
Segment Statistics
select
object_name,
statistic_name,
value
from
V$SEGMENT_STATISTICS
where object_name ='SOURCE$';
V$SYSTEM_EVENT
Note:
This event signifies that the user process is reading buffers into the SGA buffer cache and is waiting for a physical I/O call to
return. A db file scattered read issues a scatter-read to read the data into multiple discontinuous memory locations. A
scattered read is usually a multiblock read. It can occur for a fast full scan (of an index) in addition to a full table scan.
The db file scattered read wait event identifies that a full table scan is occurring. When performing a full table scan into the
buffer cache, the blocks read are read into memory locations that are not physically adjacent to each other. Such reads are
called scattered read calls, because the blocks are scattered throughout memory. This is why the corresponding wait event is
called 'db file scattered read'. Multiblock (up to DB_FILE_MULTIBLOCK_READ_COUNT blocks) reads due to full table scans
into the buffer cache show up as waits for 'db file scattered read'.
DB_FILE_SCATTERED_READ_WAIT_DETAIL:
select event,count(event) "LATCH_COUNT" from v$session_wait having count(event)> 2 and event like '%latch%' group by
event;