ข้ามไปยังเนื้อหา

Lab 13 — Oracle Performance Triage & SQL Plan Inspection (Read-only)

🧠 ภาพจำก่อนอ่าน: 🧪 Lab → 🗄️ Data → ⚙️ Process → 🩺 Health → 🧹 Cleanup
🎨 Visual Guide ของวิชานี้ — ภาพช่วยจำ ไม่แทนคำสั่งและเนื้อหาจริง

Lesson 29 · Lesson 30 · Lesson 31

Original companion exercise. NOT RUN on an Oracle instance. The Activity Guide is proprietary and not reproduced. Requires authorized account with approved SELECT privileges; no AWR/ASH/ADDM, Tuning Pack, DDL, ALTER SYSTEM, KILL SESSION, or EXPLAIN PLAN writes.

  • Use existing disposable lab/PDB if available; determine DB version, timezone, current user/service, instance and PDB.
  • Never publish real SQL texts/binds, usernames, customer data or internal IPs in public GitHub.
  • Do not grant SYSDBA or SELECT ANY DICTIONARY just to pass this exercise; if metadata unavailable, mark NOT AUTHORIZED.
SHOW USER
SHOW CON_NAME
SELECT instance_name,status,startup_time FROM v$instance;
SELECT name,open_mode,cdb FROM v$database;
SELECT con_id,name,open_mode FROM v$pdbs ORDER BY con_id;

Expected: identify instance and PDB; PDB mode independent from CDB open state.

SELECT status,COUNT(*) session_count FROM v$session
WHERE type='USER' GROUP BY status;
SELECT resource_name,current_utilization,max_utilization,limit_value
FROM v$resource_limit WHERE resource_name IN ('processes','sessions');
SELECT wait_class,total_waits,time_waited
FROM v$system_wait_class ORDER BY time_waited DESC;

Interpret: V$RESOURCE_LIMIT MAX_UTILIZATION is high-water mark; counters accumulate and are not per-minute rates. Record 2 snapshots with observation interval only in an authorized test; do not create a high-frequency polling loop on production.

SELECT sid,serial#,username,status,wait_class,event,blocking_session
FROM v$session WHERE type='USER' AND username IS NOT NULL
FETCH FIRST 20 ROWS ONLY;

Sessions showing INACTIVE do not prove JDBC leak. Correlate pool metrics, last call and app logs.

SELECT sql_id,child_number,plan_hash_value,executions,elapsed_time
FROM v$sql
WHERE executions>0
ORDER BY elapsed_time DESC FETCH FIRST 10 ROWS ONLY;

Cumulative microseconds need deltas and matching executions for a rate/average. Take care that SQL text/binds may be sensitive.

-- Only with approved DBMS_XPLAN and V$ grants.
-- Replace placeholder with an existing authorized SQL_ID.
SELECT plan_table_output
FROM TABLE(DBMS_XPLAN.DISPLAY_CURSOR(
sql_id => 'abcdef1234567', cursor_child_no => 0, format => 'TYPICAL'));

Do not run EXPLAIN PLAN because it may write into PLAN_TABLE. Do not call DISPLAY_AWR or other Diagnostics Pack methods without licensing. DISPLAY_CURSOR can return no rows if cursor aged out.

Scenario A: Oracle listener responds; application Tomcat reports ORA-12519 intermittently, and restarting Tomcat helps for hours. Create timeline of listener handler availability, process/session headroom, JDBC pool use and connection lifetimes. State what cannot be inferred from one snapshot.

Scenario B: SQL query latency increases after a maintenance window. Compare before/after optimizer stats timestamps, plan hash, estimated rows, waits and application load. Suggest one safe hypothesis to test in a sandbox; don’t change plan hints/indexes in production based only on suspicion.

  • Explain DB time/response time, throughput and wait classes
  • Distinguish instant session counts vs cumulative wait stats
  • Evaluate SQL plan/cardinality and feature license
  • Outline root-cause hypothesis and change/rollback evidence
  • Zero state mutations
  • Actual Oracle execution marked NOT RUN

Cleanup: disconnect only.

References:

Plan Inspection = ไม่ใช่ SQL Tuning Advisor. DBMS_XPLAN.DISPLAY_CURSOR แสดง Cached Cursor Plan ที่เคยรัน โดย Oracle 19c Reference ต้องมีสิทธิ์ SELECT/READ บน V$SQL, V$SQL_PLAN, V$SESSION และ V$SQL_PLAN_STATISTICS_ALL; Package Privileges ตรวจเพิ่มตาม Environment

Checkpoints:

  1. SQL_ID และ CHILD_NUMBER ที่เลือกตรงกับ Cursor ของ Incident จริงหรือไม่? V$SQL.ELAPSED_TIME เป็น Cumulative Metric
  2. DISPLAY_CURSOR('...',0,'TYPICAL') อ่าน Plan ที่อยู่ใน Cursor Cache; หาก Cursor Aged Out ต้องขอหลักฐานทางอื่นตาม License
  3. E-Rows vs A-Rows: Runtime Stats ไม่ได้ถูกเก็บทุก Query; ALLSTATS LAST จึงไม่รับประกันว่ามี A-Rows
  4. ห้ามใช้ EXPLAIN PLAN ใน Read-only Lab (อาจเขียน PLAN_TABLE); DISPLAY_AWR/AWR/ADDM ต้องตรวจ Diagnostics Pack; SQL Tuning Advisor/SQL Monitor ต้องตรวจ Tuning Pack ก่อน

Expected evidence: SQL_ID, Child#, Plan Hash, Estimated Rows, Actual Rows (if available), Exec Count, Wait Class, PDB/Instance Scope, Time Window, and redacted SQL Text/Bind Values

Official: 19c DBMS_XPLAN · 19c Licensing.

Status: DOC_REVIEWED / LIVE_NOT_EXECUTED.

▶️ Runbook + Approved Read-only SQL Scripts · 📝 Expected vs Actual Evidence Template

Status: NOT_EXECUTED. เมื่อมี Isolated Sandbox ที่ได้รับอนุญาต ให้เลือก Script ที่ตรงหัวข้อ, บันทึก Oracle Version/RU, Container/Privileges และ Expected vs Actual ลง Private Evidence. อย่าอ้างว่า GitHub Actions PASS เท่ากับรัน Lab จริง และห้าม Commit Raw Database Output ลง Public Repository.