Find SQL that performs inefficiently in Oracle
kt431128 posted 9 month ago, total 0 reviews
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
SelectOpname, Target, To_char (Start_time,'YYYY-MM-DD Hh24:mi:ss') start_time, elapsed_seconds elapsed, executions execs, buffer_gets/Decode (executions,0,1, executions) bufgets, module, Sql_text fromv$session_longops SL, v$sqlarea sawhereSl.sql_hash_value=Sa.hash_value and Upper(Substr (module,1,4))<> 'RMAN' andSUBSTR (Opname,1,4)<> 'RMAN' andSl.start_time>trunc (sysdate)Order byStart_time;
To find the full SQL statement based on the SID:
Select from where = (Select fromwhere='&sid' ) Order by ASC
SelectA.cpu_time,--CPU time one out of 10,000 (microseconds)A.optimizer_mode,--Optimization MethodA.executions,--Number of executionsA.disk_reads,--read the number of diskA.sharable_mem,--How much memory is occupied by the shared poolA.buffer_gets,--number of Read buffersA.command_type,--Command Type (3:select,2:insert;6:update;7delete;47:pl/sql program unit)A.sql_text,--SQL statementsA.sharable_mem, A.persistent_mem, A.runtime_mem, A.parse_calls, A.disk_reads, A.D Irect_writes, A.concurrency_wait_time, A.user_io_wait_time fromSYS. V_$sqlarea aWHEREParsing_schema_name= 'Chea_fill'--Table Space Order byA.cpu_timedesc
Reference: http://jenniferok.iteye.com/blog/700985
Querying the most resource-intensive queries 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 from (select sql_text,executions, over ( orderbydesc) exec_rank fromwhere <=5;
The SQL TOP5 that consumes the most disk reads:
Select from (select sql_text,disk_reads, over ( orderbydesc) disk_reads_rank from where <= 5;
Find queries that require a lot of buffered read (logical read) operations:
Select from (select sql_text,buffer_gets, over ( orderbydesc) buffer_gets_rank from where buffer_gets_rank<=5;
V$sqlarea Field Definition: http://happyhou.blog.sohu.com/60494432.html
SQL_TEXT |
VARCHAR2(1000) |
First thousand characters of the SQL text for the current cursor |
SQL_ID |
VARCHAR2(13) |
SQL identifier of the parent cursor in the library cache |
SHARABLE_MEM |
NUMBER |
Amount of shared memory used by a cursor. If multiple child cursors exist, then the sum of all shared memory used by all child cursors. |
PERSISTENT_MEM |
NUMBER |
Fixed amount of memory used for the lifetime of an open cursor. If multiple child cursors exist, the fixed sum of memory used for the lifetime of all the child cursors. |
RUNTIME_MEM |
NUMBER |
Fixed amount of memory required during execution of a cursor. If multiple child cursors exist, the fixed sum of all memory required during execution of all the child cursors. |
SORTS |
NUMBER |
Sum of the number of sorts that were do for all the child cursors |
VERSION_COUNT |
NUMBER |
Number of child cursors that is present in the cache under this parent |
LOADED_VERSIONS |
NUMBER |
Number of child cursors that is present in the cache and has their context heap (KGL heap 6) loaded |
OPEN_VERSIONS |
NUMBER |
The number of child cursors that is currently open under this current parent |
USERS_OPENING |
NUMBER |
Number of users that has any of the cursors open |
FETCHES |
NUMBER |
Number of fetches associated with the SQL statement |
EXECUTIONS |
NUMBER |
Total number of executions, totalled through all the cursors |
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 |
Total number of users executing the statement to all child cursors |
LOADS |
NUMBER |
Number of times the object was loaded or reloaded |
FIRST_LOAD_TIME |
VARCHAR2(19) |
Timestamp of the parent creation time |
INVALIDATIONS |
NUMBER |
Total number of invalidations in the child cursors |
PARSE_CALLS |
NUMBER |
Sum of all parse calls to all the child cursors under this parent |
DISK_READS |
NUMBER |
Sum of the number of disk reads over all child cursors |
DIRECT_WRITES |
NUMBER |
Sum of the number of direct writes over all child cursors |
BUFFER_GETS |
NUMBER |
Sum of buffer gets over all child cursors |
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 |
Total number of rows processed in behalf of this SQL statement |
COMMAND_TYPE |
NUMBER |
Oracle command Type definition |
OPTIMIZER_MODE |
VARCHAR2(25) |
Mode under which the SQL statement was executed |
PARSING_USER_ID |
NUMBER |
User ID of the user that have parsed the very first cursor under this parent |
PARSING_SCHEMA_ID |
NUMBER |
Schema ID that is used to parse this child cursor |
KEPT_VERSIONS |
NUMBER |
Number of child cursors that has been marked to being kept using the package DBMS_SHARED_POOL |
ADDRESS |
RAW(4 | 8) |
Address of the handle to the parent for this cursor |
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 |
Find SQL that performs inefficiently in Oracle