Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase 12»»

CPU 100%, current queries show "CREATE PROCEDURE ... " Expand / Collapse
Author
Message
Posted Thursday, September 27, 2012 6:16 AM
SSC Rookie

SSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC Rookie

Group: General Forum Members
Last Login: Thursday, February 20, 2014 3:33 AM
Points: 30, Visits: 182
Hi,

I have a SQL Server 2005, which works fine and on some time it starts to use 100% of CPU. Then website is slow, get timeout messages etc.

I used this query to find current queries:

SELECT sqltext.TEXT,
req.session_id,
req.status,
req.command,
req.cpu_time,
req.total_elapsed_time
FROM sys.dm_exec_requests req
CROSS APPLY sys.dm_exec_sql_text(sql_handle) AS sqltext

When I run query above, it shows me about 40 records, and most of them are code for creating stored procedures. Same like when you go in Management Studio "Script stored procedure As", and then select "CREATE to".

So, it looks like these 3 stored procedures are constantly re-created.

After a while, I restarted the server and now it works fine. But, it repeats this behavior every day.

Anyone have an idea what could cause this?

Thanks!


Post #1365183
Posted Thursday, September 27, 2012 6:24 AM


SSCertifiable

SSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiable

Group: General Forum Members
Last Login: 2 days ago @ 8:55 AM
Points: 5,216, Visits: 5,064
Restarting SQL is not a good idea as it flushes it's cache and when it restarts has to build the cache again which makes performance worse (usually)

A good place to start would be here http://www.simple-talk.com/books/sql-books/troubleshooting-sql-server-a-guide-for-the-accidental-dba/ - Chapter 3 High CPU Utilisation.





Want an answer fast? Try here
How to post data/code for the best help - Jeff Moden
Need a string splitter, try this - Jeff Moden
How to post performance problems - Gail Shaw
CrossTabs-Part1 & Part2 - Jeff Moden
SQL Server Backup, Integrity Check, and Index and Statistics Maintenance - Ola Hallengren
Managing Transaction Logs - Gail Shaw
Troubleshooting SQL Server: A Guide for the Accidental DBA - Jonathan Kehayias and Ted Krueger

Post #1365186
Posted Thursday, September 27, 2012 6:57 AM
SSC-Enthusiastic

SSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-Enthusiastic

Group: General Forum Members
Last Login: Thursday, March 6, 2014 1:35 AM
Points: 178, Visits: 547
If you have access to SSMS 2008 you can right click on the instance name and select Activity Monitor.

This will give you a good place to start troubleshooting.




For better, quicker answers on T-SQL questions, read Jeff Moden's suggestions.

"Million-to-one chances crop up nine times out of ten." ― Terry Pratchett, Mort
Post #1365209
Posted Thursday, September 27, 2012 7:28 AM
SSC Rookie

SSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC Rookie

Group: General Forum Members
Last Login: Thursday, February 20, 2014 3:33 AM
Points: 30, Visits: 182
anthony.green (9/27/2012)
Restarting SQL is not a good idea as it flushes it's cache and when it restarts has to build the cache again which makes performance worse (usually)


It is production server. Users can't login, can't browse website and things become urgent.
Post #1365246
Posted Thursday, September 27, 2012 7:37 AM


SSC-Forever

SSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-Forever

Group: General Forum Members
Last Login: Today @ 1:15 AM
Points: 42,747, Visits: 35,837
The stored procedures are not being recreated. They're being executed.

Find the worst performing code, tune it. Repeat until performance acceptable.
http://www.simple-talk.com/sql/performance/finding-the-causes-of-poor-performance-in-sql-server,-part-1/
http://www.simple-talk.com/sql/performance/finding-the-causes-of-poor-performance-in-sql-server,-part-2/



Gail Shaw
Microsoft Certified Master: SQL Server 2008, MVP
SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability

We walk in the dark places no others will enter
We stand on the bridge and no one may pass

Post #1365262
Posted Thursday, September 27, 2012 7:39 AM
SSC Rookie

SSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC Rookie

Group: General Forum Members
Last Login: Thursday, February 20, 2014 3:33 AM
Points: 30, Visits: 182
D.Post (9/27/2012)
If you have access to SSMS 2008 you can right click on the instance name and select Activity Monitor.

This will give you a good place to start troubleshooting.


I checked current activity, and found that there is a lot of queries for creating of procedures.

The problem is, that queries should not be executed at all. That stored procedures already exist on server for a long time. No need to run CREATE PROCEDURE query for them at all.

I have no idea why these queries are executed on the first place


So, in certain time, SQL Server executes a lot of same queries for creating of same procedures (procedures already exist on server) and CPU goes 100%.

The queries which are executed in that time are useless, I don't need them at all, and don't know from where they are coming.

How that could be possible?


Post #1365265
Posted Thursday, September 27, 2012 7:42 AM
SSC Rookie

SSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC Rookie

Group: General Forum Members
Last Login: Thursday, February 20, 2014 3:33 AM
Points: 30, Visits: 182
GilaMonster (9/27/2012)
The stored procedures are not being recreated. They're being executed.

Find the worst performing code, tune it. Repeat until performance acceptable.
http://www.simple-talk.com/sql/performance/finding-the-causes-of-poor-performance-in-sql-server,-part-1/
http://www.simple-talk.com/sql/performance/finding-the-causes-of-poor-performance-in-sql-server,-part-2/


Gila,

thanks for replay.

Website is using procedures for showing data, that part works OK.

The problem is that current queries are scripts for creating procedures, not for executing them.
Post #1365267
Posted Thursday, September 27, 2012 7:44 AM


SSC-Forever

SSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-Forever

Group: General Forum Members
Last Login: Today @ 1:15 AM
Points: 42,747, Visits: 35,837
Boris Pazin (9/27/2012)
The problem is that current queries are scripts for creating procedures, not for executing them.


The procedures are not being created. They are being executed.
When you execute a procedure, the sql_text DMV shows the create so that you can use the statement offsets to get the exact statement executing.



Gail Shaw
Microsoft Certified Master: SQL Server 2008, MVP
SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability

We walk in the dark places no others will enter
We stand on the bridge and no one may pass

Post #1365269
Posted Thursday, September 27, 2012 7:53 AM
SSC Rookie

SSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC Rookie

Group: General Forum Members
Last Login: Thursday, February 20, 2014 3:33 AM
Points: 30, Visits: 182
GilaMonster (9/27/2012)
Boris Pazin (9/27/2012)
The problem is that current queries are scripts for creating procedures, not for executing them.


The procedures are not being created. They are being executed.
When you execute a procedure, the sql_text DMV shows the create so that you can use the statement offsets to get the exact statement executing.


Wow, that is interesting!

GilaMonster, you say, if I call query above to see current queries, it will show CREATE PROCEDURE text???

Must check this immediately
Post #1365276
Posted Thursday, September 27, 2012 8:16 AM
SSC Rookie

SSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC Rookie

Group: General Forum Members
Last Login: Thursday, February 20, 2014 3:33 AM
Points: 30, Visits: 182
GilaMonster (9/27/2012)
Boris Pazin (9/27/2012)
The problem is that current queries are scripts for creating procedures, not for executing them.


The procedures are not being created. They are being executed.
When you execute a procedure, the sql_text DMV shows the create so that you can use the statement offsets to get the exact statement executing.


Thanks!!!!

Things finally make sense.
Post #1365294
« Prev Topic | Next Topic »

Add to briefcase 12»»

Permissions Expand / Collapse