"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_waitst,
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 wherea.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

Querying the most resource-intensive queries from V$sqlarea

Select B.username Username,a.disk_readsreads,
A.executionsexec,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;

The SQL TOP5 that consumes the most disk reads:
Selectdisk_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 lot of buffered read (logical read) operations:

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 theend_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 Dbms_shared_pool package

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 that is executing at the time that the SQL statement is first parsed as set by calling D Bms_application_info. Set_module

Module_hash

Number

Hash value of the module is named in the Modulecolumn

ACTION

VARCHAR2 (64)

Contains the name of the action that is executing at the time that the SQL statement is first parsed as set by calling D Bms_application_info. Set_action

Action_hash

Number

Hash value of the action is named in the Actioncolumn

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

Original address: http://blog.csdn.net/sxhong/article/details/18262663

"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.