Managing Oracle Sessions: Find and Kill Sessions Using OS Process ID (SPID)
In Oracle databases, each session running in the database corresponds to an Operating System (OS) process. If a session is consuming high CPU, memory, or blocking other sessions, you may need to find and terminate it.
This document provides detailed queries to:
✔ Find database session details using OS Process ID (SPID)
✔ Generate an ALTER SYSTEM KILL SESSION
command for RAC & Non-RAC
✔ Kill a session directly from the OS if needed
🔹 Finding Oracle Database Session Using OS Process ID
Use the following SQL query to fetch session details using the SPID (OS Process ID).
🔹 Query for RAC (Multi-Instance Environment)
🔹 Query for Single-Instance Database
🔹 Understanding the Query Output
Column | Description |
---|---|
inst_id | Instance ID (for RAC databases) |
sid | Oracle Session ID |
serial# | Serial number of the session |
username | Database user associated with the session |
osuser | OS user running the session |
machine | Host machine name |
program | Application or tool running the session |
module | Module name of the running query |
status | Session status (ACTIVE/INACTIVE) |
sql_id | SQL ID of the executing SQL statement |
event | Wait event (if the session is waiting on a resource) |
os_process_id | OS Process ID (SPID) of the session |
kill_command | Generated SQL command to kill the session |
🔹 How to Get OS Process ID (SPID)
If you do not know the OS process ID, you can list all active sessions:
You can also get the top CPU-consuming sessions:
Post a Comment
Post a Comment