- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How to identify SQL queries with the most waits in Oracle?
Problem:
You want to identify the SQL statements responsible for the most waits in your database.
Solution
We can use below SQL statement to identify SQL causing problem.The below query will rank SQL statements that ran during the past 30 minutes and display them as per the total time waited by each query.
Example
SELECT ash.user_id, u.username, s.sql_text, SUM(ash.wait_time + ash.time_waited) ttl_wait_time FROM v$active_session_history ash, v$sqlarea s, dba_users u WHERE ash.sample_time BETWEEN sysdate - 60/2880 AND sysdate AND ash.sql_id = s.sql_id AND ash.user_id = u.user_id GROUP BY ash.user_id, s.sql_text, u.username ORDER BY ttl_wait_time ;
When you have a performance problem, it is recommended to validate which SQL statements are waiting for the most. To find the queries that are waiting for the most, you must sum the values in the wait_time and the time_waited columns of the "V$ACTIVE_SESSION_HISTORY" for a specific SQL statement. In order to do this, you must join the V$SQLAREA view with the "V$ACTIVE_SESSION_HISTORY" view, using SQL_ID as the join column.
- Related Articles
- How to identify the SQL consuming more resources in Oracle?
- How to capture Oracle errors in PL/SQL?
- How to translate SQL data to XML in Oracle?
- How to display a SQL execution progress along with execution plan in Oracle?
- How to identify blocked and blocking sessions in Oracle ?
- Explain aggregate functions with the help of SQL queries
- How to monitor real time SQL execution statistics in Oracle?
- How to determine the approximate amount of SQL work left in Oracle?
- How to identify recent WAIT events in a Oracle database ?
- How to Identify Most Frequently Occurring Items in a Sequence with Python?
- How to validate the syntax of a Oracle dynamic SQL before execution ?
- Block of PL/SQL in Oracle DBMS
- Difference between Oracle and SQL Server
- Explain different comparison operators used in SQL queries
- What are the different data types used in SQL queries?
