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 2005 Forums
 SQL Server Administration (2005)
 Clearing out statistical information?

Author  Topic 

ferrethouse
Constraint Violating Yak Guru

352 Posts

Posted - 2010-01-28 : 19:00:28
I know when you restart SQL Server the statistics are refreshed but what is the command you run to clear them out without a restart? By statistics I mean the type of info these kinds of queries give you...


declare @dbid int
select @dbid = db_id()
Select dbid=database_id, objectname=object_name(s.object_id)
, indexname=i.name, i.index_id --, partition_number
, row_lock_count, row_lock_wait_count
, [block %]=cast (100.0 * row_lock_wait_count / (1 + row_lock_count) as numeric(15,2))
, row_lock_wait_in_ms
, [avg row lock waits in ms]=cast (1.0 * row_lock_wait_in_ms / (1 + row_lock_wait_count) as numeric(15,2))
from sys.dm_db_index_operational_stats (@dbid, NULL, NULL, NULL) s, sys.indexes i
where objectproperty(s.object_id,'IsUserTable') = 1
and i.object_id = s.object_id
and i.index_id = s.index_id
order by row_lock_wait_count desc

GilaMonster
Master Smack Fu Yak Hacker

4507 Posts

Posted - 2010-01-29 : 00:38:39
They're restarted when a database is closed and reopened. If you don't care about availability, you could take the DB offline and then bring it online.

What I used to do rather was to query the DMV at intervals and compare with the previous results to get the changes in that period.

--
Gail Shaw
SQL Server MVP
Go to Top of Page

ferrethouse
Constraint Violating Yak Guru

352 Posts

Posted - 2010-01-29 : 00:47:50
I think there is a DBCC to reset them. Just can't find it...
Go to Top of Page

ferrethouse
Constraint Violating Yak Guru

352 Posts

Posted - 2010-01-29 : 00:52:33
I think I found it...

DBCC DROPCLEANBUFFERS
Go to Top of Page

Kristen
Test

22859 Posts

Posted - 2010-01-29 : 03:56:20
"SQL Server the statistics are refreshed"

Its the Cache, rather than the Statistics, that is cleared isn't it?

Or are there some Statistics that are in-memory only?
Go to Top of Page

GilaMonster
Master Smack Fu Yak Hacker

4507 Posts

Posted - 2010-01-29 : 07:50:03
quote:
Originally posted by ferrethouse

I think I found it...
DBCC DROPCLEANBUFFERS


Nope. That drops ever single page in the buffer pool. It does no reset the index-related DMVs, and it's not a healthy thing to do to a busy production server.

--
Gail Shaw
SQL Server MVP
Go to Top of Page

GilaMonster
Master Smack Fu Yak Hacker

4507 Posts

Posted - 2010-01-29 : 07:53:21
quote:
Originally posted by Kristen

Or are there some Statistics that are in-memory only?


Most DMVs are memory-only. Main exception is sys.dm_db_index_physical_stats (fairly obvious when you think about it)

--
Gail Shaw
SQL Server MVP
Go to Top of Page
   

- Advertisement -