How to list active / open connections in Oracle?

Oracle

Oracle Problem Overview


Is there any hidden table, system variable or something to show active connections in a given moment?

Oracle Solutions


Solution 1 - Oracle

Use the V$SESSION view.

> V$SESSION displays session information for each current session.

Solution 2 - Oracle

For a more complete answer see: http://dbaforums.org/oracle/index.php?showtopic=16834

select
       substr(a.spid,1,9) pid,
       substr(b.sid,1,5) sid,
       substr(b.serial#,1,5) ser#,
       substr(b.machine,1,6) box,
       substr(b.username,1,10) username,
--       b.server,
       substr(b.osuser,1,8) os_user,
       substr(b.program,1,30) program
from v$session b, v$process a
where
b.paddr = a.addr
and type='USER'
order by spid; 

Solution 3 - Oracle

When I'd like to view incoming connections from our application servers to the database I use the following command:

SELECT username FROM v$session 
WHERE username IS NOT NULL 
ORDER BY username ASC;

Simple, but effective.

Solution 4 - Oracle

Select count(1) From V$session
where status='ACTIVE'
/

Solution 5 - Oracle

select s.sid as "Sid", s.serial# as "Serial#", nvl(s.username, ' ') as "Username", s.machine as "Machine", s.schemaname as "Schema name", s.logon_time as "Login time", s.program as "Program", s.osuser as "Os user", s.status as "Status", nvl(s.process, ' ') as "OS Process id"
from v$session s
where nvl(s.username, 'a') not like 'a' and status like 'ACTIVE'
order by 1,2

This query attempts to filter out all background processes.

Solution 6 - Oracle

select
  username,
  osuser,
  terminal,
  utl_inaddr.get_host_address(terminal) IP_ADDRESS
from
  v$session
where
  username is not null
order by
  username,
  osuser;

Solution 7 - Oracle

select status, count(1) as connectionCount from V$SESSION group by status;

Solution 8 - Oracle

The following gives you list of operating system users sorted by number of connections, which is useful when looking for excessive resource usage.

select osuser, count(*) as active_conn_count 
from v$session 
group by osuser 
order by active_conn_count desc

Solution 9 - Oracle

select 
    count(1) "NO. Of DB Users", 
    to_char(sysdate,'DD-MON-YYYY:HH24:MI:SS') sys_time
from 
    v$session 
where 
    username is NOT  NULL;

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionpistacchioView Question on Stackoverflow
Solution 1 - OraclePaulJWilliamsView Answer on Stackoverflow
Solution 2 - OracleehrhardtView Answer on Stackoverflow
Solution 3 - Oracleuser2021477View Answer on Stackoverflow
Solution 4 - OracleJuberView Answer on Stackoverflow
Solution 5 - OracleAlanView Answer on Stackoverflow
Solution 6 - Oracleuser3848789View Answer on Stackoverflow
Solution 7 - OracleFletch F FletchView Answer on Stackoverflow
Solution 8 - OraclejedizView Answer on Stackoverflow
Solution 9 - Oraclekirankumar MView Answer on Stackoverflow