如何在 Oracle 中列出活动/打开的连接?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/1043096/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to list active / open connections in Oracle?
提问by pistacchio
Is there any hidden table, system variable or something to show active connections in a given moment?
是否有任何隐藏表、系统变量或某些东西可以显示给定时刻的活动连接?
回答by PaulJWilliams
回答by ehrhardt
For a more complete answer see: http://dbaforums.org/oracle/index.php?showtopic=16834
有关更完整的答案,请参阅: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;
回答by user2021477
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.
简单,但有效。
回答by Alan
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.
此查询尝试过滤掉所有后台进程。
回答by user3848789
select
username,
osuser,
terminal,
utl_inaddr.get_host_address(terminal) IP_ADDRESS
from
v$session
where
username is not null
order by
username,
osuser;
回答by Juber
Select count(1) From V$session
where status='ACTIVE'
/
回答by Fletch F Fletch
select status, count(1) as connectionCount from V$SESSION group by status;
回答by jediz
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
回答by kirankumar M
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;