Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 SQL Server Administration (2000)
 sp_updatestats causes timeouts

Author  Topic 

sureshot
Yak Posting Veteran

72 Posts

Posted - 2006-08-14 : 18:15:18

I'm running it daily at 3:30AM when traffic is light, but apparently it's still causing timeouts from using running queries. I'm guessing it's holding locks or flooding I/O?

This is a 230GB DB with SAN drives for data files and logs running SQL 2005. I'm wary about switching to auto_stats async and not doing a daily (or at least weekly) stats update.

Any way to make this stats less resource intensive or other ideas?

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2006-08-14 : 18:21:00
I prefer to use UPDATE STATISTICS command as I can drive the sampling rate for each table. I typically sample at 25%.

Here's what I use:


CREATE PROC isp_UPDATE_STATISTICS
(@dbName sysname, @sample int)
AS

SET NOCOUNT ON

DECLARE @SQL nvarchar(4000)
DECLARE @ID int
DECLARE @TableName sysname
DECLARE @RowCnt int

CREATE TABLE ##Tables
(
TableID INT IDENTITY(1, 1) NOT NULL,
TableName SYSNAME NOT NULL
)

SET @SQL = ''
SET @SQL = @SQL + 'INSERT INTO ##Tables (TableName) '
SET @SQL = @SQL + 'SELECT [name] '
SET @SQL = @SQL + 'FROM ' + @dbName + '.dbo.sysobjects '
SET @SQL = @SQL + 'WHERE xtype = ''U'' AND [name] <> ''dtproperties'''

EXEC sp_executesql @statement = @SQL

SELECT TOP 1 @ID = TableID, @TableName = TableName
FROM ##Tables
ORDER BY TableID

SET @RowCnt = @@ROWCOUNT

WHILE @RowCnt <> 0
BEGIN

SET @SQL = 'UPDATE STATISTICS ' + @dbname + '.dbo.[' + @TableName + '] WITH SAMPLE ' + CONVERT(varchar(3), @sample) + ' PERCENT'

EXEC sp_executesql @statement = @SQL

SELECT TOP 1 @ID = TableID, @TableName = TableName
FROM ##Tables
WHERE TableID > @ID
ORDER BY TableID

SET @RowCnt = @@ROWCOUNT

END

DROP TABLE ##Tables


GO


Tara Kizer
Go to Top of Page

sureshot
Yak Posting Veteran

72 Posts

Posted - 2006-08-14 : 18:30:24
Thanks, that looks good. I may actually set it even lower than 25% for a few special tables given that they have millions of records.

On further inspection though it's looking the timeouts are actually happening right after stats when I run CHECKDB and that is flooding I/O on my system for 40 minutes while it runs (and finds no errors).

It seems like best practices to run CHECKDB every day, but I can't afford these constant timeouts caused by it. I think it would be a valid workaround to restore the backups to a separate box and run CHECKDB there, right?
Go to Top of Page

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2006-08-14 : 18:31:24
quote:
Originally posted by sureshot

It seems like best practices to run CHECKDB every day, but I can't afford these constant timeouts caused by it. I think it would be a valid workaround to restore the backups to a separate box and run CHECKDB there, right?



Yes. In fact, that's the recommendation.

Tara Kizer
Go to Top of Page
   

- Advertisement -