Finding SQLs with a specific condition by manually inspecting dozens of AWR reports is an error prone and tedious task.
Especially in RAC environments, where there are multiple instances generating a lot of AWR data.
However, it is possible to easily extract the required information from AWR or the cursor cache using a query.
The DBMS_SQLTUNE package
The DBMS_SQLTUNE db package has two subprograms which are useful.
They are the select_workload_repository and the select_cursor_cache subprograms.
They can be used to quickly find, and capture the sqls of interest and their metrics.
DBMS_SQLTUNE.SELECT_WORKLOAD_REPOSITORY procedure (for past workloads)
Parameter Name |
Purpose |
Begin_snap |
Start snapshot id for capture (Capture will be for
activity this snapshot’s end interval time) |
End_snap |
End snapshot id for capture (Capture will be for
activity upto and including this snapshot’s end interval time) |
Basic_filter |
Filter the list of sqls to be captured based on
elapsed time, session module, etc. When this parameter is provided adhoc pl/sql blocks
execution will also be captured. |
Example query: The sql below extracts the data of ONLY those sqls
which match these conditions: • Starting from snapshot id 10 and until snapshot id 11 select sql_id, elapsed_time , buffer_gets,
disk_reads, cpu_time, executions The screenshot below shows its output
|
DBMS_SQLTUNE.SELECT_CURSOR_CACHE procedure (for live workloads)
Parameter Name | Purpose |
basic_filter | Its like a WHERE clause to filter the list of SQLS returned. In the example belowit filters for cpu_time > 250k microseconds. |
Example query: The screenshot below shows its output |