when someone says:
๐จ “Oracle database is slow”
⚡ Oracle Performance Troubleshooting – Step-by-Step Playbook
๐ง Step 0: Stay Calm & Don’t Guess
Before doing anything:
๐ Don’t jump into AWR immediately
๐ Don’t restart database
๐ Don’t assume it’s “CPU issue”
First rule:
Find the bottleneck, not the symptom
๐ Step 1: Identify Where Time is Spent (Your Query ๐)
SELECT event, total_waits, time_waited
FROM v$system_event
ORDER BY time_waited DESC
FETCH FIRST 5 ROWS ONLY;
๐ What to check:
| If you see | Meaning |
|---|---|
| db file sequential read | Index I/O |
| db file scattered read | Full table scan |
| log file sync | Commit issue |
| CPU time high | CPU pressure |
| enq: TX row lock | Blocking |
✅ Now you know WHERE to focus
⚡ Step 2: Check Active Sessions (Real-Time)
SELECT sid, serial#, username, sql_id, event, wait_class, seconds_in_wait
FROM v$session
WHERE status = 'ACTIVE'
ORDER BY seconds_in_wait DESC;
๐ Identify:
Long running sessions
Blocking sessions
Top wait events
๐ซ Step 3: Check Blocking / Locks
SELECT blocking_session, sid, serial#, wait_class, event
FROM v$session
WHERE blocking_session IS NOT NULL;
If blocking exists:
๐ That’s your issue (most critical)
๐งฎ Step 4: Identify Top SQL (Heavy Queries)
SELECT sql_id, executions, elapsed_time/1000000 total_sec
FROM v$sql
ORDER BY elapsed_time DESC
FETCH FIRST 10 ROWS ONLY;
๐ Look for:
High elapsed time
High executions
Same SQL repeated
๐ Step 5: Check CPU Usage
SELECT stat_name, value
FROM v$sysstat
WHERE stat_name LIKE '%CPU%';
๐ Or OS level:
top
If CPU is high:
Bad SQL
Missing indexes
High concurrency
๐พ Step 6: Check I/O Bottleneck
SELECT file#, phyrds, phywrts
FROM v$filestat;
๐ OR check wait events:
db file sequential read→ index readsdb file scattered read→ full scans
๐ Step 7: Check Redo / Commit Issues
SELECT event, time_waited
FROM v$system_event
WHERE event = 'log file sync';
๐ If high:
Too many commits
Slow disk
๐ Step 8: Check Network Issues
Look for:
SQL*Net message from clientSQL*Net more data
๐ Usually application-side delay
๐ Step 9: Check AWR (If Needed)
Only AFTER initial diagnosis:
@?/rdbms/admin/awrrpt.sql
Focus on:
Top SQL
Wait events
Load profile
๐งช Step 10: Drill Down into Problem SQL
SELECT *
FROM TABLE(DBMS_XPLAN.DISPLAY_CURSOR('<SQL_ID>', NULL, 'ALLSTATS LAST'));
๐ Check:
Full table scans
Bad joins
Wrong cardinality
๐ Step 11: Take Action (Based on Root Cause)
| Issue | Action |
|---|---|
| Blocking | Kill session / fix transaction |
| Bad SQL | Tune query / add index |
| CPU high | Optimize SQL |
| I/O high | Add indexes / check storage |
| Redo issue | Reduce commits |
| Stats stale | Gather stats |
๐ฅ Real DBA Flow (Golden Rule)
When DB is slow:
Check wait events ✅
Check active sessions ✅
Check blocking ✅
Identify top SQL ✅
Drill into execution plan ✅
๐ง Interview-Level Answer (Important)
If interviewer asks:
๐ “Database is slow, what will you do?”
Say:
“First I check system wait events to identify where time is spent, then I analyze active sessions and blocking, followed by identifying top SQL and reviewing execution plans before taking corrective action.”
⚡ Pro Tips (From Real Production Experience)
80% issues = bad SQL or missing index
10% = locking
10% = infrastructure (CPU/I/O)
๐ฏ Final Thought
“Performance tuning is not about fixing everything…
It’s about fixing the right thing first.”
No comments:
Post a Comment