180

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

ROMANIA_engineer
  • 51,252
  • 26
  • 196
  • 186
pistacchio
  • 53,670
  • 101
  • 270
  • 404

9 Answers9

197

Use the V$SESSION view.

V$SESSION displays session information for each current session.

Yogesh lele
  • 362
  • 4
  • 16
PaulJWilliams
  • 18,549
  • 3
  • 49
  • 78
122

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; 
ehrhardt
  • 2,276
  • 1
  • 19
  • 13
32

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.

user2021477
  • 321
  • 3
  • 2
7
Select count(1) From V$session
where status='ACTIVE'
/
josliber
  • 43,000
  • 12
  • 95
  • 132
Juber
  • 71
  • 1
  • 1
7
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.

Yahya Hussein
  • 8,170
  • 15
  • 53
  • 100
Alan
  • 71
  • 1
  • 1
5
select
  username,
  osuser,
  terminal,
  utl_inaddr.get_host_address(terminal) IP_ADDRESS
from
  v$session
where
  username is not null
order by
  username,
  osuser;
josliber
  • 43,000
  • 12
  • 95
  • 132
user3848789
  • 69
  • 1
  • 1
4
select status, count(1) as connectionCount from V$SESSION group by status;
Tunaki
  • 125,519
  • 44
  • 317
  • 399
Fletch F Fletch
  • 363
  • 4
  • 7
4

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
maxschlepzig
  • 31,679
  • 12
  • 125
  • 164
jediz
  • 4,139
  • 5
  • 34
  • 38
2
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;
miracle173
  • 1,752
  • 13
  • 32
  • 2
    While this code snippet may solve the question, [including an explanation](http://meta.stackexchange.com/questions/114762/explaining-entirely-code-based-answers) really helps to improve the quality of your post. Remember that you are answering the question for readers in the future, and those people might not know the reasons for your code suggestion. – DimaSan Mar 07 '17 at 11:06