Oracle Sessions Overview (vsession.sql)
What This Script Does
Section titled “What This Script Does”This script provides a concise overview of all Oracle sessions, showing essential identification and status information. It’s designed for quick session analysis when DBAs need to rapidly assess current database activity without overwhelming detail, making it ideal for initial troubleshooting and system monitoring.
Script
Section titled “Script”rem vsession.sqlremttitle 'Oracle Sessions'remcol sid format 9990 heading 'SID'col serial# format 99990 heading 'SER'col user# format 990 heading 'UID'col username format a12 heading 'USERNAME'col command format 990 heading 'COMMAND'col taddr format a8 heading 'TADDR'col lockwait format a8 heading 'LOCKWAIT'col status format a8 heading 'STATUS'col server format a9 heading 'SERVER'remselect sid, serial#, user#, username, command, taddr, lockwait, status, server from v$session;
-- Run the script in SQL*Plus or SQLcl@vsession.sql
-- No parameters required-- Shows all sessions including system sessions-- Lightweight output for quick scanning
Required Privileges
Section titled “Required Privileges”- SELECT on V$SESSION
- Available to most database users
Sample Output
Section titled “Sample Output”Oracle Sessions
SID SER UID USERNAME COMMAND TADDR LOCKWAIT STATUS SERVER----- ----- --- ------------ ------- -------- -------- -------- --------- 1 1 0 SYS 0 00000000 ACTIVE DEDICATED 2 1 0 SYS 0 00000000 ACTIVE DEDICATED 3 1 0 SYS 0 00000000 ACTIVE DEDICATED 10 15 0 SYS 0 00000000 ACTIVE DEDICATED 15 25 45 SCOTT 3 07A2F3C8 ACTIVE DEDICATED 18 33 45 SCOTT 0 00000000 INACTIVE DEDICATED 22 41 67 HR_USER 1 07A2F450 ACTIVE DEDICATED 25 52 67 HR_USER 47 00000000 INACTIVE SHARED 28 67 89 APPUSER 6 07A2F5D8 07A2F600 ACTIVE DEDICATED 31 78 89 APPUSER 0 00000000 INACTIVE DEDICATED 35 89 123 REPORT_USR 0 00000000 ACTIVE SHARED
Key Output Columns
Section titled “Key Output Columns”- SID: Session identifier (unique per instance)
- SER: Serial number (increments when SID reused)
- UID: Internal user ID
- USERNAME: Database username (NULL for background processes)
- COMMAND: Current SQL command type (numeric code)
- TADDR: Transaction address (NULL if no transaction)
- LOCKWAIT: Lock wait address (NULL if not waiting)
- STATUS: Session status (ACTIVE/INACTIVE)
- SERVER: Server type (DEDICATED/SHARED/NONE)
Understanding Session Information
Section titled “Understanding Session Information”Session Status
Section titled “Session Status”- ACTIVE: Currently executing SQL
- INACTIVE: Connected but not executing
- KILLED: Marked for termination
- CACHED: Cached in connection pool
- SNIPED: Idle timeout exceeded
Server Types
Section titled “Server Types”- DEDICATED: Dedicated server process
- SHARED: Shared server (MTS) connection
- NONE: Background process
- POOLED: Connection pooling
Command Types (Common Values)
Section titled “Command Types (Common Values)”- 0: No command (idle)
- 1: CREATE TABLE
- 2: INSERT
- 3: SELECT
- 6: UPDATE
- 7: DELETE
- 47: PL/SQL EXECUTE
Performance Analysis
Section titled “Performance Analysis”Session Patterns
Section titled “Session Patterns”- High SID values: Many connections created
- LOCKWAIT not NULL: Sessions waiting for locks
- TADDR not NULL: Active transactions
- All INACTIVE: Possible connection pooling issues
Resource Usage Indicators
Section titled “Resource Usage Indicators”- Many ACTIVE sessions: High concurrency
- SHARED servers: Shared server configuration
- Background processes: System activity level
- Lock waits: Contention issues
Common Use Cases
Section titled “Common Use Cases”Quick System Overview
Section titled “Quick System Overview”-- Get session count by status@vsession.sql-- Count ACTIVE vs INACTIVE sessions-- Look for unusual patterns
Session Identification
Section titled “Session Identification”-- Find specific user sessions@vsession.sql-- Locate sessions by USERNAME-- Note SID and SERIAL# for further investigation
Lock Wait Detection
Section titled “Lock Wait Detection”-- Identify sessions waiting for locks@vsession.sql-- Look for non-NULL LOCKWAIT values-- Cross-reference with lock analysis scripts
Troubleshooting Session Issues
Section titled “Troubleshooting Session Issues”High Session Count
Section titled “High Session Count”-
Count total sessions:
SELECT COUNT(*) total_sessions,COUNT(CASE WHEN username IS NOT NULL THEN 1 END) user_sessions,COUNT(CASE WHEN status = 'ACTIVE' THEN 1 END) active_sessionsFROM v$session; -
Check session limit:
SELECT name, value FROM v$parameterWHERE name = 'sessions';
Connection Pool Analysis
Section titled “Connection Pool Analysis”-- Analyze connection patternsSELECT username, server, COUNT(*) session_count, COUNT(CASE WHEN status = 'ACTIVE' THEN 1 END) active, COUNT(CASE WHEN status = 'INACTIVE' THEN 1 END) inactiveFROM v$sessionWHERE username IS NOT NULLGROUP BY username, serverORDER BY session_count DESC;
Session Kill Preparation
Section titled “Session Kill Preparation”-- Prepare to kill specific sessionsSELECT 'ALTER SYSTEM KILL SESSION '''||sid||','||serial#||''' IMMEDIATE;'FROM v$sessionWHERE username = 'TARGET_USER'AND status = 'INACTIVE';
Advanced Analysis
Section titled “Advanced Analysis”Session Distribution by User
Section titled “Session Distribution by User”-- Count sessions per userSELECT username, COUNT(*) total, SUM(CASE WHEN status = 'ACTIVE' THEN 1 ELSE 0 END) active, SUM(CASE WHEN lockwait IS NOT NULL THEN 1 ELSE 0 END) waitingFROM v$sessionWHERE username IS NOT NULLGROUP BY usernameORDER BY total DESC;
Transaction Analysis
Section titled “Transaction Analysis”-- Sessions with active transactionsSELECT s.sid, s.serial#, s.username, s.status, t.used_ublk undo_blocks, t.used_urec undo_records, ROUND((SYSDATE - t.start_date) * 24 * 60, 2) minutes_activeFROM v$session s, v$transaction tWHERE s.taddr = t.addrORDER BY minutes_active DESC;
Resource Usage Summary
Section titled “Resource Usage Summary”-- Resource usage by session typeSELECT DECODE(username, NULL, 'Background', 'User') session_type, server, COUNT(*) sessions, SUM(CASE WHEN status = 'ACTIVE' THEN 1 ELSE 0 END) active, SUM(CASE WHEN lockwait IS NOT NULL THEN 1 ELSE 0 END) waitingFROM v$sessionGROUP BY DECODE(username, NULL, 'Background', 'User'), serverORDER BY sessions DESC;
Related Scripts
Section titled “Related Scripts”- Detailed Session Information (gvsess.sql) - Comprehensive session details
- Session Wait Events (gvsessab.sql) - Session wait analysis
- Blocking Sessions (vlockb2.sql) - Lock blocking analysis
- Active Sessions (gvsqlplanfind.sql) - SQL execution details