Showing posts with label process. Show all posts
Showing posts with label process. Show all posts

Friday, March 30, 2012

How to differentiate process instances in perfmon

In a multi-instance cluster, how can you match a named sql server instance
with an instance of sqlservr.exe? When setting up counter collection in
perfmon, I choose the "process" performance object, then the "% processor
time" counter". In list of instances, I can see sqlservr#1, sqlservr#2, etc.
How do I know which named instance each of those represents?
TIA.
Hello
One way (I dont know if is the best way) is to match the ProcessID on
Process Counter from Performance Monitor to the ProcessID that is on the
ErrorLog from the Instance.
Something like:
PerfMon -> Process -> ProcessID -> Select SQLServer# on the instances.
Now go to SQL Server Enterprise Manager for each instance and look on the
ErrorLog for the line:
Server Process ID is 3636.
That should be easy if you need to do just on time.
Carlos Eduardo Selonke de Souza
http://carlos.geekbunker.org
"Denise" wrote:

> In a multi-instance cluster, how can you match a named sql server instance
> with an instance of sqlservr.exe? When setting up counter collection in
> perfmon, I choose the "process" performance object, then the "% processor
> time" counter". In list of instances, I can see sqlservr#1, sqlservr#2, etc.
> How do I know which named instance each of those represents?
> TIA.
|||That's a good idea, thanks for the suggestion.
I don't have access to the error log on all the servers, but I can use
SELECT SERVERPROPERTY ('processid')
"Carlos Eduardo Selonke de Souza" wrote:
[vbcol=seagreen]
> Hello
> One way (I dont know if is the best way) is to match the ProcessID on
> Process Counter from Performance Monitor to the ProcessID that is on the
> ErrorLog from the Instance.
> Something like:
> PerfMon -> Process -> ProcessID -> Select SQLServer# on the instances.
> Now go to SQL Server Enterprise Manager for each instance and look on the
> ErrorLog for the line:
> Server Process ID is 3636.
> That should be easy if you need to do just on time.
> --
> Carlos Eduardo Selonke de Souza
> http://carlos.geekbunker.org
>
> "Denise" wrote:

how to determine which process is ballooning tempdb

Help!
We have an exceptionally busy server with many databases used by many applic
ations. One or more processes is causing tempdb to grow very rapidly and eat
up the disk.
I need suggestions on how to figure out which of the hundreds of processes m
ight be doing this. It's like trying to find a needle in a haystack. Is ther
e some way to filter a Profiler trace which might help me identify who the c
ulprit might be?
Thanks.Good question,
I don't think there is a direct way to do that in Profiler, but... if you
add some of hte AutoGrow events in database event class... and you're
tracking stmt:completed events... and looking at writes... you should be
able to see some type of correlation. Haven't messed around to look for the
particular model you need... but it's interesting. I'll take a look at see
if I find a nice way to do it...
Brian Moran
Principal Mentor
Solid Quality Learning
SQL Server MVP
http://www.solidqualitylearning.com
"Marie Ramos" <RamosMar@.saccounty.net> wrote in message
news:D4061B10-528B-42BE-A58F-BA6331F4D5F4@.microsoft.com...
quote:

> Help!
> We have an exceptionally busy server with many databases used by many

applications. One or more processes is causing tempdb to grow very rapidly
and eat up the disk.
quote:

> I need suggestions on how to figure out which of the hundreds of processes

might be doing this. It's like trying to find a needle in a haystack. Is
there some way to filter a Profiler trace which might help me identify who
the culprit might be?
quote:

> Thanks.
>
|||also... I'm not sure where the waittype would be... but I'm sure the spid's
waiting on the autogrow to complete must be showing some sort of
distinguishing waittype in master..sysprocesses...
a little bit of testing should be able to help you figure out the waittype
while the spid is waiting for an autogrow to complete.... and that would
give you another way to narrow it down...
Brian
"Brian Moran" <brian@.solidqualitylearning.com> wrote in message news:...
quote:

> Good question,
> I don't think there is a direct way to do that in Profiler, but... if you
> add some of hte AutoGrow events in database event class... and you're
> tracking stmt:completed events... and looking at writes... you should be
> able to see some type of correlation. Haven't messed around to look for

the
quote:

> particular model you need... but it's interesting. I'll take a look at

see
quote:

