Posted on Thursday, 9th April 2009 by kwatog
In my previous job, I have been too attached with DBArtisan that I sometimes no longer bother to know how to manually configure things in the database using plain SQL. With the lack of more advanced SQL editors and DBA tools in my current job, I had to rely on plain SQL to do all things from trivial to advanced tasks. One such task I failed to know is to manually monitor the processes running on the server.
To cut my introduction short, the script below will help you monitor processes on your database. Take note that you’ll need necessary rights to be able to run it.
select spid, status, blocked, open_tran, waitresource, waittype,
waittime, cmd, lastwaittype, cpu, physical_io,
hostname, hostprocess, loginame, program_name, net_address,
net_library, dbid, ecid, kpid, nt_domain, nt_username, uid, sid,
memusage, last_batch=convert(varchar(26), last_batch,121),
login_time=convert(varchar(26), login_time,121)
from master.dbo.sysprocesses
--where (blocked!=0 or waittype != 0x0000)
If you only want to see those that are blocking or locking, uncomment the last line. One thing that’s lacking here is the list of tables and database objects that each process id is using. That’s important if a user is running stored procedures and you need to know . I’ll provide that later as honestly, I don’t know yet which table holds that information.
Read the rest of this entry…
Tags: blocking, locking, monitor processes, SQL Server
Posted in Advanced, Performance Tuning, SQL Server | Comments (0)