SlideShare a Scribd company logo
1 of 11
It   is more than just a little system database.
  •Joe Hellsten
  •Senior DBA @ rackspace
It is installed by default but what is it?
   TEMPDB is the Junk Drawer of SQL Server “quoted by many”

      •   Temporary Objects
      •   User Objects – triggers, queries, temporary tables, variables, etc
      •   Internal Objects – sorts, triggers, work tables, XML variables or other LOB data type variables
      •   Version stores – Snapshot Isolation (SI), Read Committed Snapshot Isolation (RCSI), After
          triggers, Online index rebuilds
          •   RCSI is cheaper than SI why?
      •   SQL 2012 AlwaysOn Readable Secondary makes use of tempdb for statistics and enables SI,
          which leverages tempdb for row versioning.

      •   Other objects that use TEMPDB
           Service Broker, event notification, database mail, index creations, user-
            defined functions
   SELECT
   UserObjectPages =SUM(user_object_reserved_page_count),
   UserObjectsMB =SUM(user_object_reserved_page_count)/128.0,
   InternalObjectPages =SUM(internal_object_reserved_page_count),
   InternalObjectsMB =SUM(internal_object_reserved_page_count)/128.0,
   VersionStorePages =SUM(version_store_reserved_page_count),
   VersionStoreMB =SUM(version_store_reserved_page_count)/128.0,
   FreePages =SUM(unallocated_extent_page_count),
   FreeSpaceMB =SUM(unallocated_extent_page_count)/128.0
   FROM sys.dm_db_file_space_usage;
What makes this guy unique?
   It is recreated each time SQL Server is started
   It is modeled after the Model database
   If it has grown, it is reset to its default when recreated
   Can not have user defined file groups created
   Auto Shrink can not be used on TEMPDB (even though it is an option)
   A database snapshot can not be created on TEMPDB
   SQL 2012 can be on local disk for clusters

   THERE IS ONLY ONE TEMPDB FOR THE ENTIRE INSTANCE!
A good starting point for configuring TEMPDB

TEMPDB should reside on a different disk than system
and user dbs
Depending on disk IO you might need to split the data
and log file onto different disks as well
Size TEMPDB accordingly
Make sure instant file initialization is enabled (OS
Security Policy- enable volume maintenance)
Set auto grow to a fixed value, don’t use percentage
TEMPDB should be on a fast I/O subsystem
Multiple equal size data files depending on contention
Did I say CONTENTION?

What is contention?
    Wikipedia = “competition by users of a system for the facility at the same time”

•Latch contention on allocation pages
    • Extent allocations are tracked and managed in the data files by allocation pages.
        • PFS – Page Free Space. One PFS page per .5 GB of data file. Tracks how
           much free space each page has. Page 1 in the data file. Repeats every 8088
           pages.
        • GAM – Global Allocation Map. One GAM page per 4 GB of data file.
           Tracks extents. Page 2 in the data file. Repeats every 511,232 pages.
        • SGAM – Shared Global Allocation Map. One SGAM page per 4 GB of data
           file. Tracks extents being used as shared extents. Page 3 in the data file.
           Repeats every 511,232 pages
How to find contention in TEMPDB
•sys.dm_os_waiting_tasks
     •Any tasks waiting on PageLatch or PageIOLatch
          SELECT session_id AS sessionid,
                   wait_duration_ms AS wait_time_in_milliseconds,
                   resource_description AS type_of_allocation_contention
          FROM sys.dm_os_waiting_tasks
          WHERE wait_type LIKE ‘Page%latch_%’
                   AND (resource_description LIKE ‘2:%’)

  This query will give you the session, wait duration and resource
  description. Resource Description is <database ID>:<file ID>:<page
  number>.

  Formula for page type is
       GAM: Page ID = 2 or Page ID % 511232
        SGAM: Page ID = 3 or (Page ID – 1) % 511232
        PFS: Page ID = 1 or Page ID % 8088
