Home > SQL Server Tips > Database Management and Administration > Optimize tempdb in SQL Server by striping and splitting to multiple files
SQL Server Tips:
EMAIL THIS
 TIPS & NEWSLETTERS TOPICS 

DATABASE MANAGEMENT AND ADMINISTRATION

Optimize tempdb in SQL Server by striping and splitting to multiple files


Serdar Yegulalp, Contributor
10.15.2007
Rating: -4.09- (out of 5)


Expert advice on database administration
Digg This!    StumbleUpon Toolbar StumbleUpon    Bookmark with Delicious Del.icio.us    Add to Google


The practice of storing a database across multiple files in a filegroup (or across multiple filegroups) is done all the time to enhance the performance of user-created databases. What, then, about doing the same thing to increase the performance of the temporary database, tempdb?

On SQL Server systems with a single logical processor or relatively small load, a single file may really be all you need to handle tempdb. But on larger, more heavily-trafficked systems, tempdb performance can benefit from having multiple physical files allocated to it. Here are some pointers on how to go about doing this most effectively.

  1. Create one physical file per processor. The processors in question can be either physical or virtual, but the point is to provide one separate physical file per worker whenever possible. This way, in round-robin fashion, each worker has a separate physical file, which reduces contention of resource allocation. See blog on article on tempdb by the PSS SQL Server Engineers at Microsoft for some information about this behavior in context.
  2. Pre-allocate a decent amount of space per file. This is done so there will always be a decent amount of space already allocated for the tempdb files. You should have auto-grow turned on for tempdb's files, but there's a balancing acting between how much to allow the tempdb files to grow and how much time the system should spend allocating for growth.
  3. Microsoft's own documentation about optimizing tempdb performance talks about this and indicates that the pre-allocated size you choose for tempdb should cover the vast majority of work scenarios and that autogrowth should only kick in under the most extreme circumstances. The SQL Server Scalability FAQ suggests that if you're dealing with terabyte-size databases, expect to allocate more than 100 GB for each tempdb file. So, the exact size of the files is going to vary enormously depending on what grade of work you're doing.

    The single best way to figure out how much space to set aside is to use statistics harvested from a live workload to gauge tempdb usage. You can pre-allocate a great deal at first, then monitor tempdb usage to get an idea of exactly how much of the space is being used.

  4. Make sure the tempdb files are contiguous. This improves linear read performance, of course, but it is generally not something to obsess about. The best way to insure that the files are contiguous is to create them, then
    Digg This!    StumbleUpon Toolbar StumbleUpon    Bookmark with Delicious Del.icio.us    Add to Google



    RELATED CONTENT
    Microsoft SQL Server Performance Monitoring and Tuning
    SQL Server Mailbag: CALs, witnesses and unwanted changes
    SQL Server Mailbag: Data restoration and DB property management
    Working with IntelliSense in SQL Server 2008 Management Studio
    SQL Server Mailbag: Stored procedures, triggers and SSRS reports
    Troubleshooting Distributed Transaction Coordinator errors in SQL Server
    Clearing the Windows page file and its effect on server performance
    Optimizing SQL Server indexes –- even when they're not your indexes
    Performance implications of transaction log autogrowth in SQL Server
    The short course on how SQL Server really works
    Determining the source of full transaction logs in SQL Server

    Microsoft SQL Server 2005
    End of life comes for SQL Server 2005 SP2, 2008
    SQL Server Reporting Services Fast Guide
    SQL Server Service Broker Tutorial and Reference Guide
    Tips for tuning SQL Server 2005 to improve reporting performance
    SQL Server consolidation: Why it's an optimization technique
    Parent-child dimensions in SQL Server 2005 with Analysis Services MDX
    Enforcing data integrity in a SQL Server database
    SSIS error message due to installation problem on SQL Server 2005
    Should you upgrade to SQL Server 2005 or SQL Server 2008?
    Basics for working with DATETIME and SMALLDATETIME in SQL Server 2005
    Microsoft SQL Server 2005 Research

    Database Management and Administration
    Hardening the network and OS for SQL Server security
    Securing the server and database in SQL Server
    How SQL Server 2008 components impact SharePoint implementations
    Troubleshooting Distributed Transaction Coordinator errors in SQL Server
    Achieving high availability and disaster recovery with SharePoint databases
    Clearing the Windows page file and its effect on server performance
    Deploying a SQL Server virtual appliance for Microsoft Hyper-V
    How to create SQL Server virtual appliances for Hyper-V
    Push vs. pull: Configuring SQL Server replication
    Protect virtual databases through SQL Server database mirroring

    RELATED GLOSSARY TERMS
    Terms from Whatis.com − the technology online dictionary
    contiguity  (SearchSQLServer.com)
    contiguous  (SearchSQLServer.com)
    drilldown  (SearchSQLServer.com)
    hashing  (SearchSQLServer.com)
    hybrid online analytical processing  (SearchSQLServer.com)

    RELATED RESOURCES
    2020software.com, trial software downloads for accounting software, ERP software, CRM software and business software systems
    Search Bitpipe.com for the latest white papers and business webcasts
    Whatis.com, the online computer dictionary


    href="http://www.microsoft.com/technet/sysinternals/utilities/contig.mspx" target="_blank">use a utility like CONTIG to before putting the system into service. Since tempdb files may take a long time to make contiguous, if CONTIG reports that the file is only in a few fragments (i.e., there are no individual pieces smaller than 64 MG), the performance impact will most likely be minimal. In this case, the file probably isn't worth defragmenting.

  5. Place each tempdb file on a separate logical unit / physical disk spindle whenever possible. The same advice applies to physical files on user databases as well. This parallelizes the way tempdb is accessed, so there's less contention on the hardware level for any particular file.
  6. The tempdb files should not share space with the user databases. Again, this is to reduce contention and enhance parallelism; tempdb's files should always be on their own spindles whenever possible. Even if those multiple files are on the same physical disc (if you have no other choice), they can still increase performance. The more pre-allocated space there is available, the less contention there will be to allocate that space to begin with.
  7. Consider using trace flag 1118 to reduce tempdb contention, but don't expect a magic bullet. Turning on trace flag 1118 in SQL Server 2005 is alleged to improve performance in situations where there are multiple tempdb files. But it is definitely one of those optimizations where the end user's mileage will vary. Linchi Shea of SQLBlog.com discussed the issue and then ran tests with flag 1118 on and off in a variety of scenarios. He concluded that the best approach is to test using your live workload in order to determine whether or not it needs to be enabled. (The differences, to me, don't appear to be terribly dramatic to begin with.)

ABOUT THE AUTHOR:   

Serdar Yegulalp has been writing about Windows and related technologies for more than 10 years and is a frequent contributor to various TechTarget sites as well as other publications. He hosts the Web site Windows Insight, where he posts regularly about Windows and has an ongoing feature guide to Windows Vista for emigrants from Windows XP.
Copyright 2007 TechTarget

Rate this Tip
To rate tips, you must be a member of SearchSQLServer.com.
Register now to start rating these tips. Log in if you are already a member.




DISCLAIMER: Our Tips Exchange is a forum for you to share technical advice and expertise with your peers and to learn from other enterprise IT professionals. TechTarget provides the infrastructure to facilitate this sharing of information. However, we cannot guarantee the accuracy or validity of the material submitted. You agree that your use of the Ask The Expert services and your reliance on any questions, answers, information or other materials received through this Web site is at your own risk.



SQL Server Development - .NET, C#, T-SQL, Visual Basic
HomeNewsTopicsITKnowledge ExchangeTipsAsk the ExpertsMultimediaWhite PapersIT Downloads
About Us  |  Contact Us  |  For Advertisers  |  For Business Partners  |  Site Index  |  RSS
SEARCH 
TechTarget provides technology professionals with the information they need to perform their jobs - from developing strategy, to making cost-effective purchase decisions and managing their organizations' technology projects - with its network of technology-specific websites, events and online magazines.

TechTarget Corporate Web Site  |  Media Kits  |  Site Map




All Rights Reserved, Copyright 2005 - 2009, TechTarget | Read our Privacy Policy
  TechTarget - The IT Media ROI Experts