> if I find a nice way to do it...
> --
> Brian Moran
> Principal Mentor
> Solid Quality Learning
> SQL Server MVP
> http://www.solidqualitylearning.com
>
> "Marie Ramos" <RamosMar@.saccounty.net> wrote in message
> news:D4061B10-528B-42BE-A58F-BA6331F4D5F4@.microsoft.com...
> applications. One or more processes is causing tempdb to grow very rapidly
> and eat up the disk.
processes[QUOTE]
> might be doing this. It's like trying to find a needle in a haystack. Is
> there some way to filter a Profiler trace which might help me identify who
> the culprit might be?
>
|||Hi Marie.
I don't actually know of a conclusive set of profiler filters, perfmon
settings or sysprocesses columns that would give you what you're after per
se (hopefully someone does), but have you tried looking at the output of
sp_who2's DiskIO column?
This isn't going to give you precisely the answer you're after but if you
identify which processes are consuming large amounts of disk io & perhaps
relatively less cpu, you may be able to quickly eliminate many of the other
processes & concentrate on those with these crude characteristics.
Hopefully someone else can produce a more scientific method but this might
help you get started.
Microsoft runs a program called sqlwish for sql server which allows you to
submit requests for features. Your request for a feature to track which
process is causing tempdb to grow sounds a good one imo, as many would
benefit from such a feature - sqlwish@.microsoft.com.
Regards,
Greg Linwood
"Marie Ramos" <RamosMar@.saccounty.net> wrote in message
news:D4061B10-528B-42BE-A58F-BA6331F4D5F4@.microsoft.com...
quote:

> Help!
> We have an exceptionally busy server with many databases used by many

applications. One or more processes is causing tempdb to grow very rapidly
and eat up the disk.
quote:

> I need suggestions on how to figure out which of the hundreds of processes

might be doing this. It's like trying to find a needle in a haystack. Is
there some way to filter a Profiler trace which might help me identify who
the culprit might be?
quote:

> Thanks.
>
|||Thanks for the sp_who2 tip. I think this may be helpful.
Do you know what the number in the Diskio column represents? If it's
zero, does that mean no disk io?
Marie
*** Sent via Developersdex http://www.examnotes.net ***
Don't just participate in USENET...get rewarded for it!|||Hi Marie.
Yep - eg select statements that are satisfied entirely by rows cached in
memory, therefore not needing to access the disk.
Regards,
Greg Linwood
"Marie Ramos" <ramosmar@.saccounty.net> wrote in message
news:O4MBKHc5DHA.2740@.TK2MSFTNGP09.phx.gbl...
quote:

> Thanks for the sp_who2 tip. I think this may be helpful.
> Do you know what the number in the Diskio column represents? If it's
> zero, does that mean no disk io?
> Marie
>
> *** Sent via Developersdex http://www.examnotes.net ***
> Don't just participate in USENET...get rewarded for it!

how to determine which process is ballooning tempdb

Help!
We have an exceptionally busy server with many databases used by many applications. One or more processes is causing tempdb to grow very rapidly and eat up the disk.
I need suggestions on how to figure out which of the hundreds of processes might be doing this. It's like trying to find a needle in a haystack. Is there some way to filter a Profiler trace which might help me identify who the culprit might be?
Thanks.Good question,
I don't think there is a direct way to do that in Profiler, but... if you
add some of hte AutoGrow events in database event class... and you're
tracking stmt:completed events... and looking at writes... you should be
able to see some type of correlation. Haven't messed around to look for the
particular model you need... but it's interesting. I'll take a look at see
if I find a nice way to do it...
--
Brian Moran
Principal Mentor
Solid Quality Learning
SQL Server MVP
http://www.solidqualitylearning.com
"Marie Ramos" <RamosMar@.saccounty.net> wrote in message
news:D4061B10-528B-42BE-A58F-BA6331F4D5F4@.microsoft.com...
> Help!
> We have an exceptionally busy server with many databases used by many
applications. One or more processes is causing tempdb to grow very rapidly
and eat up the disk.
> I need suggestions on how to figure out which of the hundreds of processes
might be doing this. It's like trying to find a needle in a haystack. Is
there some way to filter a Profiler trace which might help me identify who
the culprit might be?
> Thanks.
>|||Hi Marie.
I don't actually know of a conclusive set of profiler filters, perfmon
settings or sysprocesses columns that would give you what you're after per
se (hopefully someone does), but have you tried looking at the output of
sp_who2's DiskIO column?
This isn't going to give you precisely the answer you're after but if you
identify which processes are consuming large amounts of disk io & perhaps
relatively less cpu, you may be able to quickly eliminate many of the other
processes & concentrate on those with these crude characteristics.
Hopefully someone else can produce a more scientific method but this might
help you get started.
Microsoft runs a program called sqlwish for sql server which allows you to
submit requests for features. Your request for a feature to track which
process is causing tempdb to grow sounds a good one imo, as many would
benefit from such a feature - sqlwish@.microsoft.com.
Regards,
Greg Linwood
"Marie Ramos" <RamosMar@.saccounty.net> wrote in message
news:D4061B10-528B-42BE-A58F-BA6331F4D5F4@.microsoft.com...
> Help!
> We have an exceptionally busy server with many databases used by many
applications. One or more processes is causing tempdb to grow very rapidly
and eat up the disk.
> I need suggestions on how to figure out which of the hundreds of processes
might be doing this. It's like trying to find a needle in a haystack. Is
there some way to filter a Profiler trace which might help me identify who
the culprit might be?
> Thanks.
>sql

