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.
Safety and scope
หัวข้อที่มีชื่อว่า “Safety and scope”- 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.
Task 1 — Establish identity and availability
หัวข้อที่มีชื่อว่า “Task 1 — Establish identity and availability”SHOW USERSHOW CON_NAMESELECT 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.
Task 2 — Session and resource snapshot
หัวข้อที่มีชื่อว่า “Task 2 — Session and resource snapshot”SELECT status,COUNT(*) session_count FROM v$sessionWHERE type='USER' GROUP BY status;
SELECT resource_name,current_utilization,max_utilization,limit_valueFROM v$resource_limit WHERE resource_name IN ('processes','sessions');
SELECT wait_class,total_waits,time_waitedFROM 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.
Task 3 — Which user sessions are waiting?
หัวข้อที่มีชื่อว่า “Task 3 — Which user sessions are waiting?”SELECT sid,serial#,username,status,wait_class,event,blocking_sessionFROM v$session WHERE type='USER' AND username IS NOT NULLFETCH FIRST 20 ROWS ONLY;Sessions showing INACTIVE do not prove JDBC leak. Correlate pool metrics, last call and app logs.
Task 4 — SQL candidate inventory
หัวข้อที่มีชื่อว่า “Task 4 — SQL candidate inventory”SELECT sql_id,child_number,plan_hash_value,executions,elapsed_timeFROM v$sqlWHERE executions>0ORDER 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.
Task 5 — Cursor execution plan (optional)
หัวข้อที่มีชื่อว่า “Task 5 — Cursor execution plan (optional)”-- Only with approved DBMS_XPLAN and V$ grants.-- Replace placeholder with an existing authorized SQL_ID.SELECT plan_table_outputFROM 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.
Task 6 — Two realistic incident drills
หัวข้อที่มีชื่อว่า “Task 6 — Two realistic incident drills”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.
Completion
หัวข้อที่มีชื่อว่า “Completion”- 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:
- https://docs.oracle.com/en/database/oracle/oracle-database/26/tgdba/measuring-database-performance.html
- https://docs.oracle.com/en/database/oracle/oracle-database/26/tgsql/generating-and-displaying-execution-plans.html
- https://docs.oracle.com/en/database/oracle/oracle-database/26/dblic/Licensing-Information.html
🧪 V2 SQL Plan Evidence & Access Drill (DOC_REVIEWED, NOT_EXECUTED)
หัวข้อที่มีชื่อว่า “🧪 V2 SQL Plan Evidence & Access Drill (DOC_REVIEWED, NOT_EXECUTED)”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:
- SQL_ID และ CHILD_NUMBER ที่เลือกตรงกับ Cursor ของ Incident จริงหรือไม่?
V$SQL.ELAPSED_TIMEเป็น Cumulative Metric DISPLAY_CURSOR('...',0,'TYPICAL')อ่าน Plan ที่อยู่ใน Cursor Cache; หาก Cursor Aged Out ต้องขอหลักฐานทางอื่นตาม LicenseE-RowsvsA-Rows: Runtime Stats ไม่ได้ถูกเก็บทุก Query;ALLSTATS LASTจึงไม่รับประกันว่ามี A-Rows- ห้ามใช้
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.
🧪 Sandbox Execution & Evidence (Optional)
หัวข้อที่มีชื่อว่า “🧪 Sandbox Execution & Evidence (Optional)”▶️ 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.