Top 20 DB Monitoring SQL Scripts For DBAs-2
Top 20 DB Monitoring SQL Scripts For DBAs-2
Asfaw Gedamu
Introduction
Maintaining a healthy and performant Oracle database requires constant vigilance. These SQL
scripts equip DBAs with the tools to gain valuable insights into key metrics, such as resource
utilization, wait events, session activity, and object health. By incorporating these scripts into
your monitoring routines, you can proactively address bottlenecks and prevent disruptions before
they impact users.
Prerequisites
Ideal Audience
Identify currently active user sessions and their activities. (Great for troubleshooting slow
queries)
Monitor tablespace utilization to identify potential space constraints. (Important for proactive
capacity planning)
Identify sessions causing locks and the objects involved. (Helps resolve blocking issues)
• Investigate blocking sessions and take appropriate actions (e.g., kill sessions, optimize
queries).
• Implement preventative measures to minimize blocking occurrences.
Identify queries exceeding a specific execution time threshold. (Helps pinpoint inefficient
queries)
select
sid,inst_id,opname,totalwork,sofar,start_time,time_remaining
from gv$session_longops
where totalwork<>sofar
/
Select
module,parsing_schema_name,inst_id,sql_id,CHILD_NUMBER,sql_plan_
baseline,sql_profile,plan_hash_value,sql_fulltext,
to_char(last_active_time,'DD/MM/YY HH24:MI:SS' ),executions,
elapsed_time/executions/1000/1000,
rows_processed,sql_plan_baseline from gv$sql where
last_active_time>sysdate-1/24
and executions <> 0 order by elapsed_time/executions desc
select log_user,schema_user,last_date,
last_sec,this_date,this_sec, next_date,
next_sec,total_time,broken,interval,failures,what,instance from
d
ba_jobs;
Conclusion
By incorporating these SQL scripts into your Oracle database monitoring routine, you can gain
valuable insights into various aspects of database health and performance. This proactive
approach empowers you to identify and address potential issues before they impact users or
applications. Remember, these scripts are a starting point, and you might need to customize them
based on your specific environment and monitoring needs.