Monday, March 26, 2012

How to determine sql process responsible for system load

Hi
I administer sql databases at a local hospital and would occasionally like
to determine which sql server process/task is responsible for the load on
the system (cpu, memory etc) at a particular time.
The server hosts a largish number of databases for various 3rd party systems
and some in house systems primarily accessed in an interactive
(non-transactional) manner. I monitor system performance regularly and have
been noticing sustained periods (~5 mins) of high cpu usage (>50%) and disk
activity, which is not consistent with the normal pattern. I would like to
work out which database/application is responsible. At the same time SQL
compilations are low and the Buffer Manager looks healthy (ie Page life
expectancy, Cache Hits and Lizy Writes all good). Task Manager reports that
SQL Server is the application using the cpu time and the server does not run
any other applications.
The Current Activity in Enterprise Manager shows me all active connections
and processes but not their relative system load. The Profiler will show me
which processes are running and what they are doing, which is very useful,
however it does not show me what is running at the time I start the profile
log, which would typically be _after_ I have discovered that the system is
excessively loaded.
Is there any other way to get a snapshot of all active sql server processes
and their relative load/queryplan cost/size of returned recordset etc that
could give me a clue?
InterBase, for instance, has a Performance Monitor which gives a real-time
display of memory use, records fetched and much more per database and per
running query/procedure.
Thanks & Regards
Bas
========================================
==
Bas Groeneveld
Benchmark Design System and Software Engineering
PO Box 165N, Ballarat North, VIC 3350
Phone: +61 3 5333 5441 Mob: 0409 954 501Forgot to mention that we are running SQL Server 2000 SP3
Bas
"Bas Groeneveld" <nospam@.nospam.com.au> wrote in message
news:1aReg.252$ap3.32@.news-server.bigpond.net.au...
> Hi
> I administer sql databases at a local hospital and would occasionally like
> to determine which sql server process/task is responsible for the load on
> the system (cpu, memory etc) at a particular time.
> The server hosts a largish number of databases for various 3rd party
systems
> and some in house systems primarily accessed in an interactive
> (non-transactional) manner. I monitor system performance regularly and
have
> been noticing sustained periods (~5 mins) of high cpu usage (>50%) and
disk
> activity, which is not consistent with the normal pattern. I would like to
> work out which database/application is responsible. At the same time SQL
> compilations are low and the Buffer Manager looks healthy (ie Page life
> expectancy, Cache Hits and Lizy Writes all good). Task Manager reports
that
> SQL Server is the application using the cpu time and the server does not
run
> any other applications.
> The Current Activity in Enterprise Manager shows me all active connections
> and processes but not their relative system load. The Profiler will show
me
> which processes are running and what they are doing, which is very useful,
> however it does not show me what is running at the time I start the
profile
> log, which would typically be _after_ I have discovered that the system is
> excessively loaded.
> Is there any other way to get a snapshot of all active sql server
processes
> and their relative load/queryplan cost/size of returned recordset etc that
> could give me a clue?
> InterBase, for instance, has a Performance Monitor which gives a real-time
> display of memory use, records fetched and much more per database and per
> running query/procedure.
> Thanks & Regards
> Bas
> --
> ========================================
==
> Bas Groeneveld
> Benchmark Design System and Software Engineering
> PO Box 165N, Ballarat North, VIC 3350
> Phone: +61 3 5333 5441 Mob: 0409 954 501
>
>|||Hi Bas,
You best bet is probably running profiler. You should be able to get a
pretty good overview of what's going on within SQL Server during your busy
times. You will be able to identify any long running queries and there's eve
n
a column for CPU usage per event.
Ray
"Bas Groeneveld" wrote:

> Forgot to mention that we are running SQL Server 2000 SP3
> Bas
> "Bas Groeneveld" <nospam@.nospam.com.au> wrote in message
> news:1aReg.252$ap3.32@.news-server.bigpond.net.au...
> systems
> have
> disk
> that
> run
> me
> profile
> processes
>
>|||Hi Bas,
You best bet is probably running profiler. You should be able to get a
pretty good overview of what's going on within SQL Server during your busy
times. You will be able to identify any long running queries and there's eve
n
a column for CPU usage per event.
Ray
"Bas Groeneveld" wrote:

> Forgot to mention that we are running SQL Server 2000 SP3
> Bas
> "Bas Groeneveld" <nospam@.nospam.com.au> wrote in message
> news:1aReg.252$ap3.32@.news-server.bigpond.net.au...
> systems
> have
> disk
> that
> run
> me
> profile
> processes
>
>|||Thanks for the reply Ray.
My only problem is how to determine which queries are already running when I
start the profiler (as I usually start it _after_ I realise that there is an
excessive load). Is there a way to do this?
If there is no way to do that I would need to run both profiler and
performance monitor logging to files for a period of time and then work it
out from the log files. This is possible of course, I was just wondering if
there was another way.
Cheers
Bas
"rb" <rb@.discussions.microsoft.com> wrote in message
news:C94751DD-9ECE-46DA-A288-47086356B167@.microsoft.com...
> Hi Bas,
> You best bet is probably running profiler. You should be able to get a
> pretty good overview of what's going on within SQL Server during your busy
> times. You will be able to identify any long running queries and there's
even[vbcol=seagreen]
> a column for CPU usage per event.
> Ray
> "Bas Groeneveld" wrote:
>
like[vbcol=seagreen]
on[vbcol=seagreen]
like to[vbcol=seagreen]
SQL[vbcol=seagreen]
life[vbcol=seagreen]
not[vbcol=seagreen]
connections[vbcol=seagreen]
show[vbcol=seagreen]
useful,[vbcol=seagreen]
system is[vbcol=seagreen]
that[vbcol=seagreen]
real-time[vbcol=seagreen]
per[vbcol=seagreen]|||Thanks for the reply Ray.
My only problem is how to determine which queries are already running when I
start the profiler (as I usually start it _after_ I realise that there is an
excessive load). Is there a way to do this?
If there is no way to do that I would need to run both profiler and
performance monitor logging to files for a period of time and then work it
out from the log files. This is possible of course, I was just wondering if
there was another way.
Cheers
Bas
"rb" <rb@.discussions.microsoft.com> wrote in message
news:C94751DD-9ECE-46DA-A288-47086356B167@.microsoft.com...
> Hi Bas,
> You best bet is probably running profiler. You should be able to get a
> pretty good overview of what's going on within SQL Server during your busy
> times. You will be able to identify any long running queries and there's
even[vbcol=seagreen]
> a column for CPU usage per event.
> Ray
> "Bas Groeneveld" wrote:
>
like[vbcol=seagreen]
on[vbcol=seagreen]
like to[vbcol=seagreen]
SQL[vbcol=seagreen]
life[vbcol=seagreen]
not[vbcol=seagreen]
connections[vbcol=seagreen]
show[vbcol=seagreen]
useful,[vbcol=seagreen]
system is[vbcol=seagreen]
that[vbcol=seagreen]
real-time[vbcol=seagreen]
per[vbcol=seagreen]|||Hi Bas,
You could run DBCC Inputbuffer to check what query is being run (if you have
identified the spid first), you could also run sp_who2 for more info on the
queries being executed by all users. If you suspect locking/dead locks you
could enable trace flags 1204 (and 1205 I think) and get info posted to the
SQL error log.
You could run profiler and only filter out long running queries but as you
say you need to run this prior to the problem occuring to gather useful
information. You would get I/O and cpu stats from profiler so it may we wort
h
running if this problem occurs often.
Ray
"Bas Groeneveld" wrote:

> Thanks for the reply Ray.
> My only problem is how to determine which queries are already running when
I
> start the profiler (as I usually start it _after_ I realise that there is
an
> excessive load). Is there a way to do this?
> If there is no way to do that I would need to run both profiler and
> performance monitor logging to files for a period of time and then work it
> out from the log files. This is possible of course, I was just wondering i
f
> there was another way.
> Cheers
> Bas
>
> "rb" <rb@.discussions.microsoft.com> wrote in message
> news:C94751DD-9ECE-46DA-A288-47086356B167@.microsoft.com...
> even
> like
> on
> like to
> SQL
> life
> not
> connections
> show
> useful,
> system is
> that
> real-time
> per
>
>|||Hi Bas,
You could run DBCC Inputbuffer to check what query is being run (if you have
identified the spid first), you could also run sp_who2 for more info on the
queries being executed by all users. If you suspect locking/dead locks you
could enable trace flags 1204 (and 1205 I think) and get info posted to the
SQL error log.
You could run profiler and only filter out long running queries but as you
say you need to run this prior to the problem occuring to gather useful
information. You would get I/O and cpu stats from profiler so it may we wort
h
running if this problem occurs often.
Ray
"Bas Groeneveld" wrote:

> Thanks for the reply Ray.
> My only problem is how to determine which queries are already running when
I
> start the profiler (as I usually start it _after_ I realise that there is
an
> excessive load). Is there a way to do this?
> If there is no way to do that I would need to run both profiler and
> performance monitor logging to files for a period of time and then work it
> out from the log files. This is possible of course, I was just wondering i
f
> there was another way.
> Cheers
> Bas
>
> "rb" <rb@.discussions.microsoft.com> wrote in message
> news:C94751DD-9ECE-46DA-A288-47086356B167@.microsoft.com...
> even
> like
> on
> like to
> SQL
> life
> not
> connections
> show
> useful,
> system is
> that
> real-time
> per
>
>

How to determine sql process responsible for system load

Hi
I administer sql databases at a local hospital and would occasionally like
to determine which sql server process/task is responsible for the load on
the system (cpu, memory etc) at a particular time.
The server hosts a largish number of databases for various 3rd party systems
and some in house systems primarily accessed in an interactive
(non-transactional) manner. I monitor system performance regularly and have
been noticing sustained periods (~5 mins) of high cpu usage (>50%) and disk
activity, which is not consistent with the normal pattern. I would like to
work out which database/application is responsible. At the same time SQL
compilations are low and the Buffer Manager looks healthy (ie Page life
expectancy, Cache Hits and Lizy Writes all good). Task Manager reports that
SQL Server is the application using the cpu time and the server does not run
any other applications.
The Current Activity in Enterprise Manager shows me all active connections
and processes but not their relative system load. The Profiler will show me
which processes are running and what they are doing, which is very useful,
however it does not show me what is running at the time I start the profile
log, which would typically be _after_ I have discovered that the system is
excessively loaded.
Is there any other way to get a snapshot of all active sql server processes
and their relative load/queryplan cost/size of returned recordset etc that
could give me a clue?
InterBase, for instance, has a Performance Monitor which gives a real-time
display of memory use, records fetched and much more per database and per
running query/procedure.
Thanks & Regards
Bas
--
========================================== Bas Groeneveld
Benchmark Design System and Software Engineering
PO Box 165N, Ballarat North, VIC 3350
Phone: +61 3 5333 5441 Mob: 0409 954 501Forgot to mention that we are running SQL Server 2000 SP3
Bas
"Bas Groeneveld" <nospam@.nospam.com.au> wrote in message
news:1aReg.252$ap3.32@.news-server.bigpond.net.au...
> Hi
> I administer sql databases at a local hospital and would occasionally like
> to determine which sql server process/task is responsible for the load on
> the system (cpu, memory etc) at a particular time.
> The server hosts a largish number of databases for various 3rd party
systems
> and some in house systems primarily accessed in an interactive
> (non-transactional) manner. I monitor system performance regularly and
have
> been noticing sustained periods (~5 mins) of high cpu usage (>50%) and
disk
> activity, which is not consistent with the normal pattern. I would like to
> work out which database/application is responsible. At the same time SQL
> compilations are low and the Buffer Manager looks healthy (ie Page life
> expectancy, Cache Hits and Lizy Writes all good). Task Manager reports
that
> SQL Server is the application using the cpu time and the server does not
run
> any other applications.
> The Current Activity in Enterprise Manager shows me all active connections
> and processes but not their relative system load. The Profiler will show
me
> which processes are running and what they are doing, which is very useful,
> however it does not show me what is running at the time I start the
profile
> log, which would typically be _after_ I have discovered that the system is
> excessively loaded.
> Is there any other way to get a snapshot of all active sql server
processes
> and their relative load/queryplan cost/size of returned recordset etc that
> could give me a clue?
> InterBase, for instance, has a Performance Monitor which gives a real-time
> display of memory use, records fetched and much more per database and per
> running query/procedure.
> Thanks & Regards
> Bas
> --
> ==========================================> Bas Groeneveld
> Benchmark Design System and Software Engineering
> PO Box 165N, Ballarat North, VIC 3350
> Phone: +61 3 5333 5441 Mob: 0409 954 501
>
>|||Hi Bas,
You best bet is probably running profiler. You should be able to get a
pretty good overview of what's going on within SQL Server during your busy
times. You will be able to identify any long running queries and there's even
a column for CPU usage per event.
Ray
"Bas Groeneveld" wrote:
> Forgot to mention that we are running SQL Server 2000 SP3
> Bas
> "Bas Groeneveld" <nospam@.nospam.com.au> wrote in message
> news:1aReg.252$ap3.32@.news-server.bigpond.net.au...
> > Hi
> >
> > I administer sql databases at a local hospital and would occasionally like
> > to determine which sql server process/task is responsible for the load on
> > the system (cpu, memory etc) at a particular time.
> >
> > The server hosts a largish number of databases for various 3rd party
> systems
> > and some in house systems primarily accessed in an interactive
> > (non-transactional) manner. I monitor system performance regularly and
> have
> > been noticing sustained periods (~5 mins) of high cpu usage (>50%) and
> disk
> > activity, which is not consistent with the normal pattern. I would like to
> > work out which database/application is responsible. At the same time SQL
> > compilations are low and the Buffer Manager looks healthy (ie Page life
> > expectancy, Cache Hits and Lizy Writes all good). Task Manager reports
> that
> > SQL Server is the application using the cpu time and the server does not
> run
> > any other applications.
> >
> > The Current Activity in Enterprise Manager shows me all active connections
> > and processes but not their relative system load. The Profiler will show
> me
> > which processes are running and what they are doing, which is very useful,
> > however it does not show me what is running at the time I start the
> profile
> > log, which would typically be _after_ I have discovered that the system is
> > excessively loaded.
> >
> > Is there any other way to get a snapshot of all active sql server
> processes
> > and their relative load/queryplan cost/size of returned recordset etc that
> > could give me a clue?
> >
> > InterBase, for instance, has a Performance Monitor which gives a real-time
> > display of memory use, records fetched and much more per database and per
> > running query/procedure.
> >
> > Thanks & Regards
> > Bas
> >
> > --
> >
> > ==========================================> > Bas Groeneveld
> > Benchmark Design System and Software Engineering
> > PO Box 165N, Ballarat North, VIC 3350
> > Phone: +61 3 5333 5441 Mob: 0409 954 501
> >
> >
> >
>
>|||Thanks for the reply Ray.
My only problem is how to determine which queries are already running when I
start the profiler (as I usually start it _after_ I realise that there is an
excessive load). Is there a way to do this?
If there is no way to do that I would need to run both profiler and
performance monitor logging to files for a period of time and then work it
out from the log files. This is possible of course, I was just wondering if
there was another way.
Cheers
Bas
"rb" <rb@.discussions.microsoft.com> wrote in message
news:C94751DD-9ECE-46DA-A288-47086356B167@.microsoft.com...
> Hi Bas,
> You best bet is probably running profiler. You should be able to get a
> pretty good overview of what's going on within SQL Server during your busy
> times. You will be able to identify any long running queries and there's
even
> a column for CPU usage per event.
> Ray
> "Bas Groeneveld" wrote:
> > Forgot to mention that we are running SQL Server 2000 SP3
> >
> > Bas
> >
> > "Bas Groeneveld" <nospam@.nospam.com.au> wrote in message
> > news:1aReg.252$ap3.32@.news-server.bigpond.net.au...
> > > Hi
> > >
> > > I administer sql databases at a local hospital and would occasionally
like
> > > to determine which sql server process/task is responsible for the load
on
> > > the system (cpu, memory etc) at a particular time.
> > >
> > > The server hosts a largish number of databases for various 3rd party
> > systems
> > > and some in house systems primarily accessed in an interactive
> > > (non-transactional) manner. I monitor system performance regularly and
> > have
> > > been noticing sustained periods (~5 mins) of high cpu usage (>50%) and
> > disk
> > > activity, which is not consistent with the normal pattern. I would
like to
> > > work out which database/application is responsible. At the same time
SQL
> > > compilations are low and the Buffer Manager looks healthy (ie Page
life
> > > expectancy, Cache Hits and Lizy Writes all good). Task Manager reports
> > that
> > > SQL Server is the application using the cpu time and the server does
not
> > run
> > > any other applications.
> > >
> > > The Current Activity in Enterprise Manager shows me all active
connections
> > > and processes but not their relative system load. The Profiler will
show
> > me
> > > which processes are running and what they are doing, which is very
useful,
> > > however it does not show me what is running at the time I start the
> > profile
> > > log, which would typically be _after_ I have discovered that the
system is
> > > excessively loaded.
> > >
> > > Is there any other way to get a snapshot of all active sql server
> > processes
> > > and their relative load/queryplan cost/size of returned recordset etc
that
> > > could give me a clue?
> > >
> > > InterBase, for instance, has a Performance Monitor which gives a
real-time
> > > display of memory use, records fetched and much more per database and
per
> > > running query/procedure.
> > >
> > > Thanks & Regards
> > > Bas
> > >
> > > --
> > >
> > > ==========================================> > > Bas Groeneveld
> > > Benchmark Design System and Software Engineering
> > > PO Box 165N, Ballarat North, VIC 3350
> > > Phone: +61 3 5333 5441 Mob: 0409 954 501
> > >
> > >
> > >
> >
> >
> >|||Hi Bas,
You could run DBCC Inputbuffer to check what query is being run (if you have
identified the spid first), you could also run sp_who2 for more info on the
queries being executed by all users. If you suspect locking/dead locks you
could enable trace flags 1204 (and 1205 I think) and get info posted to the
SQL error log.
You could run profiler and only filter out long running queries but as you
say you need to run this prior to the problem occuring to gather useful
information. You would get I/O and cpu stats from profiler so it may we worth
running if this problem occurs often.
Ray
"Bas Groeneveld" wrote:
> Thanks for the reply Ray.
> My only problem is how to determine which queries are already running when I
> start the profiler (as I usually start it _after_ I realise that there is an
> excessive load). Is there a way to do this?
> If there is no way to do that I would need to run both profiler and
> performance monitor logging to files for a period of time and then work it
> out from the log files. This is possible of course, I was just wondering if
> there was another way.
> Cheers
> Bas
>
> "rb" <rb@.discussions.microsoft.com> wrote in message
> news:C94751DD-9ECE-46DA-A288-47086356B167@.microsoft.com...
> > Hi Bas,
> >
> > You best bet is probably running profiler. You should be able to get a
> > pretty good overview of what's going on within SQL Server during your busy
> > times. You will be able to identify any long running queries and there's
> even
> > a column for CPU usage per event.
> >
> > Ray
> >
> > "Bas Groeneveld" wrote:
> >
> > > Forgot to mention that we are running SQL Server 2000 SP3
> > >
> > > Bas
> > >
> > > "Bas Groeneveld" <nospam@.nospam.com.au> wrote in message
> > > news:1aReg.252$ap3.32@.news-server.bigpond.net.au...
> > > > Hi
> > > >
> > > > I administer sql databases at a local hospital and would occasionally
> like
> > > > to determine which sql server process/task is responsible for the load
> on
> > > > the system (cpu, memory etc) at a particular time.
> > > >
> > > > The server hosts a largish number of databases for various 3rd party
> > > systems
> > > > and some in house systems primarily accessed in an interactive
> > > > (non-transactional) manner. I monitor system performance regularly and
> > > have
> > > > been noticing sustained periods (~5 mins) of high cpu usage (>50%) and
> > > disk
> > > > activity, which is not consistent with the normal pattern. I would
> like to
> > > > work out which database/application is responsible. At the same time
> SQL
> > > > compilations are low and the Buffer Manager looks healthy (ie Page
> life
> > > > expectancy, Cache Hits and Lizy Writes all good). Task Manager reports
> > > that
> > > > SQL Server is the application using the cpu time and the server does
> not
> > > run
> > > > any other applications.
> > > >
> > > > The Current Activity in Enterprise Manager shows me all active
> connections
> > > > and processes but not their relative system load. The Profiler will
> show
> > > me
> > > > which processes are running and what they are doing, which is very
> useful,
> > > > however it does not show me what is running at the time I start the
> > > profile
> > > > log, which would typically be _after_ I have discovered that the
> system is
> > > > excessively loaded.
> > > >
> > > > Is there any other way to get a snapshot of all active sql server
> > > processes
> > > > and their relative load/queryplan cost/size of returned recordset etc
> that
> > > > could give me a clue?
> > > >
> > > > InterBase, for instance, has a Performance Monitor which gives a
> real-time
> > > > display of memory use, records fetched and much more per database and
> per
> > > > running query/procedure.
> > > >
> > > > Thanks & Regards
> > > > Bas
> > > >
> > > > --
> > > >
> > > > ==========================================> > > > Bas Groeneveld
> > > > Benchmark Design System and Software Engineering
> > > > PO Box 165N, Ballarat North, VIC 3350
> > > > Phone: +61 3 5333 5441 Mob: 0409 954 501
> > > >
> > > >
> > > >
> > >
> > >
> > >
>
>sql