Raise Error
If exists (SELECT session_id, wait_type, wait_duration_ms, blocking_session_id,
 resource_description,
 ResourceType = Case
  WHEN PageID = 1 OR PageID %8088 = 0 THEN 'Is PFS Page'
  WHEN PageID = 2 OR PageID % 511232 = 0 THEN 'Is GAM Page'
  WHEN PageID = 3 OR (PageID - 1) % 511232 = 0 THEN 'Is SGAM Page'
     END
FROM
(SELECT session_id, wait_type, wait_duration_ms, blocking_session_id, resource_description,
 CAST(RIGHT(resource_description, LEN(resource_description)
         - CHARINDEX(':', resource_description, 3)) AS INT) AS PageID
FROM sys.dm_os_waiting_tasks
WHERE wait_type LIKE 'PAGE%LATCH_%'
AND resource_description LIKE '2:%'
) AS tab)
DECLARE @StringVariable NVARCHAR(50)
Set @StringVariable = (Select
 ResourceType = Case
  WHEN PageID = 1 OR PageID %8088 = 0 THEN 'Contention On PFS Page'
  WHEN PageID = 2 OR PageID % 511232 = 0 THEN 'Contention On GAM Page'
  WHEN PageID = 3 OR (PageID - 1) % 511232 = 0 THEN 'Contention On SGAM Page'
    -- ELSE 'Is Not PFS, GAM, or SGAM page'
   END
FROM
(SELECT top 1
  CAST(RIGHT(resource_description, LEN(resource_description)
         - CHARINDEX(':', resource_description, 3)) AS INT) AS PageID
FROM sys.dm_os_waiting_tasks
WHERE wait_type LIKE 'PAGE%LATCH_%'
AND resource_description LIKE '2:%'
) as tab)
RAISERROR (@StringVariable, -- Message text.
        10, -- Severity,
        1 -- State
        ) with log
go 100
You have contention, now what?
Contention causes transactions to queue causing extended wait times.

•Add more data files
    • How many? 1 per core, 1 per 2 cores, 1 per 4 cores
    • Microsoft still states 1 data file per core
    • In real life it depends on concurrent processes On an 8 core system
      how many concurrent processes can there be?

•Don’t over do it - to many files can have negative impact

•Create equal size files. MSSQL uses proportional fill model meaning a
larger file will be used more than the others.

•Multiple data files help reduce contention since each file has its own GAM,
SGAM and PFS information.
• Troubleshoot TEMPDB I/O like you would any other database
• Put TEMPDB on your fastest possible drives
• Put TEMPDB on the fastest RAID you can support
• Avoid memory overflows that spill to tempdb.
• Avoid long running queries in the version store
• Pre-size Files to Avoid Auto-growth


Options for more IOPs
• Put data files and log file on different sets of disks
• Split the individual data files to different sets of disks


Need more IOPs
    Visit FUSIONIO.COM. GO with SSD’s, with over 100,000 IOPs
Were you paying attention?
How often should you back up TEMPDB?
How many data files per core?
How often should you shrink TEMPDB?
Where should you place your TEMPDB data and log files?
What does PFS, GAM and SGAM mean?
Tim Radney, Senior DBA for a top 40
  US Bank
President of “Columbus GA SQL Users
  Group”

Robert Davis, Idera ACE, MCM, MVP

More Related Content

Similar to Tempdb Not your average Database

Dmv's & Performance Monitor in SQL Server
Dmv's & Performance Monitor in SQL ServerDmv's & Performance Monitor in SQL Server
Dmv's & Performance Monitor in SQL ServerZeba Ansari
 
Investigate SQL Server Memory Like Sherlock Holmes
Investigate SQL Server Memory Like Sherlock HolmesInvestigate SQL Server Memory Like Sherlock Holmes
Investigate SQL Server Memory Like Sherlock HolmesRichard Douglas
 
High Performance Mysql
High Performance MysqlHigh Performance Mysql
High Performance Mysqlliufabin 66688
 
Sql server performance tuning and optimization
Sql server performance tuning and optimizationSql server performance tuning and optimization
Sql server performance tuning and optimizationManish Rawat
 
Maximizing performance via tuning and optimization
Maximizing performance via tuning and optimizationMaximizing performance via tuning and optimization
Maximizing performance via tuning and optimizationMariaDB plc
 
Maximizing performance via tuning and optimization
Maximizing performance via tuning and optimizationMaximizing performance via tuning and optimization
Maximizing performance via tuning and optimizationMariaDB plc
 
The MySQL Performance Schema & New SYS Schema
The MySQL Performance Schema & New SYS SchemaThe MySQL Performance Schema & New SYS Schema
The MySQL Performance Schema & New SYS SchemaTed Wennmark
 
My Database Skills Killed the Server
My Database Skills Killed the ServerMy Database Skills Killed the Server
My Database Skills Killed the ServerColdFusionConference
 
