π¨ Real-Time Troubleshooting Scenario (Hands-On Practice)
π― Situation
Time: 11:15 AM
Environment: Production
Users complaint:
“Application is very slow. Pages are hanging.”
You have no prior info.
⏱️ Your Goal (as DBA)
Identify root cause in 5–10 minutes
Avoid guesswork
Take correct action
π Step 1: Where is time spent?
You run:
SELECT event, total_waits, time_waited
FROM v$system_event
ORDER BY time_waited DESC
FETCH FIRST 5 ROWS ONLY;
π Output:
EVENT TIME_WAITED
---------------------------- -----------
enq: TX - row lock contention 9854321
db file sequential read 234567
CPU time 123456
❓ Question 1 (Your Move)
π What does this indicate?
✅ Expected Thinking:
Top wait = row lock contention
This is blocking issue, not CPU or I/O
π Step 2: Find Blocking Session
You run:
SELECT blocking_session, sid, serial#, event
FROM v$session
WHERE blocking_session IS NOT NULL;
π Output:
BLOCKING_SESSION SID EVENT
--------------- ---- -----------------------------
145 201 enq: TX - row lock contention
145 305 enq: TX - row lock contention
145 410 enq: TX - row lock contention
❓ Question 2
π What do you conclude?
✅ Answer:
Session 145 is blocking multiple sessions
This is a critical production issue
π Step 3: Identify Blocking SQL
SELECT sid, serial#, username, sql_id, status
FROM v$session
WHERE sid = 145;
Output:
SID SERIAL# USERNAME SQL_ID STATUS
145 6789 APPUSER abc123xyz INACTIVE
❓ Question 3
π Why is this dangerous?
✅ Answer:
Session is INACTIVE but holding locks
Likely:
Uncommitted transaction
Application issue
π₯ Step 4: Business Decision Time
You have 2 options:
Option A:
π Wait for user to commit/rollback
Option B:
π Kill the session
❓ Question 4
π What will you do?
✅ Best Answer:
If production is impacted → Kill session
⚡ Step 5: Kill Blocking Session
ALTER SYSTEM KILL SESSION '145,6789' IMMEDIATE;
π Step 6: Validate Fix
Check again:
SELECT blocking_session FROM v$session
WHERE blocking_session IS NOT NULL;
Output:
No rows selected
π Result
Blocking removed
Application restored
Issue resolved in minutes
π§ Now Let’s Level Up (Scenario 2)
π¨ New Situation
Users say:
“Reports are very slow”
You run:
SELECT event, time_waited
FROM v$system_event
ORDER BY time_waited DESC;
Output:
db file scattered read 9999999
CPU time 8888888
❓ Question 5
π What does this indicate?
✅ Answer:
Heavy Full Table Scans
Likely:
Missing indexes
Bad SQL
π Next Step
SELECT sql_id, elapsed_time, executions
FROM v$sql
ORDER BY elapsed_time DESC
FETCH FIRST 5 ROWS ONLY;
❓ Question 6
π What will you do next?
✅ Answer:
Pick top SQL_ID
Check execution plan:
SELECT *
FROM TABLE(DBMS_XPLAN.DISPLAY_CURSOR('<SQL_ID>', NULL, 'ALLSTATS LAST'));
π― Final Diagnosis
Full table scan detected
Missing index
⚡ Fix
CREATE INDEX idx_col ON table_name(column_name);
π Final Learning
π₯ Golden Troubleshooting Flow:
Check wait events
Identify type of issue
Find sessions / SQL
Take targeted action
π― Mock Interview Question (Based on Scenario)
π “How will you handle blocking in production?”
Perfect Answer:
“I first check wait events to confirm locking, identify blocking session using V$SESSION, verify the SQL and session state, and if it’s impacting users, I kill the blocking session and inform application team.”
No comments:
Post a Comment