如何列出Oracle中的活动/开放连接?

问题描述 投票:143回答:9

是否有任何隐藏的表,系统变量或某些东西在给定时刻显示活动连接?

oracle
9个回答
168
投票

使用V$SESSION视图。

V$SESSION显示每个当前会话的会话信息。


99
投票

有关更完整的答案,请参阅: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; 

26
投票

当我想查看从应用程序服务器到数据库的传入连接时,我使用以下命令:

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

简单但有效。


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;

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

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

4
投票

下面给出了按连接数排序的操作系统用户列表,这在查找过多的资源使用情况时很有用。

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

4
投票
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

此查询尝试过滤掉所有后台进程。


1
投票
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;
© www.soinside.com 2019 - 2024. All rights reserved.