Managing Memory & Locks - Series 1 Memory Management
Managing  Memory & Locks - Series 1 Memory ManagementManaging  Memory & Locks - Series 1 Memory Management
Managing Memory & Locks - Series 1 Memory ManagementDAGEOP LTD
 
Storage talk
Storage talkStorage talk
Storage talkchristkv
 
How to Analyze and Tune MySQL Queries for Better Performance
How to Analyze and Tune MySQL Queries for Better PerformanceHow to Analyze and Tune MySQL Queries for Better Performance
How to Analyze and Tune MySQL Queries for Better Performanceoysteing
 
MySQL Oslayer performace optimization
MySQL  Oslayer performace optimizationMySQL  Oslayer performace optimization
MySQL Oslayer performace optimizationLouis liu
 
AWS re:Invent 2016: ElastiCache Deep Dive: Best Practices and Usage Patterns ...
AWS re:Invent 2016: ElastiCache Deep Dive: Best Practices and Usage Patterns ...AWS re:Invent 2016: ElastiCache Deep Dive: Best Practices and Usage Patterns ...
AWS re:Invent 2016: ElastiCache Deep Dive: Best Practices and Usage Patterns ...Amazon Web Services
 
It Depends - Database admin for developers - Rev 20151205
It Depends - Database admin for developers - Rev 20151205It Depends - Database admin for developers - Rev 20151205
It Depends - Database admin for developers - Rev 20151205Maggie Pint
 
IMC Summit 2016 Breakout - Per Minoborg - Work with Multiple Hot Terabytes in...
IMC Summit 2016 Breakout - Per Minoborg - Work with Multiple Hot Terabytes in...IMC Summit 2016 Breakout - Per Minoborg - Work with Multiple Hot Terabytes in...
IMC Summit 2016 Breakout - Per Minoborg - Work with Multiple Hot Terabytes in...In-Memory Computing Summit
 

Similar to Tempdb Not your average Database (20)

Dmv's & Performance Monitor in SQL Server
Dmv's & Performance Monitor in SQL ServerDmv's & Performance Monitor in SQL Server
Dmv's & Performance Monitor in SQL Server
 
Investigate SQL Server Memory Like Sherlock Holmes
Investigate SQL Server Memory Like Sherlock HolmesInvestigate SQL Server Memory Like Sherlock Holmes
Investigate SQL Server Memory Like Sherlock Holmes
 
High Performance Mysql
High Performance MysqlHigh Performance Mysql
High Performance Mysql
 
Sql server performance tuning and optimization
Sql server performance tuning and optimizationSql server performance tuning and optimization
Sql server performance tuning and optimization
 
Maximizing performance via tuning and optimization
Maximizing performance via tuning and optimizationMaximizing performance via tuning and optimization
Maximizing performance via tuning and optimization
 
Maximizing performance via tuning and optimization
Maximizing performance via tuning and optimizationMaximizing performance via tuning and optimization
Maximizing performance via tuning and optimization
 
SQLServer Database Structures
SQLServer Database Structures SQLServer Database Structures
SQLServer Database Structures
 
The MySQL Performance Schema & New SYS Schema
The MySQL Performance Schema & New SYS SchemaThe MySQL Performance Schema & New SYS Schema
The MySQL Performance Schema & New SYS Schema
 
My Database Skills Killed the Server
My Database Skills Killed the ServerMy Database Skills Killed the Server
My Database Skills Killed the Server
 
Dba tuning
Dba tuningDba tuning
Dba tuning
 
Cassandra as Memcache
Cassandra as MemcacheCassandra as Memcache
Cassandra as Memcache
 
Managing Memory & Locks - Series 1 Memory Management
Managing  Memory & Locks - Series 1 Memory ManagementManaging  Memory & Locks - Series 1 Memory Management
Managing Memory & Locks - Series 1 Memory Management
 
Storage talk
Storage talkStorage talk
Storage talk
 
How to Analyze and Tune MySQL Queries for Better Performance
How to Analyze and Tune MySQL Queries for Better PerformanceHow to Analyze and Tune MySQL Queries for Better Performance
How to Analyze and Tune MySQL Queries for Better Performance
 
MySQL Oslayer performace optimization
MySQL  Oslayer performace optimizationMySQL  Oslayer performace optimization
MySQL Oslayer performace optimization
 
