V$SESSION V$PROCESS Join - Oracle Session to OS Process Mapping
V$SESSION V$PROCESS Join - Complete Guide
Section titled “V$SESSION V$PROCESS Join - Complete Guide”Joining V$SESSION and V$PROCESS is essential for Oracle DBAs to map database sessions to operating system processes. This guide provides ready-to-run queries for session analysis and troubleshooting.
Quick Join Query
Section titled “Quick Join Query”-- Basic V$SESSION to V$PROCESS joinSELECT s.sid, s.serial#, s.username, s.status, s.program, p.spid AS os_pid, p.pga_used_mem/1024/1024 AS pga_mbFROM v$session sJOIN v$process p ON s.paddr = p.addrWHERE s.type = 'USER'ORDER BY p.pga_used_mem DESC;Understanding the Join
Section titled “Understanding the Join”Key Columns
Section titled “Key Columns”| V$SESSION Column | V$PROCESS Column | Purpose |
|---|---|---|
PADDR | ADDR | Join key - Process address |
SID | - | Session identifier |
SERIAL# | - | Session serial number |
USERNAME | - | Database user |
PROGRAM | - | Client program name |
| - | SPID | OS process ID |
| - | PGA_USED_MEM | PGA memory used |
The Join Explained
Section titled “The Join Explained”-- PADDR in V$SESSION points to ADDR in V$PROCESSFROM v$session sJOIN v$process p ON s.paddr = p.addrCommon Use Cases
Section titled “Common Use Cases”1. Find OS Process for a Session
Section titled “1. Find OS Process for a Session”-- Get OS PID for a specific SIDSELECT p.spid AS os_process_idFROM v$session sJOIN v$process p ON s.paddr = p.addrWHERE s.sid = &sid;2. Find Session from OS Process
Section titled “2. Find Session from OS Process”-- Get session details from OS PIDSELECT s.sid, s.serial#, s.username, s.status, s.sql_id, s.event, s.programFROM v$session sJOIN v$process p ON s.paddr = p.addrWHERE p.spid = '&os_pid';3. All Active Sessions with OS Details
Section titled “3. All Active Sessions with OS Details”-- Active sessions with full detailsSELECT s.sid, s.serial#, s.username, s.status, s.machine, s.program, p.spid AS os_pid, s.sql_id, s.event, s.seconds_in_wait, s.last_call_et AS seconds_activeFROM v$session sJOIN v$process p ON s.paddr = p.addrWHERE s.status = 'ACTIVE' AND s.type = 'USER'ORDER BY s.last_call_et DESC;4. Sessions Using Most Memory
Section titled “4. Sessions Using Most Memory”-- Top PGA consumersSELECT s.sid, s.serial#, s.username, s.program, p.spid AS os_pid, ROUND(p.pga_used_mem/1024/1024, 2) AS pga_used_mb, ROUND(p.pga_alloc_mem/1024/1024, 2) AS pga_alloc_mb, ROUND(p.pga_max_mem/1024/1024, 2) AS pga_max_mbFROM v$session sJOIN v$process p ON s.paddr = p.addrWHERE s.type = 'USER'ORDER BY p.pga_used_mem DESCFETCH FIRST 20 ROWS ONLY;5. Sessions with Current SQL
Section titled “5. Sessions with Current SQL”-- Sessions with their executing SQLSELECT s.sid, s.serial#, s.username, p.spid AS os_pid, s.sql_id, SUBSTR(q.sql_text, 1, 100) AS sql_textFROM v$session sJOIN v$process p ON s.paddr = p.addrLEFT JOIN v$sql q ON s.sql_id = q.sql_id AND s.sql_child_number = q.child_numberWHERE s.status = 'ACTIVE' AND s.type = 'USER'ORDER BY s.sid;6. Generate Kill Commands
Section titled “6. Generate Kill Commands”-- Generate OS kill commands for specific sessionsSELECT 'kill -9 ' || p.spid AS os_kill_command, 'ALTER SYSTEM KILL SESSION ''' || s.sid || ',' || s.serial# || ''' IMMEDIATE;' AS db_kill_command, s.username, s.programFROM v$session sJOIN v$process p ON s.paddr = p.addrWHERE s.username = '&username';RAC Considerations
Section titled “RAC Considerations”For RAC environments, include instance information:
-- RAC: Sessions across all instancesSELECT s.inst_id, s.sid, s.serial#, s.username, p.spid AS os_pid, s.programFROM gv$session sJOIN gv$process p ON s.paddr = p.addr AND s.inst_id = p.inst_idWHERE s.type = 'USER'ORDER BY s.inst_id, s.sid;Extended Join with More Views
Section titled “Extended Join with More Views”Include Wait Events
Section titled “Include Wait Events”SELECT s.sid, s.serial#, s.username, p.spid, s.event, s.wait_class, s.seconds_in_wait, sw.stateFROM v$session sJOIN v$process p ON s.paddr = p.addrJOIN v$session_wait sw ON s.sid = sw.sidWHERE s.type = 'USER' AND s.wait_class != 'Idle';Include Blocking Information
Section titled “Include Blocking Information”SELECT s.sid, s.serial#, s.username, p.spid AS os_pid, s.blocking_session, s.event, bs.username AS blocker_user, bp.spid AS blocker_os_pidFROM v$session sJOIN v$process p ON s.paddr = p.addrLEFT JOIN v$session bs ON s.blocking_session = bs.sidLEFT JOIN v$process bp ON bs.paddr = bp.addrWHERE s.blocking_session IS NOT NULL;Troubleshooting
Section titled “Troubleshooting”Session Not Found
Section titled “Session Not Found”If the join returns no rows, the session might be:
- A background process (filter with
s.type = 'USER') - Already disconnected
- Using a different address mapping
-- Check all session typesSELECT type, COUNT(*)FROM v$sessionGROUP BY type;Permission Issues
Section titled “Permission Issues”Required privileges:
GRANT SELECT ON v$session TO username;GRANT SELECT ON v$process TO username;-- Or grant the view roleGRANT SELECT_CATALOG_ROLE TO username;Related Scripts
Section titled “Related Scripts”- gvsess.sql - Active session analysis
- vprocess.sql - Process information
- vsession.sql - Session overview
- gvlockb.sql - Blocking lock analysis