ITPub博客

首页 > 数据库 > Oracle > SQL 记录数据库连接数信息

SQL 记录数据库连接数信息

原创 Oracle 作者:kitesky 时间:2011-01-27 14:38:16 0 删除 编辑
从master.dbo.sysprocesses取连接数信息并记录的SQL。[@more@]

-- create connection_log
create table connection_log
(
time datetime,
date datetime,
hour int,
minute int,
second int,
dbname varchar(56),
connect_count int
)

-- catch data
set nocount on
declare @v_time datetime
while 1=1
begin
select @v_time = GETDATE()
select
@v_time as time,
convert(varchar(10), @v_time, 120) as date,
DATEPART(hour, @v_time) as hour,
DATEPART(minute, @v_time) as minute,
DATEPART(second, @v_time) as second,
DB_NAME(dbid) as datasbase,
count(*) as connect_count
from master.dbo.sysprocesses
where dbid <> 0
group by dbid

waitfor delay '00:00:01'
end

来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/66009/viewspace-1045257/ ,如需转载,请注明出处,否则将追究法律责任。

请登录后发表评论 登录
全部评论

注册时间:2009-04-22

  • 博文量
    273
  • 访问量
    2225416