Monday, March 19, 2012

How to detect a stored proc is running from TSQL?

I launch a stored proc from a job that is scheduled several times a day. I want the proc to detect if it is still running (from a previous process) and exit out if it is. I want to be absolutely sure it is or is not running.

Thanks!

I don't know of a straight forward way to check if a stored prcocedure is running but I have a couple of workarounds. Before that I just want to highlight if the only source that is running the stored procedure is the job you're talking about, then if it is still running and it is time for the next job, the next instance won't run so you wouldn't have the case that 2 job instances are running in the same time. Regardless here are the workarounds:

Include in your database a table that you can use to check the status of the stored procedure. For example a table called SystemStatus that includes a Key column and a Status column. Add a row for this procedure with initial value in the status false (for not running). Make the first statement in the procedure a check on the value of the status field for this row. If it true then another instance is running so end the procedure. If it is false then update it to true and let the final statement in the procedure update it back to false|||

I can't able to understand "I want the proc to detect if it is still running (from a previous process) and exit out if it is"

You mean, to find the current SP is already running on your Server (or job) before executing it.

If yes, you need not worry about it. Bcs if the current job is executing then the SQL server never initate the next scheduled job, it will wait to complete the current job, then it will find the next possible schedule to execute.

if you 2 or more parllel jobs with same SP (not really required) then you need to follow some log based events.