AWS re:Invent 2016: ElastiCache Deep Dive: Best Practices and Usage Patterns ...
AWS re:Invent 2016: ElastiCache Deep Dive: Best Practices and Usage Patterns ...AWS re:Invent 2016: ElastiCache Deep Dive: Best Practices and Usage Patterns ...
AWS re:Invent 2016: ElastiCache Deep Dive: Best Practices and Usage Patterns ...
 
Mysql For Developers
Mysql For DevelopersMysql For Developers
Mysql For Developers
 
It Depends - Database admin for developers - Rev 20151205
It Depends - Database admin for developers - Rev 20151205It Depends - Database admin for developers - Rev 20151205
It Depends - Database admin for developers - Rev 20151205
 
It Depends
It DependsIt Depends
It Depends
 
IMC Summit 2016 Breakout - Per Minoborg - Work with Multiple Hot Terabytes in...
IMC Summit 2016 Breakout - Per Minoborg - Work with Multiple Hot Terabytes in...IMC Summit 2016 Breakout - Per Minoborg - Work with Multiple Hot Terabytes in...
IMC Summit 2016 Breakout - Per Minoborg - Work with Multiple Hot Terabytes in...
 

Recently uploaded

EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEarley Information Science
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CVKhem
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountPuma Security, LLC
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slidespraypatel2
 
What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?Antenna Manufacturer Coco
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking MenDelhi Call girls
 
A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024Results
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processorsdebabhi2
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)wesley chun
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...apidays
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationRadu Cotescu
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationMichael W. Hawkins
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfEnterprise Knowledge
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Scriptwesley chun
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationSafe Software
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘RTylerCroy
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsJoaquim Jorge
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024The Digital Insurer
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024The Digital Insurer
 
Advantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your BusinessAdvantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your BusinessPixlogix Infotech
 

Recently uploaded (20)

EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CV
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path Mount
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slides
 
What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
 
A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
Advantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your BusinessAdvantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your Business
 

