Monitor Sessions
Monitor and analyze active sessions in the Teradata database system to identify performance issues, blocking problems, and resource consumption patterns using real-time MCP resources and tools.
π Enhanced Capabilities
This skill now leverages real-time MCP resources for faster monitoring!
With tdwm-mcp v1.5.0, this skill provides:
- β REAL-TIME RESOURCES - Instant session data without running queries
- β SQL TEXT VISIBILITY - View query text and execution steps
- β BLOCKING DETECTION - Identify lock chains and contention
- β CONTROL ACTIONS - Optional session termination when needed
- β INTEGRATED CONTEXT - Sessions + workload + resource data in one view
Instructions
When to Use This Skill
- User asks to check active sessions or current database activity
- Need to identify who is running what queries
- Investigating performance issues or blocked sessions
- Monitoring specific user activity
- Response to complaints about slow queries or system unresponsiveness
Available MCP Tools
Session Monitoring:
list_sessions- List all active user sessions with detailsshow_session_sql_text- View full SQL text for specific sessionshow_session_sql_steps- View execution steps for session querymonitor_session_query_band- View query band settings for sessionsidentify_blocking- Identify sessions blocking other sessions
Control Actions (Optional):
abort_sessions_user- Terminate all sessions for a specific user
Related Monitoring:
show_tdwm_summary- View workload distribution (context for sessions)show_query_log- Historical query analysis
Available MCP Resources (NEW β¨)
Real-Time Session Data:
tdwm://system/sessions- Real-time snapshot of all active sessionstdwm://system/summary- Workload distribution showing session contexttdwm://system/workloads- Active workloads (to understand session classification)
Query Analysis:
tdwm://system/delayed-queries- Sessions waiting in delay queuestdwm://system/throttle-statistics- Throttle impact on sessions
Reference:
tdwm://reference/session-states- Explanation of session statestdwm://reference/blocking-types- Types of blocking scenarios
Step-by-Step Workflow
Phase 1: Quick Assessment (Use Resources First)
-
Get Real-Time Session Overview
- Read resource:
tdwm://system/sessions - Provides instant snapshot of all active sessions
- Review session count, usernames, current states
- Identify sessions of interest (long-running, high CPU, blocked)
- Read resource:
-
Understand Workload Context
- Read resource:
tdwm://system/summary - Shows how sessions are distributed across workloads
- Identifies which workloads are busy
- Provides system-wide context
- Read resource:
Phase 2: Detailed Analysis (Use Tools)
-
List Active Sessions
- Use
list_sessionsfor detailed, sortable session data - Review session IDs, usernames, runtime, CPU time, I/O
- Filter by user, state, or runtime criteria
- Identify sessions requiring deeper investigation
- Use
-
Examine Session SQL
- For suspicious or long-running sessions:
- Use
show_session_sql_textto see full query text - Use
show_session_sql_stepsto see execution steps
- Use
- Analyze query complexity and optimization
- Check if queries match expected workload patterns
- For suspicious or long-running sessions:
-
Check for Blocking
- Use
identify_blockingto find lock contention - Identify both blocking and blocked sessions
- Document blocking chains (Session A blocks B blocks C)
- Determine if blocking is normal (brief) or problematic (long)
- Use
-
Review Query Bands
- Use
monitor_session_query_bandto see session tags - Verify queries are properly classified
- Check if query bands match expected application
- Use
Phase 3: Analysis and Reporting
-
Correlate Session Data
- Cross-reference sessions with workload summary
- Check if throttles are delaying sessions (resource:
tdwm://system/throttle-statistics) - Identify patterns: multiple users, same application, similar queries
-
Provide Recommendations
- Summarize active session count and patterns
- Highlight problematic sessions (blocking, long-running, high resource)
- Provide session IDs and usernames for follow-up
- Recommend actions: optimize query, adjust workload, abort session
Phase 4: Control Actions (Optional)
- Take Action if Needed
- For runaway queries: Consider using
abort_sessions_user - For blocking issues: Identify which session to terminate
- Emergency situations: Act quickly to restore service
- Always document: Record what was terminated and why
- For runaway queries: Consider using
Examples
Example 1: Quick Session Check Using Resources (Fast)
Scenario: "Show me what's currently running on the database"
Action (Resource-First Approach):
1. Read real-time sessions:
tdwm://system/sessions
β Instant snapshot: 47 active sessions
2. Analyze resource data:
- 23 sessions in ETL workload (expected for this time)
- 15 sessions in INTERACTIVE workload
- 9 sessions in DEFAULT workload
- Most sessions <5 minutes runtime (normal)
- 2 sessions running >30 minutes (investigate)
3. Get workload context:
tdwm://system/summary
β ETL workload using 60% of resources
β Interactive workload using 30%
β System healthy, no overload
4. Report:
"47 active sessions, system healthy. ETL workload dominant (expected).
2 long-running sessions (ID 1234, 5678) worth monitoring."
Result: Complete overview in seconds without running any queries
Example 2: Investigate Specific User (Detailed)
Scenario: "What is user john_smith doing right now?"
Action (Resource + Tool Approach):
1. Check resource first:
tdwm://system/sessions
β Filter for user='john_smith'
β Found 3 active sessions: 1245, 1246, 1247
2. Get detailed session data:
list_sessions()
β Filter output for john_smith
β Session 1245: Running 45 minutes, high CPU
β Session 1246: Running 2 minutes, normal
β Session 1247: Idle, 0 CPU
3. Examine long-running session 1245:
show_session_sql_text(session_id=1245)
β Query: Large aggregation on fact table
β No obvious optimization issues
show_session_sql_steps(session_id=1245)
β Currently in step 5 of 8
β Doing JOIN operation
β No blocking detected
4. Check query band:
monitor_session_query_band()
β Filter for session 1245
β Query band: APP=ANALYTICS_TOOL, USER=john_smith
β Classified in ANALYTICS workload (correct)
5. Report:
"john_smith has 3 sessions:
- Session 1245: Long-running analytics query (45 min), progressing normally
- Session 1246: Recent query, completing soon
- Session 1247: Idle connection
No issues detected. Long query is expected for analytics workload."
Result: Complete user activity profile with context
Example 3: Diagnose Blocking Issues (Critical)
Scenario: "Some queries seem stuck, check for blocking"
Action (Blocking Analysis):
1. Quick resource check:
tdwm://system/sessions
β 12 sessions in "blocked" state
β Multiple sessions waiting on locks
2. Identify blocking chains:
identify_blocking()
β Blocking detected!
β Session 2001 (user: etl_batch) is blocking 8 sessions
β Session 2050 (user: report_user) is blocking 4 sessions
3. Analyze blocking session 2001:
show_session_sql_text(session_id=2001)
β UPDATE statement on CUSTOMER table
β Has been running for 90 minutes
β Holding exclusive table lock
list_sessions()
β Filter for session 2001
β Started at 02:00 AM (ETL window)
β Should have completed by now
4. Check blocked sessions:
list_sessions()
β Filter for blocked sessions
β All trying to SELECT from CUSTOMER table
β Waiting for lock release
β Users complaining about reports not loading
5. Analyze second blocker (session 2050):
show_session_sql_text(session_id=2050)
β Long-running report query
β Holding shared lock, blocking UPDATE attempts
6. Review reference:
tdwm://reference/blocking-types
β Scenario: ETL update blocking reports = Type 1 blocking
β Recommendation: Complete ETL or abort if stuck
7. Report:
"BLOCKING DETECTED - 12 sessions blocked:
Primary blocker: Session 2001 (etl_batch)
- Running 90 minutes (abnormally long)
- UPDATE on CUSTOMER table
- Blocking 8 report sessions
- RECOMMENDATION: Check if ETL is stuck, may need to abort
Secondary blocker: Session 2050 (report_user)
- Long-running report (60 min)
- Blocking 4 UPDATE attempts
- RECOMMENDATION: Let complete or optimize query
IMMEDIATE ACTION NEEDED for Session 2001"
Result: Clear identification of blocking issues with recommendations
Example 4: Emergency Session Termination (Control Action)
Scenario: "User adhoc_user01 is running runaway queries, kill all their sessions"
Action (Control Action):
1. Verify problem first:
tdwm://system/sessions
β User adhoc_user01 has 15 active sessions
β All running identical query
β System CPU at 95% (critical)
2. Get detailed view:
list_sessions()
β Filter for adhoc_user01
β 15 sessions, each using 6% CPU
β Total: 90% of system CPU
β All started within 5 minutes (query blast)
3. Check query:
show_session_sql_text(session_id=3001) # Pick one session
β SELECT with CROSS JOIN (Cartesian product!)
β Missing WHERE clause
β Generating billions of rows
4. Confirm termination decision:
- Runaway query confirmed
- No business justification for Cartesian product
- System critically overloaded
- User needs to be stopped
5. Execute termination:
abort_sessions_user(username="adhoc_user01")
β Terminating all 15 sessions for adhoc_user01
β Result: "15 sessions terminated"
6. Monitor recovery:
tdwm://system/summary
β Wait 30 seconds
β CPU dropping from 95% to 45%
β System recovering
7. Document incident:
"Emergency termination of adhoc_user01 sessions at 14:23:
- 15 runaway queries with Cartesian product
- Consuming 90% of system CPU
- Missing WHERE clause in query
- System returned to normal after termination
- User notified to fix query before resubmitting"
Result: System stabilized, incident documented
Example 5: Routine Session Audit (Proactive)
Scenario: Daily morning check of overnight session activity
Action (Comprehensive Audit):
1. Get high-level overview:
tdwm://system/summary
β 34 active sessions (normal for 8 AM)
β ETL workload: 12 sessions
β Interactive: 18 sessions
β Ad-hoc: 4 sessions
2. Check real-time sessions:
tdwm://system/sessions
β No sessions running >2 hours (good)
β No blocked sessions
β Resource usage balanced
3. Review delayed queries:
tdwm://system/delayed-queries
β 3 queries in delay queue (acceptable)
β All from ad-hoc workload (expected throttling)
4. Check throttle statistics:
tdwm://system/throttle-statistics
β ETL throttle: 0 delayed (nighttime processing complete)
β Ad-hoc throttle: 3 delayed (working as designed)
β Interactive throttle: 0 delayed (good performance)
5. List all sessions for record:
list_sessions()
β Full session inventory captured
β No anomalies detected
6. Check for any blocking:
identify_blocking()
β No blocking detected
7. Report:
"Morning session audit - 8:00 AM:
β
34 active sessions (normal)
β
No blocking issues
β
No long-running sessions (all <2 hours)
β
Throttles working as expected
β
System healthy
Overnight ETL completed successfully.
Interactive users beginning morning queries.
No issues requiring attention."
Result: Clean bill of health, documented baseline
Best Practices
Resource-First Approach (NEW β¨)
- START with resources for instant overview (
tdwm://system/sessions) - Resources are faster than running queries
- Use tools for detailed analysis only when needed
- Resources provide point-in-time snapshot
Investigation Workflow
- Always start with system-wide view before drilling into specifics
- Cross-reference session data with workload summary for context
- Document session IDs prominently for easy reference
- Consider time of day and expected workload patterns
Blocking Analysis
- Check for blocking proactively during performance investigations
- Analyze blocking chains to find root cause (first blocker)
- Understand business impact (how many users affected)
- Distinguish normal brief locks from problematic long locks
Control Actions
- ONLY abort sessions when necessary (runaway queries, system emergency)
- Always document what was terminated and why
- Notify users when their sessions are terminated
- Consider less drastic options first (throttling, priority adjustment)
Session State Understanding
- Reference
tdwm://reference/session-statesfor state meanings - "Active" = currently executing
- "Blocked" = waiting on lock
- "Idle" = connected but not executing
Monitoring Frequency
- Critical systems: Check every 15-30 minutes
- Normal systems: Check 2-3 times per day
- Always check during peak hours (morning, midday)
- Set up alerts for blocking or long-running sessions
Related Skills
- Use monitor-queries skill for historical query analysis
- Use control-sessions skill for detailed session management
- Use monitor-resources skill for CPU/memory/I/O correlation
- Use emergency-response skill for crisis situations