Sunday, March 22, 2026

Oracle database is slow

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 seeMeaning
db file sequential readIndex I/O
db file scattered readFull table scan
log file syncCommit issue
CPU time highCPU pressure
enq: TX row lockBlocking

✅ 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 reads

  • db 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 client

  • SQL*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)

IssueAction
BlockingKill session / fix transaction
Bad SQLTune query / add index
CPU highOptimize SQL
I/O highAdd indexes / check storage
Redo issueReduce commits
Stats staleGather stats

๐Ÿ”ฅ Real DBA Flow (Golden Rule)

When DB is slow:

  1. Check wait events

  2. Check active sessions

  3. Check blocking

  4. Identify top SQL

  5. 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