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


164

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

Answers:


183

使用V$SESSION视图。

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


5
从命令的第1行开始的错误:select * from FROM v $ session在命令行的错误:1列:14错误报告:SQL错误:ORA-00903:无效的表名00903。00000-“无效的表名” *原因:*行动:
pistacchio

3
您没有权限,或者没有正确安装DBA视图。
S.Lott

4
您将需要select_catalog_role角色。
PaulJWilliams,2009年

2
您也可以加入v $ sqltext获取会话的当前SQL。
阿尔金尼

27
pistacchio,您在SQL中有2个“ from FROM”:“ select * from FROM v $ session”
marcprux 2010年

116

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

28

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

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

简单但有效。


6
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

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


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

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
欢迎来到SO!请为您的答案提供一些直觉。
vefthym 2014年


4

以下提供了按连接数排序的操作系统用户列表,这在查找过度使用资源时很有用。

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

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;

1
尽管此代码段可以解决问题,但提供说明确实有助于提高您的帖子质量。请记住,您将来会为读者回答这个问题,而这些人可能不知道您提出代码建议的原因。
DimaSan
By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.