Go: Query Oracle slow session and SQL

Source: Internet
Author: User
Tags sorts

--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) 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 c4/>.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

Go: Query Oracle slow session and SQL

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.