"Priming" a whole database in MSSQL for first-hit speed
Posted
by David Spillett
on Stack Overflow
See other posts from Stack Overflow
or by David Spillett
Published on 2010-05-04T19:29:45Z
Indexed on
2010/05/04
19:38 UTC
Read the original article
Hit count: 328
sql-server
|cache
For a particular apps I have a set of queries that I run each time the database has been restarted for any reason (server reboot usually). These "prime" SQL Server's page cache with the common core working set of the data so that the app is not unusually slow the first time a user logs in afterwards.
One instance of the app is running on an over-specced arrangement where the SQL box has more RAM than the size of the database (4Gb in the machine, the DB is under 1.5Gb currently and unlikely to grow too much relative to that in the near future). Is there a neat/easy way of telling SQL Server to go away and load everything into RAM?
It could be done the hard way by having a script scan sysobjects
& sysindexes
and running SELECT * FROM <table> WITH(INDEX(<index_name>)) ORDER BY <index_fields>
for every key and index found, which should cause every used page to be read at least once and so be in RAM, but is there a cleaner or more efficient way? All planned instances where the database server is stopped are out-of-normal-working-hours (all the users are at most one timezone away and unlike me none of them work at silly hours) so such a process (until complete) slowing down users more than the working set not being primed at all would is not an issue.
© Stack Overflow or respective owner