0% found this document useful (0 votes)
6 views

What Database Administrators Query Before Anything Else

Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views

What Database Administrators Query Before Anything Else

Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 6

What Database Administrators Query

Before Anything Else

SQL Scripts

Asfaw Gedamu
Database Administrators (DBAs) often start their workday or troubleshooting sessions by
running specific queries to get a quick overview of the database’s health, performance, and
status. They call it a health check or a daily routine.

These queries help them identify potential issues, monitor system resources, and ensure
everything is running smoothly. Below are three essential queries DBAs typically run before
anything else, along with explanations of why they are critical:

1. Check Database Uptime and Status


1. SELECT
2. instance_name,
3. status,
4. database_status,
5. startup_time,
6. host_name
7. FROM
8. v$instance;
9.

Output Example:

1. | INSTANCE_NAME | STATUS | DATABASE_STATUS | STARTUP_TIME


| HOST_NAME |
2. |---------------|---------|-----------------|-------------
-------|---------------|
3. | ORCL | OPEN | ACTIVE | 2023-10-01
08:00:00| db-server-01 |
4.

Why It’s Essential:

• Database Availability: Confirms whether the database is up and running.


• Uptime: Shows how long the database has been running since the last startup, which can
help identify unexpected restarts.
• Status: Indicates if the database is in a healthy state (e.g., `OPEN`, `MOUNTED`, or
`DOWN`).

2. Monitor Active Sessions and Resource Usage


1. SELECT
2. sid,
3. serial#,
4. username,
5. status,
6. program,
7. sql_id,
8. event,
9. wait_time,
10. seconds_in_wait
11. FROM
12. v$session
13. WHERE
14. status = 'ACTIVE';
15.
Output Example:

1. | SID | SERIAL# | USERNAME | STATUS | PROGRAM |


SQL_ID | EVENT | WAIT_TIME | SECONDS_IN_WAIT |
2. |-----|---------|----------|--------|------------------|--
----------|---------------------|-----------|------------------|
3. | 123 | 45678 | APP_USER | ACTIVE | sqlplus.exe |
abc123xyz | db file sequential read | 0 | 5
|
4.

Why It’s Essential:

• Performance Monitoring: Identifies active sessions and what they are doing, helping to
spot long-running queries or resource bottlenecks.
• Troubleshooting: Reveals sessions waiting on specific events (e.g., I/O, locks), which can
indicate performance issues.
• Resource Usage: Helps DBAs understand who is connected and what resources they are
consuming.

3. Check Table space Usage


1. SELECT
2. tablespace_name,
3. file_name,
4. bytes / 1024 / 1024 AS size_mb,
5. (bytes - (SELECT SUM(bytes) FROM dba_free_space WHERE
file_id = file_id)) / 1024 / 1024 AS used_mb,
6. (bytes - (SELECT SUM(bytes) FROM dba_free_space WHERE
file_id = file_id)) / bytes * 100 AS pct_used
7. FROM
8. dba_data_files;
9.

Output Example:
1. | TABLESPACE_NAME | FILE_NAME | SIZE_MB |
USED_MB | PCT_USED |
2. |-----------------|----------------------|---------|------
---|----------|
3. | USERS | /u01/oradata/users01 | 1024 | 800
| 78.12 |
4. | SYSTEM | /u01/oradata/system01| 512 | 450
| 87.89 |
5.

Why It’s Essential:

• Storage Monitoring: Tracks how much space is used and available in each table space,
helping to prevent out-of-space errors.
• Capacity Planning: Identifies table spaces that are nearing full capacity, allowing DBAs
to proactively add more space.
• Performance Impact: Full table spaces can lead to performance degradation, so
monitoring usage is critical.

4. Check for Blocking Locks


1. SELECT
2. blocking_session,
3. sid,
4. serial#,
5. wait_class,
6. event,
7. seconds_in_wait
8. FROM
9. v$session
10. WHERE
11. blocking_session IS NOT NULL;
12.

Output Example:

1. | BLOCKING_SESSION | SID | SERIAL# | WAIT_CLASS | EVENT


| SECONDS_IN_WAIT |
2. |------------------|-----|---------|------------|---------
------------|------------------|
3. | 123 | 456 | 78901 | Application| enq: TX
- row lock contention | 120 |
4.

Why It’s Essential:

• Deadlock Detection: Identifies sessions that are blocking others, which can cause
application timeouts or failures.
• Performance Bottlenecks: Helps resolve contention issues that may be slowing down the
database.

Why These Queries Are Critical for DBAs:

1. Proactive Monitoring: These queries provide a snapshot of the database’s health, allowing
DBAs to catch issues before they escalate.

2. Troubleshooting: They help quickly identify the root cause of performance problems, resource
contention, or storage issues.

3. Operational Efficiency: By running these queries regularly, DBAs can ensure the database is
running optimally and avoid unexpected downtime.

These queries are the foundation of a DBA’s toolkit and are often automated or integrated into
monitoring tools for continuous oversight.

You might also like