| Author |
Topic |
|
SamC
White Water Yakist
3467 Posts |
Posted - 2004-05-24 : 11:52:35
|
| I'm getting bitten by timeouts executing stored procs. Dropping the proc and recreating the proc always resolves the problem. 2nd time in two days.I ran a DBCC FREEPROCCACHE earlier today. Didn't seem to help much.Not indexes. The DB is reindexed every night.Any ideas?Sam |
|
|
gwhiz
Yak Posting Veteran
78 Posts |
Posted - 2004-05-24 : 12:07:21
|
| Make sure you statistics are up to date. Is this a production sp? Have you tried using WITH RECOMPILE? Have you looked at the execution plan to see how they are different? |
 |
|
|
tkizer
Almighty SQL Goddess
38200 Posts |
Posted - 2004-05-24 : 12:29:38
|
| Sam, if dropping and recreating the stored procedure fixes your problem, then alter your stored proc so that it does WITH RECOMPILE.Tara |
 |
|
|
SamC
White Water Yakist
3467 Posts |
Posted - 2004-05-24 : 13:10:22
|
| Thanks everyone...This is a production database. This problem seems to hop from one stored procedure to another. This is the third stored procedure in 3 weeks.Execution plans look fine. The procs seem to execute properly in Query Analyzer, but timeout from the ASP/ADO web calls.Because the problem seems to disappear after recompilation, I don't believe it's an ASP/WEB/Network problem. It suggests something is wrong with the DB.Sam |
 |
|
|
X002548
Not Just a Number
15586 Posts |
Posted - 2004-05-24 : 13:22:28
|
| Sam,Run profile and save to a file...and let it run until the problem shows up again...I don't buy that it's the DB...No miracles...I'm better there's no garbage collection on the web side and it's not cleaning up...whatever...Let us know...Brett8-) |
 |
|
|
SamC
White Water Yakist
3467 Posts |
Posted - 2004-05-24 : 13:28:38
|
| What kind of profiler trace would you run? |
 |
|
|
X002548
Not Just a Number
15586 Posts |
Posted - 2004-05-25 : 16:15:15
|
| Sam,SQL Profiler...no?Graz had made some teplates out there for PASS last year...But you can make up your own...Have you tried that yet?I just saw someone else with the exact same problem..Yet in his case the opposite happend, they'd recompile and notheing..FREEPROCACHE and DROPCLEANBUFFERS fixed his problem...did you CHECKDB?Brett8-) |
 |
|
|
X002548
Not Just a Number
15586 Posts |
Posted - 2004-05-25 : 16:31:28
|
| Anyone got a template set up for profiler specifically to monitor sprocs?Brett8-) |
 |
|
|
tkizer
Almighty SQL Goddess
38200 Posts |
Posted - 2004-05-25 : 16:56:52
|
| I almost always use the default events. They usually provide what you need. Start there and then see if it gives you what you need to see.Tara |
 |
|
|
SamC
White Water Yakist
3467 Posts |
Posted - 2004-05-25 : 17:11:43
|
| Thanks. I've got to wait for the problem to raise it's ugly head again...Sam |
 |
|
|
derrickleggett
Pointy Haired Yak DBA
4184 Posts |
Posted - 2004-05-25 : 18:09:37
|
| Sam, in my nightly maintenance script I wrote a process to recompile all the stored procs after the reindex is done each night. I haven't had this problem since implementing this. You might want to consider this as part of your nightly process.MeanOldDBAderrickleggett@hotmail.comWhen life gives you a lemon, fire the DBA. |
 |
|
|
SamC
White Water Yakist
3467 Posts |
Posted - 2004-05-25 : 18:13:18
|
| What's the least amount of script to recompile all procs? Sam |
 |
