See who is logged into the database

This is a script that was passed down to me about eight years ago from another DBA and I have passed it on to others. I use it all the time to see who is logged into the database. I use it when I have to kill an OS process for a user connected to the database or just to see who is on.

To run, I log on to the database server and set my Oracle environment for the database I want to check using coraenv or oraenv. Then, I just type "on_ora_sid". This script runs a SQL script called "session.sql" and will query the Oracle V$Session tables and return the userid of people logged into the Oracle database identified SID.


#!/bin/csh -f
# This program will query the Oracle V$Session tables and return
# the userid of people logged in to the Oracle Database identified
# oracle_sid
echo ""
echo ""
echo "Users logged in to" $ORACLE_SID
sleep 3
sqlplus system/password @/ora01/scripts/dba_scripts/session.sql
echo ""


column username heading user format a10
column program heading running format a40
column status heading status format a9
column spid heading proc format a5
column lockwait heading lockwait format a8 
select sys.v_$session.username, 
from sys.v_$session, sys.v_$process
where sys.v_$session.paddr = sys.v_$process.addr 
and sys.v_$session.username is not null;

    Requires Free Membership to View

This was first published in June 2006

There are Comments. Add yours.

TIP: Want to include a code block in your comment? Use <pre> or <code> tags around the desired text. Ex: <code>insert code</code>

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy
Sort by: OldestNewest

Forgot Password?

No problem! Submit your e-mail address below. We'll send you an email containing your password.

Your password has been sent to:

Disclaimer: Our Tips Exchange is a forum for you to share technical advice and expertise with your peers and to learn from other enterprise IT professionals. TechTarget provides the infrastructure to facilitate this sharing of information. However, we cannot guarantee the accuracy or validity of the material submitted. You agree that your use of the Ask The Expert services and your reliance on any questions, answers, information or other materials received through this Web site is at your own risk.