Blockings
Select 'Total user session:', count (*) from Sysprocesses where spid>51
Union all
Select 'Total active session:', count(*) from Sysprocesses where status<>'Sleeping'
Union all
Select 'Total blocked session:', count(*) from Sysprocesses where blocked<>0
------------------------------------------------------------------------------------------------------------------------
Current running Queries
SELECT [Link],
req.session_id,
[Link],
[Link],
req.cpu_time,
req.total_elapsed_time
FROM sys.dm_exec_requests req
CROSS APPLY sys.dm_exec_sql_text(sql_handle) AS sqltext
----------------------------------------------------------------
SELECT spid 'SPID',
blocked 'Blocked By',
[Link] 'Wait Type',
sp.open_tran 'Open Trans',
[Link] 'Status',
[Link] 'Wait Time',
cmd 'Command',
[Link] 'Login',
program_name'Program'
FROM master..sysprocesses AS sp
JOIN master..syslogins AS sl ON [Link] = [Link]
WHERE (blocked != 0
and blocked != spid)
OR spid IN (SELECT blocked FROM master..sysprocesses WHERE blocked != 0
and blocked != spid)
ORDER BY blocked, spid
Review details and document anything unusual
Select loginname, programname, hostname, blocked from Sysprocesses where status<>’Sleeping’
Blocking Query Text
SELECT
r.session_id,
r.blocking_session_id,
s.program_name,
s.host_name,
[Link]
FROM
sys.dm_exec_requests r
INNER JOIN sys.dm_exec_sessions s ON r.session_id = s.session_id
CROSS APPLY sys.dm_exec_sql_text(r.sql_handle) t
WHERE
s.is_user_process = 1 AND
r.session_id = SPID
-- For 2000
DBCC INPUTBUFFER(SPID)
No of Concurrent Users DB wise
SELECT db_name(dbid) as DatabaseName, count(dbid) as NoOfConnections,
loginame as LoginName
FROM [Link]
WHERE dbid > 0
GROUP BY dbid, loginame
SIZE of DB
select Name,
(convert(float,size)) * (8192.0/1048576) File_Size,
(convert(float,fileproperty(name,'SpaceUsed'))) * (8192.0/1048576)
MB_Used,
((convert(float,size)) * (8192.0/1048576) -
(convert(float,fileproperty(name,'SpaceUsed'))) * (8192.0/1048576))
MB_Free
from sysfiles
order by
fileproperty(name,'IsLogFile')
Query executing for Top 20 At present.
select top 20
[Link], [Link], total_worker_time/execution_count AS
AverageCPUTime,
CASE statement_end_offset
WHEN -1 THEN [Link]
ELSE
SUBSTRING([Link],statement_start_offset/2,statement_end_offset/2)
END AS StatementText
from sys.dm_exec_query_stats qs CROSS APPLY
sys.dm_exec_sql_text(qs.sql_handle) st
ORDER BY AverageCPUTime DESC
CPU % for Current Time
set nocount on declare @ts_now bigint
select @ts_now = cpu_ticks /( cpu_ticks / ms_ticks )
/*cpu_ticks / convert(float, cpu_ticks_in_ms)*/ from sys.dm_os_sys_info
select top 1 record_id,dateadd(ms, -1 * (@ts_now - [timestamp]),
GetDate()) as EventTime,
SQLProcessUtilization,SystemIdle,100 - SystemIdle -
SQLProcessUtilization as OtherProcessUtilization
from (select [Link]('(./Record/@id)[1]', 'int') as
record_id,
[Link]('(./Record/SchedulerMonitorEvent/SystemHealth/SystemIdle)
[1]', 'int') as SystemIdle,
[Link]('(./Record/SchedulerMonitorEvent/SystemHealth/ProcessUtiliz
ation)[1]', 'int') as SQLProcessUtilization,
timestamp from (select timestamp, convert(xml, record) as
record
from sys.dm_os_ring_buffers
where ring_buffer_type = N'RING_BUFFER_SCHEDULER_MONITOR'
and record like '%<SystemHealth>%') as x
) as y order by record_id desc
DB Wise CPU
Use <DB Name>
select db_name(database_id) DBName,sum(cpu_time) total_cpu
from sys.dm_exec_requests group by db_name(database_id)
Get DB Growth
Declare @OldestLog datetime,
@FirstLog int,
@SearchText nvarchar(50),
@DBName sysname
Declare @ErrorLog Table (LogID int identity(1, 1) not null primary key,
LogDate datetime null,
ProcessInfo nvarchar(100) null,
LogText nvarchar(max) null)
Declare @EnumLogs Table (ArchiveNum int not null primary key,
ArcDate Datetime not null,
LogFileSize bigint not null)
Set nocount On
Set @OldestLog = '2/20/2011'
Set @SearchText = N'pages dumped: '
Set @DBName = 'KomodoFCB_Prod_V6'
Insert Into @EnumLogs
Exec master..xp_enumerrorlogs
Select Top 1 @FirstLog = ArchiveNum
From @EnumLogs
Where ArcDate < @OldestLog
Order By ArcDate DESC
If @FirstLog Is Null
Begin
Select Top 1 @FirstLog = ArchiveNum
From @EnumLogs
Order By ArchiveNum DESC
End
While @FirstLog >= 0
Begin
Insert Into @ErrorLog (LogDate, ProcessInfo, LogText)
Exec master..xp_readerrorlog @FirstLog
Set @FirstLog = @FirstLog - 1
End
Select Convert(varchar, LogDate, 101) As BUPDate,
Cast(Cast((Cast(RTrim(LTrim(SubString(LogText, CharIndex(@SearchText, LogText) +
Len(@SearchText), CharIndex(',', LogText, CharIndex(@SearchText, LogText)) -
CharIndex(@SearchText, LogText) - Len(@SearchText)))) as BigInt) * 8.0)/1024 As Decimal(9, 2)) As
varchar) + ' MB' As BUPSize
From @ErrorLog
Where CharIndex('Backup', ProcessInfo) > 0
And CharIndex('Database backed up. Database: ' + @DBName, LogText) > 0
Order By LogDate Asc
Set nocount Off
Get who is the owner of DB