SQL to monitor sessions in an Oracle database
Here is a SQL script that you can use to monitor Oracle database sessions:
-- Query to monitor Oracle database sessions
SELECT s.sid, s.serial#, s.username, s.status, s.machine, s.program, s.osuser, s.process, s.logon_time
FROM v$session s
WHERE s.type = 'USER'
ORDER BY s.logon_time ASC;
This script queries the v$session
view, which contains information about all the sessions currently connected to the database. The WHERE
clause filters the rows to show only user sessions, and the ORDER BY
clause sorts the results by logon time in ascending order.
The columns in the v$session
view include:
sid
: the session ID of the sessionserial#
: the serial number of the sessionusername
: the username of the user connected to the sessionstatus
: the status of the session (e.g. ACTIVE, INACTIVE)machine
: the name of the machine from which the session is connectedprogram
: the name of the program connected to the sessionosuser
: the operating system user associated with the sessionprocess
: the process ID of the sessionlogon_time
: the time at which the session was established
You can modify this script to include other columns from the v$session
view, or add additional filters to the WHERE
clause to narrow down the results.
Comments