Tempdb Not your average Database

  • 1. It is more than just a little system database. •Joe Hellsten •Senior DBA @ rackspace
  • 2. It is installed by default but what is it?  TEMPDB is the Junk Drawer of SQL Server “quoted by many” • Temporary Objects • User Objects – triggers, queries, temporary tables, variables, etc • Internal Objects – sorts, triggers, work tables, XML variables or other LOB data type variables • Version stores – Snapshot Isolation (SI), Read Committed Snapshot Isolation (RCSI), After triggers, Online index rebuilds • RCSI is cheaper than SI why? • SQL 2012 AlwaysOn Readable Secondary makes use of tempdb for statistics and enables SI, which leverages tempdb for row versioning. • Other objects that use TEMPDB  Service Broker, event notification, database mail, index creations, user- defined functions  SELECT  UserObjectPages =SUM(user_object_reserved_page_count),  UserObjectsMB =SUM(user_object_reserved_page_count)/128.0,  InternalObjectPages =SUM(internal_object_reserved_page_count),  InternalObjectsMB =SUM(internal_object_reserved_page_count)/128.0,  VersionStorePages =SUM(version_store_reserved_page_count),  VersionStoreMB =SUM(version_store_reserved_page_count)/128.0,  FreePages =SUM(unallocated_extent_page_count),  FreeSpaceMB =SUM(unallocated_extent_page_count)/128.0  FROM sys.dm_db_file_space_usage;
  • 3. What makes this guy unique?  It is recreated each time SQL Server is started  It is modeled after the Model database  If it has grown, it is reset to its default when recreated  Can not have user defined file groups created  Auto Shrink can not be used on TEMPDB (even though it is an option)  A database snapshot can not be created on TEMPDB  SQL 2012 can be on local disk for clusters  THERE IS ONLY ONE TEMPDB FOR THE ENTIRE INSTANCE!
  • 4. A good starting point for configuring TEMPDB TEMPDB should reside on a different disk than system and user dbs Depending on disk IO you might need to split the data and log file onto different disks as well Size TEMPDB accordingly Make sure instant file initialization is enabled (OS Security Policy- enable volume maintenance) Set auto grow to a fixed value, don’t use percentage TEMPDB should be on a fast I/O subsystem Multiple equal size data files depending on contention
  • 5. Did I say CONTENTION? What is contention? Wikipedia = “competition by users of a system for the facility at the same time” •Latch contention on allocation pages • Extent allocations are tracked and managed in the data files by allocation pages. • PFS – Page Free Space. One PFS page per .5 GB of data file. Tracks how much free space each page has. Page 1 in the data file. Repeats every 8088 pages. • GAM – Global Allocation Map. One GAM page per 4 GB of data file. Tracks extents. Page 2 in the data file. Repeats every 511,232 pages. • SGAM – Shared Global Allocation Map. One SGAM page per 4 GB of data file. Tracks extents being used as shared extents. Page 3 in the data file. Repeats every 511,232 pages
  • 6. How to find contention in TEMPDB •sys.dm_os_waiting_tasks •Any tasks waiting on PageLatch or PageIOLatch SELECT session_id AS sessionid, wait_duration_ms AS wait_time_in_milliseconds, resource_description AS type_of_allocation_contention FROM sys.dm_os_waiting_tasks WHERE wait_type LIKE ‘Page%latch_%’ AND (resource_description LIKE ‘2:%’) This query will give you the session, wait duration and resource description. Resource Description is <database ID>:<file ID>:<page number>. Formula for page type is  GAM: Page ID = 2 or Page ID % 511232 SGAM: Page ID = 3 or (Page ID – 1) % 511232 PFS: Page ID = 1 or Page ID % 8088
  • 7. Raise Error If exists (SELECT session_id, wait_type, wait_duration_ms, blocking_session_id, resource_description, ResourceType = Case WHEN PageID = 1 OR PageID %8088 = 0 THEN 'Is PFS Page' WHEN PageID = 2 OR PageID % 511232 = 0 THEN 'Is GAM Page' WHEN PageID = 3 OR (PageID - 1) % 511232 = 0 THEN 'Is SGAM Page' END FROM (SELECT session_id, wait_type, wait_duration_ms, blocking_session_id, resource_description, CAST(RIGHT(resource_description, LEN(resource_description) - CHARINDEX(':', resource_description, 3)) AS INT) AS PageID FROM sys.dm_os_waiting_tasks WHERE wait_type LIKE 'PAGE%LATCH_%' AND resource_description LIKE '2:%' ) AS tab) DECLARE @StringVariable NVARCHAR(50) Set @StringVariable = (Select ResourceType = Case WHEN PageID = 1 OR PageID %8088 = 0 THEN 'Contention On PFS Page' WHEN PageID = 2 OR PageID % 511232 = 0 THEN 'Contention On GAM Page' WHEN PageID = 3 OR (PageID - 1) % 511232 = 0 THEN 'Contention On SGAM Page' -- ELSE 'Is Not PFS, GAM, or SGAM page' END FROM (SELECT top 1 CAST(RIGHT(resource_description, LEN(resource_description) - CHARINDEX(':', resource_description, 3)) AS INT) AS PageID FROM sys.dm_os_waiting_tasks WHERE wait_type LIKE 'PAGE%LATCH_%' AND resource_description LIKE '2:%' ) as tab) RAISERROR (@StringVariable, -- Message text. 10, -- Severity, 1 -- State ) with log go 100
  • 8. You have contention, now what? Contention causes transactions to queue causing extended wait times. •Add more data files • How many? 1 per core, 1 per 2 cores, 1 per 4 cores • Microsoft still states 1 data file per core • In real life it depends on concurrent processes On an 8 core system how many concurrent processes can there be? •Don’t over do it - to many files can have negative impact •Create equal size files. MSSQL uses proportional fill model meaning a larger file will be used more than the others. •Multiple data files help reduce contention since each file has its own GAM, SGAM and PFS information.
  • 9. • Troubleshoot TEMPDB I/O like you would any other database • Put TEMPDB on your fastest possible drives • Put TEMPDB on the fastest RAID you can support • Avoid memory overflows that spill to tempdb. • Avoid long running queries in the version store • Pre-size Files to Avoid Auto-growth Options for more IOPs • Put data files and log file on different sets of disks • Split the individual data files to different sets of disks Need more IOPs Visit FUSIONIO.COM. GO with SSD’s, with over 100,000 IOPs
  • 10. Were you paying attention? How often should you back up TEMPDB? How many data files per core? How often should you shrink TEMPDB? Where should you place your TEMPDB data and log files? What does PFS, GAM and SGAM mean?
  • 11. Tim Radney, Senior DBA for a top 40 US Bank President of “Columbus GA SQL Users Group” Robert Davis, Idera ACE, MCM, MVP

Editor's Notes

  1. Brand Transformation Presentation
  2. Brand Transformation Presentation
  3. Brand Transformation Presentation