|
|
derrickleggett
Pointy Haired Yak DBA
4184 Posts |
Posted - 2004-05-25 : 18:40:32
|
| Put this script into the master database and just run it for each database. I have a job that just runs this in each db. I suppose you could also use sp_MSforeachdb to do it somehow. SET QUOTED_IDENTIFIER ON GOSET ANSI_NULLS ON GOALTER PROCEDURE sp_system_admin_maintenance--Name: sp_system_admin_maintenance--Purpose: This stored Procedure(SP) will be used for running nightly maintenance on -- all databases. It resides in the master database of each database server.-- 1) DBCC DBREINDEX on all tables.-- 2) UPDATE STATISTICS on all tables.-- 3) Recompile all procedures.-- 4) UPDATE USAGE on the database.-- 5) DBCC CHECKDB on the database.-- --Format: EXEC sp_system_admin_maintenance----Example: EXEC sp_system_admin_maintenance----Action: Author: Date: Comments:--------- ------------- --/--/---- ------------------------------------------Created Derrick Leggett 11/11/2003 Initial Development --Modified Derrick Leggett 02/17/2004 Added shrinkdatabase logic into maintenance.--ASSET ARITHABORT ON--Record start timePRINT 'START TIME: ' + CAST(GETDATE() AS VARCHAR(255))--Declare needed variables.DECLARE @int_error_counter INT, @int_max INT, @int_counter INT, @txt_sql NVARCHAR(4000), @txt_name NVARCHAR(4000), @txt_owner NVARCHAR(255), @txt_db NVARCHAR(255)--Declare table variable to hold table or procedure names.DECLARE @tbl_names TABLE ( int_id INT IDENTITY(1,1) PRIMARY KEY, txt_name VARCHAR(255), txt_owner VARCHAR(255))--Insert into table all user tables.INSERT @tbl_names( txt_name, txt_owner) SELECT so.name, su.name FROM sysobjects so INNER JOIN sysusers su ON so.uid = su.uid WHERE so.xtype = 'U' AND so.name NOT LIKE 'dt%'--Set up loop to run DBCC commands against all user tables.SELECT @int_max = (SELECT MAX(int_id) FROM @tbl_names), @int_counter = (SELECT MIN(int_id) FROM @tbl_names)WHILE @int_counter <= @int_maxBEGIN SELECT @txt_name = ( SELECT '[' + txt_owner + '].[' + txt_name + ']' FROM @tbl_names WHERE int_id = @int_counter) --Reindex all user tables. SELECT @txt_sql = 'DBCC DBREINDEX(''' + @txt_name + ''')' PRINT @txt_sql EXEC ( @txt_sql )SELECT @int_counter = @int_counter + 1END--Insert into table all procedures.DELETE @tbl_namesINSERT @tbl_names( txt_name, txt_owner) SELECT so.name, su.name FROM sysobjects so INNER JOIN sysusers su ON so.uid = su.uid WHERE so.xtype = 'P'--Set up loop to force a recompile of all stored procedures.SELECT @int_max = (SELECT MAX(int_id) FROM @tbl_names), @int_counter = (SELECT MIN(int_id) FROM @tbl_names)WHILE @int_counter <= @int_maxBEGIN SELECT @txt_name = ( SELECT '[' + txt_owner + '].[' + txt_name + ']' FROM @tbl_names WHERE int_id = @int_counter) --Recompile the procedures. SELECT @txt_sql = 'EXEC sp_recompile ''' + @txt_name + '''' PRINT @txt_sql EXEC ( @txt_sql )SELECT @int_counter = @int_counter + 1ENDSELECT @txt_db = DB_NAME()--Update the usage on the database.PRINT 'DBCC UPDATEUSAGE (' + @txt_db + ') WITH NO_INFOMSGS'DBCC UPDATEUSAGE (@txt_db) WITH NO_INFOMSGS--Update the usage on the database.PRINT 'DBCC CHECKDB (' + @txt_db + ') WITH NO_INFOMSGS'DBCC CHECKDB (@txt_db) WITH NO_INFOMSGS--Record start time of checkpoint..PRINT 'CHECKPOINT START TIME: ' + CAST(GETDATE() AS VARCHAR(255))PRINT 'CHECKPOINT'CHECKPOINT--Record end time of checkpoint..PRINT 'CHECKPOINT END TIME: ' + CAST(GETDATE() AS VARCHAR(255))--Record end time.PRINT 'END TIME: ' + CAST(GETDATE() AS VARCHAR(255))GOSET QUOTED_IDENTIFIER OFF GOSET ANSI_NULLS ON GOMeanOldDBAderrickleggett@hotmail.comWhen life gives you a lemon, fire the DBA. |
 |
|
|
SamC
White Water Yakist
3467 Posts |
Posted - 2004-05-26 : 08:32:08
|
Thanks for the post. I revised it just a bit to print out milliseconds on each REINDEX.After reading about CHECKPOINT in BOL, I'm still not clear on what it's doing. It ensures all outstanding buffers are written to disk ?It looks like the procedure does a REINDEX on all tables and RECOMPILES all procedures, but I don't see where UPDATESTATISTICS is performed as mentioned in the procedure comments?SamSET QUOTED_IDENTIFIER ONGOSET ANSI_NULLS ONGODROP PROCEDURE dbo.NISA_MaintenanceGOCREATE PROCEDURE dbo.NISA_Maintenance--Name: sp_system_admin_maintenance--Purpose: This stored Procedure(SP) will be used for running nightly maintenance on-- all databases. It resides in the master database of each database server.-- 1) DBCC DBREINDEX on all tables.-- 2) UPDATE STATISTICS on all tables.-- 3) Recompile all procedures.-- 4) UPDATE USAGE on the database.-- 5) DBCC CHECKDB on the database.-- --Format: EXEC sp_system_admin_maintenance----Example: EXEC sp_system_admin_maintenance----Action: Author: Date: Comments:--------- ------------- --/--/---- ------------------------------------------Created Derrick Leggett 11/11/2003 Initial Development--Modified Derrick Leggett 02/17/2004 Added shrinkdatabase logic into maintenance.---- EXEC dbo.NISA_MaintenanceASSET ARITHABORT ON--Record start timePRINT 'START TIME: ' + CAST(GETDATE() AS VARCHAR(255))--Declare needed variables.DECLARE @int_error_counter INT, @int_max INT, @int_counter INT, @txt_sql NVARCHAR(4000), @txt_name NVARCHAR(4000), @txt_owner NVARCHAR(255), @txt_db NVARCHAR(255), @t1 DATETIME--Declare table variable to hold table or procedure names.DECLARE @tbl_names TABLE ( int_id INT IDENTITY(1,1) PRIMARY KEY, txt_name VARCHAR(255), txt_owner VARCHAR(255))--Insert into table all user tables.INSERT @tbl_names (txt_name,txt_owner) SELECT so.name, su.name FROM sysobjects so INNER JOIN sysusers su ON so.uid = su.uid WHERE so.xtype = 'U' AND so.name NOT LIKE 'dt%'--Set up loop to run DBCC commands against all user tables.SELECT @int_max = (SELECT MAX(int_id) FROM @tbl_names), @int_counter = (SELECT MIN(int_id) FROM @tbl_names)WHILE @int_counter <= @int_max BEGIN SELECT @txt_name = (SELECT '[' + txt_owner + '].[' + txt_name + ']' FROM @tbl_names WHERE int_id = @int_counter) --Reindex all user tables. SELECT @txt_sql = 'DBCC DBREINDEX(''' + @txt_name + ''')' PRINT @txt_sql SET @T1 = GETDATE() EXEC ( @txt_sql ) PRINT CAST(DATEDIFF(ms, @T1, GETDATE()) AS VARCHAR) SELECT @int_counter = @int_counter + 1END--Insert into table all procedures.DELETE @tbl_namesINSERT @tbl_names(txt_name, txt_owner) SELECT so.name, su.name FROM sysobjects so INNER JOIN sysusers su ON so.uid = su.uid WHERE so.xtype = 'P'--Set up loop to force a recompile of all stored procedures.SELECT @int_max = (SELECT MAX(int_id) FROM @tbl_names), @int_counter = (SELECT MIN(int_id) FROM @tbl_names)WHILE @int_counter <= @int_max BEGIN SELECT @txt_name = (SELECT '[' + txt_owner + '].[' + txt_name + ']' FROM @tbl_names WHERE int_id = @int_counter) --Recompile the procedures. SELECT @txt_sql = 'EXEC sp_recompile ''' + @txt_name + '''' PRINT @txt_sql EXEC ( @txt_sql ) SELECT @int_counter = @int_counter + 1ENDSELECT @txt_db = DB_NAME()--Update the usage on the database.PRINT 'DBCC UPDATEUSAGE (' + @txt_db + ') WITH NO_INFOMSGS'DBCC UPDATEUSAGE (@txt_db) WITH NO_INFOMSGS--Update the usage on the database.PRINT 'DBCC CHECKDB (' + @txt_db + ') WITH NO_INFOMSGS'DBCC CHECKDB (@txt_db) WITH NO_INFOMSGS--Record start time of checkpoint..PRINT 'CHECKPOINT START TIME: ' + CAST(GETDATE() AS VARCHAR(255))PRINT 'CHECKPOINT'CHECKPOINT--Record end time of checkpoint..PRINT 'CHECKPOINT END TIME: ' + CAST(GETDATE() AS VARCHAR(255))--Record end time.PRINT 'END TIME: ' + CAST(GETDATE() AS VARCHAR(255))GOSET QUOTED_IDENTIFIER OFFGOSET ANSI_NULLS ONGO |
 |
|
|
derrickleggett
Pointy Haired Yak DBA
4184 Posts |
Posted - 2004-05-26 : 09:04:39
|
| This things been through several revisions. Theoretically, there's no reason to do an UPDATE STATISTICS after doing a REINDEX. Also, the checkpoint isn't really needed. It just insures the buffers are written to disk like you said. It saves me a little bit of space and insures the process happens before moving on to the next db basically.MeanOldDBAderrickleggett@hotmail.comWhen life gives you a lemon, fire the DBA. |
 |
|
|
SamC
White Water Yakist
3467 Posts |
Posted - 2004-05-26 : 09:12:27
|
| Derrick,I'm optimistic that forcing the recompilation after reindex will push this problem into remission.Thanks everyone for your support.Sam |
 |
|
|
derrickleggett
Pointy Haired Yak DBA
4184 Posts |
Posted - 2004-05-26 : 09:13:33
|
| :) Well, It worked in our case. We had a rapidly growing system also though.MeanOldDBAderrickleggett@hotmail.comWhen life gives you a lemon, fire the DBA. |
 |
|
|
SamC
White Water Yakist
3467 Posts |
Posted - 2004-06-23 : 12:53:18
|
| Same problem reared it's head today. A report wouldn't render until I dropped and recreated the stored procedure.Really strange since the "recompile" attribute was set on all stored procedures last night at 1AM, right after reindexing all tables.The problem behaves as if the stored proc exec plan believes there are no indexes. The proc will complete, if I give it 5 minutes to run. Seems to me that Rob V had a problem like this some time in the past (maybe it just sounded like this) but I can't put my finger on that thread.Sam |
 |
|
|
MuadDBA
628 Posts |
Posted - 2004-06-23 : 14:31:20
|
| Did you profile it? I am with others who have said they don't beleive it's a DB issue so much as a possible client issue. |
 |
|
|
SamC
White Water Yakist
3467 Posts |
Posted - 2004-06-23 : 14:33:32
|
| Happens on all clients in a diverse geography until the SP is dropped and recreated. |
 |
|
|
eyechart
Master Smack Fu Yak Hacker
3575 Posts |
Posted - 2004-06-23 : 14:58:35
|
| Sam you may want to open a call up with Microsoft on this. They will most likely have you run a tool called PSSDiag that captures perfmon, profiler and blocking data (in parallel) which should allow them to determine exactly what is going on. Too bad they don't release this for the general masses to use.Also, they may determine that you need to run a newer build of SQL Server. The last place I worked we werer given build 919 from Microsoft to get around a problem we were having.If you don't have a support contract, it will cost you a couple of bucks to make the call.-ec |
 |
|
|
Next Page
|