|||

Sami,

Thank you for your quick and detailed response. Actually I have used this method before. Unfortunately, this transaction is what I wanted to avoid here because it is a long-running proc that runs many other procs so I wanted to avoid holding blocking other users just to prevent my proc from running simultaneously. Thanks again!

Mr. P.

|||

You could use application locks in SQL Server. Something like below should work. This can be simplified a bit in SQL Server 2005.

Code Snippet

exec @.rc = sp_getapplock 'Only_this_SP', 'Exclusive', default, 0

if @.rc = -1

begin

-- SP is already running:

end

-- Release lock at end of SP:

exec @.rc = sp_releaseapplock 'Only_this_SP'

Sunday, February 19, 2012

How to delay queue processing?

I am looking for some suggestions on how to implement a delay in processing
queue elements. For example, I am using a queue to process requests to call
a web service. If the web service is unable to process a particular request,
I would like that request to be retried 5 minutes from now while continuing
to process other requests that may be in the queue. I suspect I may need
additional queues, such as a delay queue. Any ideas would be appreciated.

TIA -- Keith.Conversation Timers can be used to do something periodically or to do something after a fixed delay. You can either keep the same dialog you received the message came in on, set a timer and then send the message again when the timer message is received or else put the messages on a different queue and then process that queue periodically. The first option will require keeping the message body around somewhere - either by using retension on the queue or by keeping it in a seperate table (maybe indexed by dialogID).

