--Query for the slowest SQL
SELECT * FROM (
Select Parsing_user_id,executions,sorts
Command_type,disk_reads,sql_text from V$sqlarea ORDER BY disk_reads Desc
) Where rownum<10
--Query corresponding session
Select SE. Sid,se. Serial#,pr. SPID,
SE. Username,se. Status,se. TERMINAL,
SE. Program,se. MODULE,
SE. Sql_address,st. EVENT,
St. P1text,si. Physical_reads,si. Block_changes from V$session Se,v$session_wait St,
V$sess_io si,v$process PR
Where St. Sid=se. SID and St. Sid=si. Sid
and SE. Paddr=pr. ADDR
and SE. Sid>6
and ST. Wait_time=0
and ST. EVENT not like '%sql% '
ORDER by Physical_reads DESC;
SELECT sql_address from V$session ss,v$sqltext TT
WHERE SS. Sql_hash_value=tt. Hash_value and sid=439;
V$sqltext: The stored full sql,sql is split
V$sqlarea: Stored SQL and some related information, such as the cumulative number of executions, logical reading, physical reading and other statistical information (statistics)
V$sql: A SQL statement that has been resolved in a memory-shared SQL zone. Instant
To find the full SQL statement based on the SID:
Select Sql_text from V$sqltext a WHERE A.hash_value = (select Sql_hash_value from v$session b where b.sid = ' &sid ' )
ORDER BY piece ASC
Select A.cpu_time,--CPU time one out of 10,000 (microseconds)
A.optimizer_mode,--Optimization method
A.executions,--Execution times
A.disk_reads,--Read Disk count
A.sharable_mem,--The amount of memory occupied by the shared pool
A.buffer_gets,--The number of read buffers
A.command_type,--Command Type (3:select,2:insert;6:update;7delete;47:pl/sql program unit)
A.sql_text,--SQL Statements
A.sharable_mem,
A.persistent_mem,
A.runtime_mem,
A.parse_calls,
A.disk_reads,
A.direct_writes,
A.concurrency_wait_time,
A.user_io_wait_time
From SYS. V_$sqlarea A
WHERE parsing_schema_name = ' chea_fill '--table space
ORDER BY a.cpu_time Desc
Reference: http://jenniferok.iteye.com/blog/700985
Query the most resource-intensive query from V$sqlarea Select B.username username,a.disk_reads reads,
A.executions Exec,a.disk_reads/decode (a.executions,0,1,a.executions) Rds_exec_ratio,
A.sql_text Statement
From V$sqlarea A,dba_users b
where a.parsing_user_id=b.user_id
and A.disk_reads > 100000
ORDER BY a.disk_reads Desc; Replacing the disk_reads column with the buffer_gets column gives you information about the SQL statement that consumes the most memory. V$sql: A SQL statement that has been resolved in a memory-shared SQL zone. Instant
List the 5 most frequently used queries: select Sql_text,executions
From (select Sql_text,executions,
Rank () over
(Order BY executions Desc) Exec_rank
From V$sql)
Where Exec_rank <=5; consumes disk reads the most SQL TOP5:
Select Disk_reads,sql_text
From (select Sql_text,disk_reads,
Dense_rank () over
(Order BY disk_reads Desc) Disk_reads_rank
From V$sql)
where Disk_reads_rank <=5;
Find queries that require a large buffer read (logical read) operation: Select Buffer_gets,sql_text
From (select Sql_text,buffer_gets,
Dense_rank () over
(Order BY buffer_gets Desc) Buffer_gets_rank
From V$sql)
where buffer_gets_rank<=5; V$sqlarea Field Definition: http://happyhou.blog.sohu.com/60494432.html
SQL_TEXT |
VARCHAR2(1000) |
The first 1000 characters of a SQL literal |
SQL_ID |
VARCHAR2(13) |
SQL identifier of the parent cursor in the library cache |
SHARABLE_MEM |
NUMBER |
Shared memory size (in bytes) |
PERSISTENT_MEM |
NUMBER |
Fixed memory size (in bytes) for the lifetime |
RUNTIME_MEM |
NUMBER |
Fixed memory size during the execution period |
SORTS |
NUMBER |
Number of orders completed |
VERSION_COUNT |
NUMBER |
Number of child cursors that is present in the cache under this parent |
LOADED_VERSIONS |
NUMBER |
Shows whether the context heap is loaded, 1 is 0 no |
OPEN_VERSIONS |
NUMBER |
Shows if the child cursor is locked, 1 is 0 no |
USERS_OPENING |
NUMBER |
Number of users executing the statement |
FETCHES |
NUMBER |
The number of fetch for the SQL statement. |
EXECUTIONS |
NUMBER |
Number of executions since it was loaded into the cache library |
END_OF_FETCH_COUNT |
NUMBER |
Number of times this cursor is fully executed since the cursor is brought into the library cache. The value of this statistic isn't incremented when the cursor is partially executed, either because it failed during the Execution or because only the first few rows produced by this cursor be fetched before the cursor is closed or re-execute D. By definition, the value of the END_OF_FETCH_COUNT column should is less or equal to the value of the EXECUTIONS column. |
USERS_EXECUTING |
NUMBER |
Number of users executing the statement |
LOADS |
NUMBER |
Number of times the object has been loaded |
FIRST_LOAD_TIME |
VARCHAR2(19) |
Initial loading time |
INVALIDATIONS |
NUMBER |
Invalid number of times |
PARSE_CALLS |
NUMBER |
Number of calls resolved |
DISK_READS |
NUMBER |
Number of Read disks |
DIRECT_WRITES |
NUMBER |
Sum of the number of direct writes over all child cursors |
BUFFER_GETS |
NUMBER |
Number of Read buffers |
APPLICATION_WAIT_TIME |
NUMBER |
Application Wait Time |
CONCURRENCY_WAIT_TIME |
NUMBER |
Concurrency Wait Time |
CLUSTER_WAIT_TIME |
NUMBER |
Cluster Wait Time |
USER_IO_WAIT_TIME |
NUMBER |
User I/O Wait time |
PLSQL_EXEC_TIME |
NUMBER |
PL/SQL Execution time |
JAVA_EXEC_TIME |
NUMBER |
Java Execution Time |
ROWS_PROCESSED |
NUMBER |
The total number of columns returned by the parse SQL statement |
COMMAND_TYPE |
NUMBER |
Command Type Code |
OPTIMIZER_MODE |
VARCHAR2(25) |
The optimizer model of the QL statement |
PARSING_USER_ID |
NUMBER |
The first resolved user ID |
PARSING_SCHEMA_ID |
NUMBER |
The first resolved plan ID |
KEPT_VERSIONS |
NUMBER |
Indicates whether the current child cursor is marked as resident memory using the Dbms_shared_pool package |
ADDRESS |
RAW(4 | 8) |
Current cursor Parent handle address |
HASH_VALUE |
NUMBER |
Hash value of the parent statement in the library cache |
OLD_HASH_VALUE |
NUMBER |
Old SQL Hash value |
MODULE |
VARCHAR2(64) |
Contains the name of the module is executing at the time that the SQL statement is first parsed as set by calling c6/>.SET_MODULE |
MODULE_HASH |
NUMBER |
Hash value of the module is named in the MODULE column |
ACTION |
VARCHAR2(64) |
Contains the name of the action is executing at the time that the SQL statement is first parsed as set by calling c2/>.SET_ACTION |
ACTION_HASH |
NUMBER |
Hash value of the action that's named in the ACTION column |
SERIALIZABLE_ABORTS |
NUMBER |
Number of times the transaction fails to serialize, producing ORA-08177 errors, totalled through all the child cursors |
CPU_TIME |
NUMBER |
CPU time (in microseconds) used by the cursor for parsing/executing/fetching |
ELAPSED_TIME |
NUMBER |
Elapsed time (in microseconds) used by the cursor for parsing/executing/fetching |
IS_OBSOLETE |
VARCHAR2(1) |
Indicates whether the cursor has a become obsolete ( Y ) or not ( N ). This can happen if the number of child cursors is too large. |
CHILD_LATCH |
NUMBER |
Child latch number which is protecting the cursor |
PROGRAM_ID |
NUMBER |
Program Identifie |
Source: http://blog.csdn.net/sxhong/article/details/18262663
Query Oracle for slow session and SQL