Search This Blog

Friday, March 11, 2011

sql server best practices: tempdb

despite all of my lovely certifications and ten years of experience as the company dba, i am constantly faced with sql server performance issues (deadlocking more than anything else) that challenge or completely go against what i thought i knew about best practices. today, i learned that the default settings for the tembdb system database are far from adequate; the settings need to be changed based on the server environment. this is something that i've known and preached about with user databases (optimal hard disk RAID configurations, separation of physical and log files, etc. - i will cover this in another post), but i only really knew that the tempdb is recreated whenever the server is started and that the default size of the database files should be set large enough such that auto-growth never occurs. the following are some things i didn't know:
  • the number of tempdb physical files should be equal to the number of processors or cores on the server. as the name implies, the tempdb stores temporary information required by sql server to complete some operation such as intermediate result sets and temporary tables created in queries. if there is only one tempdb data file, only one processor will be used to read and write information. to make use of all of the available processors, create one physical file per processor and set them all to be the same size.
  • since the tempdb is recreated every time the server starts, redundancy is pointless. put the tempdb files on the fastest drives available
  • auto-growth of the tempdb is bad for the same reasons that auto-growth is bad for user databases (file fragmentation, processing halts while the file grows, etc.) but, since the tempdb is constantly used for operations, the heinousness of auto-growth of the files grows exponentially with server load. don't be stingy with the default size - allocate enough disk space to ensure that there will always be enough available without depending on growth
    • edit: divide the maximum amount of memory allocated to sql server (server properties -> memory) by the number of logical processors to get the recommended size of each tempdb physical file