Here's a little sample that uses timere to do something once a minute:

-- Set up a queue for the timer sample

CREATE QUEUE [TimerQueue]

CREATE SERVICE [TimerService] ON QUEUE [TimerQueue]([DEFAULT]) ;

CREATE SERVICE [TimerResponseService] ON QUEUE [TimerQueue];

GO

-- Create the stored procedure to handle the timer messages

CREATE PROCEDURE [dbo].[HandleTimer] AS

DECLARE @.conversationHandle uniqueidentifier

DECLARE @.message_type_name sysname

DECLARE @.dialog uniqueidentifier

BEGIN TRANSACTION

-- Timer messages only happen once a minute so there's no

-- need to receive in a loop.

WAITFOR (

RECEIVE top(1)

@.message_type_name=message_type_name,

@.dialog = conversation_handle

FROM [TimerQueue]

), TIMEOUT 500

IF (@.message_type_name = 'http://schemas.microsoft.com/SQL/ServiceBroker/DialogTimer')

BEGIN

-- Start the next cycle

BEGIN CONVERSATION TIMER ( @.dialog ) TIMEOUT = 60;

-- Do Whatever you want to do here

END

COMMIT TRANSACTION

go

ALTER QUEUE [TimerQueue] WITH ACTIVATION (

STATUS = ON, PROCEDURE_NAME = HandleTimer ,

MAX_QUEUE_READERS = 1,EXECUTE AS SELF)

go

DECLARE @.conversationHandle uniqueidentifier

BEGIN DIALOG CONVERSATION @.conversationHandle

FROM SERVICE [TimerResponseService]

TO SERVICE 'TimerService';

BEGIN CONVERSATION TIMER ( @.ConversationHandle ) TIMEOUT = 60;