SlideShare a Scribd company logo
1 of 47
Download to read offline
Wonder TempDB

Dubi Lebel

Dad, chef, gardener and
DBA
Dubi.lebel@gmail.com
Who am I?
 Dubi- Or Not To Be
 To do is to be - Descartes
 To be is to do - Voltaire
 Do be do be do - Frank Sinatra
 Yaba Daba Do - Fred Flintstone




11/2/2009         Dubi Or Not To Be
                                      2
Temporary Agenda
 It all about TemDB
 For what?
 Where?
 How to?
 best practice!




11/2/2009          Dubi Or Not To Be
                                       3
TempDB
 Only one TempDB per instance.
 Operations within TempDB are minimally logged.
 data in TempDB does not persist after SQL Server shuts
  down.
 Only one file group in TempDB is allowed for data and
  one file group for logs.
 By default auto grow is enabled.
 When the server restarts, the TempDB file size is reset
  to the configured value (the default is 8 MB).


11/2/2009       Dubi Or Not To Be
                                                            4
What is TempDB
BOL:
      The TempDB system database is a global resource that is
      available to all users connected to the instance of SQL
      Server and is used to hold the following:




11/2/2009         Dubi Or Not To Be
                                                                5
BOL: TempDB hold the following :
 Temporary user objects that are explicitly
  created, such as: global or local
    temporary tables,
    temporary stored procedures,
    table variables,
    Cursors (Key-set-driven and static cursors ).




11/2/2009         Dubi Or Not To Be
                                                     6
BOL: TempDB hold the following :
 Internal objects that are created by the SQL Server
  Database Engine, for example:
    work tables to store intermediate results for:
           spools
           sorting.
           Hash match.
    Index (create with SORT_IN_TempDB )




11/2/2009             Dubi Or Not To Be
                                                        7
BOL: TempDB hold the following :
 Row versions that are generated by data
  modification transactions in a database that uses read-
  committed
    using row versioning isolation
    snapshot isolation transactions.




11/2/2009        Dubi Or Not To Be
                                                            8
BOL: TempDB hold the following :
 Row versions that are generated by data
  modification transactions for features, such as:
    online index operations,
    Multiple Active Result Sets (MARS),
    AFTER triggers.




11/2/2009        Dubi Or Not To Be
                                                     9
Is that all?




11/2/2009   Dubi Or Not To Be
                                10
TempDB also hold the following:
 DBCC CHECK
 Service Broker
 Database Mail (Service Broker)
 Event notifications (Service Broker)
 Query notifications (Service Broker)
 XML
 Common table expression queries (with cte(col,col) as select..)
 Large object (LOB) data type variables and parameters



11/2/2009          Dubi Or Not To Be
                                                                    11
event log:
Source: MSSQLSERVER
 Event ID: 17052
 Description: The log file for database 'TempDB' is full.
 Back up the transaction log for the database to free up
 some log space




11/2/2009       Dubi Or Not To Be
                                                            12
error message
Server: Msg 8624, Level 16, State 1
 Internal SQL Server error

 or
Server: Msg 1101, Level 17, State 10, Line 1
 Could not allocate new page for database 'TempDB'.
 There are no more pages available in filegroup
 DEFAULT. Space can be created by dropping objects,
 adding additional files, or allowing file growth.



11/2/2009      Dubi Or Not To Be
                                                      13
How to plan TempDB Capacity ?
 Check that auto-grow is on or off for TempDB
 Execute individual queries , workload trace files , index
  maintenance and monitor TempDB space.
 Sum the space-use values from the previous steps to
  predict your total workload usage.
 adjust this value. And adjust again.




11/2/2009        Dubi Or Not To Be
                                                              14
How to Monitor TempDB Use?
 sys.dm_db_file_space_usage - disk space that is used
 sys.dm_db_session_space_usage and
  sys.dm_db_task_space_usage - page allocation or
  deallocation activity




11/2/2009      Dubi Or Not To Be
                                                         15
Monitoring TempDB Disk Space 1
SELECT
 SUM(unallocated_extent_page_count) AS [free pages],
 (SUM(unallocated_extent_page_count)*1.0/128) AS
  [free space in MB]
FROM sys.dm_db_file_space_usage;


  returns the total number of free pages and total free
  space in megabytes (MB) available in all files in
  TempDB


11/2/2009       Dubi Or Not To Be
                                                          16
11/2/2009   Dubi Or Not To Be
                                17
Monitoring TempDB Disk Space 2
SELECT SUM(version_store_reserved_page_count)
     AS [version store pages used],
     (SUM(version_store_reserved_page_count)*1.0/128)
     AS [version store space in MB]
 FROM sys.dm_db_file_space_usage;

   returns the total number of pages used by the version
  store and the total space in MB used by the version store
  in TempDB


11/2/2009       Dubi Or Not To Be
                                                          18
11/2/2009   Dubi Or Not To Be
                                19
Monitoring TempDB Disk Space 3
SELECT transaction_id
FROM
  sys.dm_tran_active_snapshot_database_transactions
ORDER BY elapsed_time_seconds DESC;

  If the version store is using a lot of space in TempDB, you
  must determine what is the longest running transaction.




11/2/2009       Dubi Or Not To Be
                                                            20
11/2/2009   Dubi Or Not To Be
                                21
Monitoring TempDB Disk Space 4
SELECT SUM(internal_object_reserved_page_count)
     AS [internal object pages used],
   (SUM(internal_object_reserved_page_count)*1.0/128)
     AS [internal object space in MB]
FROM sys.dm_db_file_space_usage;

   returns the total number of pages used by internal objects
  and the total space in MB used by internal objects in
  TempDB


11/2/2009       Dubi Or Not To Be
                                                          22
11/2/2009   Dubi Or Not To Be
                                23
Monitoring TempDB Disk Space 5
SELECT SUM(user_object_reserved_page_count)
     AS [user object pages used],
 (SUM(user_object_reserved_page_count)*1.0/128)
     AS [user object space in MB]
 FROM sys.dm_db_file_space_usage;

  returns the total number of pages used by user objects
  and the total space used by user objects in TempDB.




11/2/2009       Dubi Or Not To Be
                                                           24
11/2/2009   Dubi Or Not To Be
                                25
Monitoring TempDB Disk Space 6
SELECT SUM(size)*1.0/128 AS [size in MB]
FROM TempDB.sys.database_files

  returns the total amount of disk space used by all files
  in TempDB.




11/2/2009       Dubi Or Not To Be
                                                             26
11/2/2009   Dubi Or Not To Be
                                27
SELECT
  SUM (user_object_reserved_page_count)*8 as
     usr_obj_kb,
  SUM (internal_object_reserved_page_count)*8 as
     internal_obj_kb,
  SUM (unallocated_extent_page_count)*8 as
     freespace_kb,
  SUM (mixed_extent_page_count)*8 as
     mixedextent_kb
FROM sys.dm_db_file_space_usag



11/2/2009      Dubi Or Not To Be
                                                   28
11/2/2009   Dubi Or Not To Be
                                29
which Transact-SQL statements are
the top consumers of tempdb space
 SELECT t1.session_id, t1.request_id,
     t1.task_alloc, t1.task_dealloc, t2.sql_handle,
     t2.statement_start_offset, t2.statement_end_offset,
     t2.plan_handle FROM (Select session_id,
     request_id, SUM(internal_objects_alloc_page_count)
     AS task_alloc, SUM
     (internal_objects_dealloc_page_count) AS
     task_dealloc
  FROM sys.dm_db_task_space_usage
  GROUP BY session_id, request_id) AS
     t1, sys.dm_exec_requests AS t2 WHERE t1.session_id
     = t2.session_id AND (t1.request_id = t2.request_id)
  ORDER BY t1.task_alloc DESC

11/2/2009        Dubi Or Not To Be
                                                           30
Perfmon counters
 Access Methods::Worktables Created/sec
    temporary objects and are used to store results for query
     spool, LOB variables, and cursors.
    Typically this number is < 200
 Access Methods::Workfiles Created/sec
    temporary results for hash joins and hash aggregates
 Access Methods: Worktables From Cache Ratio




11/2/2009        Dubi Or Not To Be
                                                                 31
Perfmon counters
 Temp Tables Creation Rate (SQL Server 2005)
    The number of temporary table or variables created/sec.
 Temp Tables For Destruction (SQL Server 2005)
    The number of temporary tables or variables waiting to be
     destroyed by cleanup system thread.




11/2/2009        Dubi Or Not To Be
                                                                 32
How to add space to TempDB?
 ALTER DATABASE, the data file will return to the new
  size every time you restart the instance of SQL Server.
 Set the recovery model of TempDB to SIMPLE.

 Turn      on auto-grow, but be careful, % can be dangers!
  based it on the speed of the I/O subsystem

 BUT it is a good idea to turn         off the auto-grow feature
  for the TempDB data files



11/2/2009           Dubi Or Not To Be
                                                                    33
Hardware
 Generally, RAID 1+0 provides better write performance
  than any other RAID level providing data protection,
  including RAID 5.
 Striping recommended
 Separate from user databases
 SQL Server 2008
    CHECKSUM for new installs (Earlier versions – NONE, Not
     changeable)
    On upgrade NONE still default
    Recommend setting CHECKSUM after upgrade


11/2/2009        Dubi Or Not To Be
                                                               34
File Placement
 On a high-performance IO subsystem
 Preferably on a separate spindle(s)
 IO subsystem requirements not as strict
    Durability not required (KB917047)
    RAM Disk or IO subsystem with cache




 multiple files on the same physical spindle or multiple
  devices?


                                                            35
Number of Files
 create as many files as needed to maximize disk
  bandwidth.
 One of the best practice is to create one data file for
  each (virtual) CPU on the server
 KB 328551 -
    Trace flag 1118 switches allocations in TempDB from
     single-page at a time for the first 8 pages
    create the files with equal sizing




11/2/2009         Dubi Or Not To Be
                                                            36
equal sizing
The equal sizing of data files is critical because the
  proportional fill algorithm is based on the size of the
  files. If data files are created with unequal sizes, the
  proportional fill algorithm tries to use the largest file
  more for GAM allocations instead of spreading the
  allocations between all the files, thereby defeating the
  purpose of creating multiple data files.




11/2/2009        Dubi Or Not To Be
                                                              37
Moving TempDB from system disk
Alter database TempDB modify file
  (name = tempdev,
  filename = „DEV:MyPathTempDB.mdf')

Alter database TempDB modify file
  (name = templog,
  filename = „DEV:MyPathtemplog.ldf')

Restart server

11/2/2009        Dubi Or Not To Be
                                          38
What about the log file?
 Most operations in tempdb are not logged.
 Operations on user objects are logged.
 Sort operations in tempdb also require logging.
 Estimating the log space:
    similar to estimating the log file size for other databases.


 Multi log files?




11/2/2009         Dubi Or Not To Be
                                                                    39
Moving TempDB from system disk
 Be careful when you move the TempDB database
  because if the TempDB database cannot be created,
  SQL Server will not start. If the TempDB database
  cannot be created, start SQL Server by using the (-f)
  startup parameter and move the TempDB database to a
  valid location.




11/2/2009      Dubi Or Not To Be
                                                          40
What about Shrinking files?
 Auto shrink is not allowed for tempdb.
 How to shrink the TempDB database in SQL Server
  http://support.microsoft.com/kb/307487




It is not recommended!

11/2/2009       Dubi Or Not To Be
                                                    41
What about auto update stats?
 disabling the auto update stats
 Usually objects created in the TempDB are fairly small
  and, as such, the statistics will not reach the threshold
  that causes the statistics to update automatically.
 However, you'll need to manually update statistics if you
  occasionally use large temporary objects.
 What about “auto create statistics”



11/2/2009       Dubi Or Not To Be
                                                              42
Indexing temporary table
 Indexing temporary large temp tables greatly increases
  TempDB performance
 use the normal CREATE INDEX command after the table
  has been created.
 table variables cannot have indexes created on them.
  But can have a primary key defined upon creation
  using the DECLARE @variable TABLE command.




11/2/2009       Dubi Or Not To Be
                                                           43
Restrictions
 Adding filegroups.

 Backing up or restoring the database.

 Changing collation. The default collation is the server collation.

 Changing the database owner. TempDB is owned by dbo.

 Creating a database snapshot.

 Dropping the database.

 Dropping the guest user from the database.

 Enabling change data capture.



11/2/2009              Dubi Or Not To Be
                                                                       44
Restrictions
 Participating in database mirroring.

 Removing the primary filegroup, primary data file, or log file.

 Renaming the database or primary filegroup.

 Running DBCC CHECKALLOC.

 Running DBCC CHECKCATALOG.

 Setting the database to OFFLINE.

 Setting the database or primary filegroup to READ_ONLY.




11/2/2009             Dubi Or Not To Be
                                                                    45
 Working with tempdb in SQL Server 2005
    http://technet.microsoft.com/en-us/library/cc966545.aspx
   Capacity Planning for TempDB
    http://msdn.microsoft.com/en-us/library/ms345368.aspx
   TempDB Database
     http://msdn.microsoft.com/en-us/library/ms190768.aspx
   Concurrency enhancements for the TempDB database
    http://support.microsoft.com/kb/328551
   How to shrink the TempDB database in SQL Server
    http://support.microsoft.com/kb/307487

    11/2/2009     Dubi Or Not To Be
                                                         46
END or AND ?

D.O.N.T.B


11/2/2009   Dubi Or Not To Be
                                47

More Related Content

More from sqlserver.co.il

SQL Explore 2012: P&T Part 3
SQL Explore 2012: P&T Part 3SQL Explore 2012: P&T Part 3
SQL Explore 2012: P&T Part 3sqlserver.co.il
 
SQL Explore 2012: P&T Part 2
SQL Explore 2012: P&T Part 2SQL Explore 2012: P&T Part 2
SQL Explore 2012: P&T Part 2sqlserver.co.il
 
SQL Explore 2012: P&T Part 1
SQL Explore 2012: P&T Part 1SQL Explore 2012: P&T Part 1
SQL Explore 2012: P&T Part 1sqlserver.co.il
 
SQL Explore 2012 - Tzahi Hakikat and Keren Bartal: Extended Events
SQL Explore 2012 - Tzahi Hakikat and Keren Bartal: Extended EventsSQL Explore 2012 - Tzahi Hakikat and Keren Bartal: Extended Events
SQL Explore 2012 - Tzahi Hakikat and Keren Bartal: Extended Eventssqlserver.co.il
 
SQL Explore 2012 - Michael Zilberstein: ColumnStore
SQL Explore 2012 - Michael Zilberstein: ColumnStoreSQL Explore 2012 - Michael Zilberstein: ColumnStore
SQL Explore 2012 - Michael Zilberstein: ColumnStoresqlserver.co.il
 
SQL Explore 2012 - Meir Dudai: DAC
SQL Explore 2012 - Meir Dudai: DACSQL Explore 2012 - Meir Dudai: DAC
SQL Explore 2012 - Meir Dudai: DACsqlserver.co.il
 
SQL Explore 2012 - Aviad Deri: Spatial
SQL Explore 2012 - Aviad Deri: SpatialSQL Explore 2012 - Aviad Deri: Spatial
SQL Explore 2012 - Aviad Deri: Spatialsqlserver.co.il
 
Bi303 data warehousing with fast track and pdw - Assaf Fraenkel
Bi303 data warehousing with fast track and pdw - Assaf FraenkelBi303 data warehousing with fast track and pdw - Assaf Fraenkel
Bi303 data warehousing with fast track and pdw - Assaf Fraenkelsqlserver.co.il
 
Fast transition to sql server 2012 from mssql 2005 2008 for developers - Dav...
Fast transition to sql server 2012 from mssql 2005 2008 for  developers - Dav...Fast transition to sql server 2012 from mssql 2005 2008 for  developers - Dav...
Fast transition to sql server 2012 from mssql 2005 2008 for developers - Dav...sqlserver.co.il
 
Extreme performance - IDF UG
Extreme performance - IDF UGExtreme performance - IDF UG
Extreme performance - IDF UGsqlserver.co.il
 
3 extreme performance - databases acceleration using ssd
3   extreme performance - databases acceleration using ssd 3   extreme performance - databases acceleration using ssd
3 extreme performance - databases acceleration using ssd sqlserver.co.il
 
3 extreme performance - databases acceleration using ssd
3   extreme performance - databases acceleration using ssd 3   extreme performance - databases acceleration using ssd
3 extreme performance - databases acceleration using ssd sqlserver.co.il
 
4 extreme performance - part ii
4   extreme performance - part ii4   extreme performance - part ii
4 extreme performance - part iisqlserver.co.il
 
2 extreme performance - smaller is better
2   extreme performance - smaller is better2   extreme performance - smaller is better
2 extreme performance - smaller is bettersqlserver.co.il
 

More from sqlserver.co.il (20)

SQL Explore 2012: P&T Part 3
SQL Explore 2012: P&T Part 3SQL Explore 2012: P&T Part 3
SQL Explore 2012: P&T Part 3
 
SQL Explore 2012: P&T Part 2
SQL Explore 2012: P&T Part 2SQL Explore 2012: P&T Part 2
SQL Explore 2012: P&T Part 2
 
SQL Explore 2012: P&T Part 1
SQL Explore 2012: P&T Part 1SQL Explore 2012: P&T Part 1
SQL Explore 2012: P&T Part 1
 
SQL Explore 2012 - Tzahi Hakikat and Keren Bartal: Extended Events
SQL Explore 2012 - Tzahi Hakikat and Keren Bartal: Extended EventsSQL Explore 2012 - Tzahi Hakikat and Keren Bartal: Extended Events
SQL Explore 2012 - Tzahi Hakikat and Keren Bartal: Extended Events
 
SQL Explore 2012 - Michael Zilberstein: ColumnStore
SQL Explore 2012 - Michael Zilberstein: ColumnStoreSQL Explore 2012 - Michael Zilberstein: ColumnStore
SQL Explore 2012 - Michael Zilberstein: ColumnStore
 
SQL Explore 2012 - Meir Dudai: DAC
SQL Explore 2012 - Meir Dudai: DACSQL Explore 2012 - Meir Dudai: DAC
SQL Explore 2012 - Meir Dudai: DAC
 
SQL Explore 2012 - Aviad Deri: Spatial
SQL Explore 2012 - Aviad Deri: SpatialSQL Explore 2012 - Aviad Deri: Spatial
SQL Explore 2012 - Aviad Deri: Spatial
 
מיכאל
מיכאלמיכאל
מיכאל
 
נועם
נועםנועם
נועם
 
עדי
עדיעדי
עדי
 
מיכאל
מיכאלמיכאל
מיכאל
 
Bi303 data warehousing with fast track and pdw - Assaf Fraenkel
Bi303 data warehousing with fast track and pdw - Assaf FraenkelBi303 data warehousing with fast track and pdw - Assaf Fraenkel
Bi303 data warehousing with fast track and pdw - Assaf Fraenkel
 
DBCC - Dubi Lebel
DBCC - Dubi LebelDBCC - Dubi Lebel
DBCC - Dubi Lebel
 
Fast transition to sql server 2012 from mssql 2005 2008 for developers - Dav...
Fast transition to sql server 2012 from mssql 2005 2008 for  developers - Dav...Fast transition to sql server 2012 from mssql 2005 2008 for  developers - Dav...
Fast transition to sql server 2012 from mssql 2005 2008 for developers - Dav...
 
ISUG 113: File stream
ISUG 113: File streamISUG 113: File stream
ISUG 113: File stream
 
Extreme performance - IDF UG
Extreme performance - IDF UGExtreme performance - IDF UG
Extreme performance - IDF UG
 
3 extreme performance - databases acceleration using ssd
3   extreme performance - databases acceleration using ssd 3   extreme performance - databases acceleration using ssd
3 extreme performance - databases acceleration using ssd
 
3 extreme performance - databases acceleration using ssd
3   extreme performance - databases acceleration using ssd 3   extreme performance - databases acceleration using ssd
3 extreme performance - databases acceleration using ssd
 
4 extreme performance - part ii
4   extreme performance - part ii4   extreme performance - part ii
4 extreme performance - part ii
 
2 extreme performance - smaller is better
2   extreme performance - smaller is better2   extreme performance - smaller is better
2 extreme performance - smaller is better
 

Recently uploaded

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
 
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
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfsudhanshuwaghmare1
 
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 Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxMalak Abu Hammad
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking MenDelhi Call girls
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking MenDelhi Call girls
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...Martijn de Jong
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerThousandEyes
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Miguel Araújo
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Servicegiselly40
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...Neo4j
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Drew Madelung
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024The Digital Insurer
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonAnna Loughnan Colquhoun
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024The Digital Insurer
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Enterprise Knowledge
 
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
 
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
 
🐬 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
 

Recently uploaded (20)

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
 
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
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
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 Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptx
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Service
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...
 
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
 
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
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 

Nothing Is Not More Permanent Than The Temporary

  • 1. Wonder TempDB Dubi Lebel Dad, chef, gardener and DBA Dubi.lebel@gmail.com
  • 2. Who am I?  Dubi- Or Not To Be  To do is to be - Descartes  To be is to do - Voltaire  Do be do be do - Frank Sinatra  Yaba Daba Do - Fred Flintstone 11/2/2009 Dubi Or Not To Be 2
  • 3. Temporary Agenda  It all about TemDB  For what?  Where?  How to?  best practice! 11/2/2009 Dubi Or Not To Be 3
  • 4. TempDB  Only one TempDB per instance.  Operations within TempDB are minimally logged.  data in TempDB does not persist after SQL Server shuts down.  Only one file group in TempDB is allowed for data and one file group for logs.  By default auto grow is enabled.  When the server restarts, the TempDB file size is reset to the configured value (the default is 8 MB). 11/2/2009 Dubi Or Not To Be 4
  • 5. What is TempDB BOL: The TempDB system database is a global resource that is available to all users connected to the instance of SQL Server and is used to hold the following: 11/2/2009 Dubi Or Not To Be 5
  • 6. BOL: TempDB hold the following :  Temporary user objects that are explicitly created, such as: global or local  temporary tables,  temporary stored procedures,  table variables,  Cursors (Key-set-driven and static cursors ). 11/2/2009 Dubi Or Not To Be 6
  • 7. BOL: TempDB hold the following :  Internal objects that are created by the SQL Server Database Engine, for example:  work tables to store intermediate results for:  spools  sorting.  Hash match.  Index (create with SORT_IN_TempDB ) 11/2/2009 Dubi Or Not To Be 7
  • 8. BOL: TempDB hold the following :  Row versions that are generated by data modification transactions in a database that uses read- committed  using row versioning isolation  snapshot isolation transactions. 11/2/2009 Dubi Or Not To Be 8
  • 9. BOL: TempDB hold the following :  Row versions that are generated by data modification transactions for features, such as:  online index operations,  Multiple Active Result Sets (MARS),  AFTER triggers. 11/2/2009 Dubi Or Not To Be 9
  • 10. Is that all? 11/2/2009 Dubi Or Not To Be 10
  • 11. TempDB also hold the following:  DBCC CHECK  Service Broker  Database Mail (Service Broker)  Event notifications (Service Broker)  Query notifications (Service Broker)  XML  Common table expression queries (with cte(col,col) as select..)  Large object (LOB) data type variables and parameters 11/2/2009 Dubi Or Not To Be 11
  • 12. event log: Source: MSSQLSERVER Event ID: 17052 Description: The log file for database 'TempDB' is full. Back up the transaction log for the database to free up some log space 11/2/2009 Dubi Or Not To Be 12
  • 13. error message Server: Msg 8624, Level 16, State 1 Internal SQL Server error or Server: Msg 1101, Level 17, State 10, Line 1 Could not allocate new page for database 'TempDB'. There are no more pages available in filegroup DEFAULT. Space can be created by dropping objects, adding additional files, or allowing file growth. 11/2/2009 Dubi Or Not To Be 13
  • 14. How to plan TempDB Capacity ?  Check that auto-grow is on or off for TempDB  Execute individual queries , workload trace files , index maintenance and monitor TempDB space.  Sum the space-use values from the previous steps to predict your total workload usage.  adjust this value. And adjust again. 11/2/2009 Dubi Or Not To Be 14
  • 15. How to Monitor TempDB Use?  sys.dm_db_file_space_usage - disk space that is used  sys.dm_db_session_space_usage and sys.dm_db_task_space_usage - page allocation or deallocation activity 11/2/2009 Dubi Or Not To Be 15
  • 16. Monitoring TempDB Disk Space 1 SELECT SUM(unallocated_extent_page_count) AS [free pages], (SUM(unallocated_extent_page_count)*1.0/128) AS [free space in MB] FROM sys.dm_db_file_space_usage; returns the total number of free pages and total free space in megabytes (MB) available in all files in TempDB 11/2/2009 Dubi Or Not To Be 16
  • 17. 11/2/2009 Dubi Or Not To Be 17
  • 18. Monitoring TempDB Disk Space 2 SELECT SUM(version_store_reserved_page_count) AS [version store pages used], (SUM(version_store_reserved_page_count)*1.0/128) AS [version store space in MB] FROM sys.dm_db_file_space_usage; returns the total number of pages used by the version store and the total space in MB used by the version store in TempDB 11/2/2009 Dubi Or Not To Be 18
  • 19. 11/2/2009 Dubi Or Not To Be 19
  • 20. Monitoring TempDB Disk Space 3 SELECT transaction_id FROM sys.dm_tran_active_snapshot_database_transactions ORDER BY elapsed_time_seconds DESC; If the version store is using a lot of space in TempDB, you must determine what is the longest running transaction. 11/2/2009 Dubi Or Not To Be 20
  • 21. 11/2/2009 Dubi Or Not To Be 21
  • 22. Monitoring TempDB Disk Space 4 SELECT SUM(internal_object_reserved_page_count) AS [internal object pages used], (SUM(internal_object_reserved_page_count)*1.0/128) AS [internal object space in MB] FROM sys.dm_db_file_space_usage; returns the total number of pages used by internal objects and the total space in MB used by internal objects in TempDB 11/2/2009 Dubi Or Not To Be 22
  • 23. 11/2/2009 Dubi Or Not To Be 23
  • 24. Monitoring TempDB Disk Space 5 SELECT SUM(user_object_reserved_page_count) AS [user object pages used], (SUM(user_object_reserved_page_count)*1.0/128) AS [user object space in MB] FROM sys.dm_db_file_space_usage; returns the total number of pages used by user objects and the total space used by user objects in TempDB. 11/2/2009 Dubi Or Not To Be 24
  • 25. 11/2/2009 Dubi Or Not To Be 25
  • 26. Monitoring TempDB Disk Space 6 SELECT SUM(size)*1.0/128 AS [size in MB] FROM TempDB.sys.database_files returns the total amount of disk space used by all files in TempDB. 11/2/2009 Dubi Or Not To Be 26
  • 27. 11/2/2009 Dubi Or Not To Be 27
  • 28. SELECT SUM (user_object_reserved_page_count)*8 as usr_obj_kb, SUM (internal_object_reserved_page_count)*8 as internal_obj_kb, SUM (unallocated_extent_page_count)*8 as freespace_kb, SUM (mixed_extent_page_count)*8 as mixedextent_kb FROM sys.dm_db_file_space_usag 11/2/2009 Dubi Or Not To Be 28
  • 29. 11/2/2009 Dubi Or Not To Be 29
  • 30. which Transact-SQL statements are the top consumers of tempdb space  SELECT t1.session_id, t1.request_id, t1.task_alloc, t1.task_dealloc, t2.sql_handle, t2.statement_start_offset, t2.statement_end_offset, t2.plan_handle FROM (Select session_id, request_id, SUM(internal_objects_alloc_page_count) AS task_alloc, SUM (internal_objects_dealloc_page_count) AS task_dealloc FROM sys.dm_db_task_space_usage GROUP BY session_id, request_id) AS t1, sys.dm_exec_requests AS t2 WHERE t1.session_id = t2.session_id AND (t1.request_id = t2.request_id) ORDER BY t1.task_alloc DESC 11/2/2009 Dubi Or Not To Be 30
  • 31. Perfmon counters  Access Methods::Worktables Created/sec  temporary objects and are used to store results for query spool, LOB variables, and cursors.  Typically this number is < 200  Access Methods::Workfiles Created/sec  temporary results for hash joins and hash aggregates  Access Methods: Worktables From Cache Ratio 11/2/2009 Dubi Or Not To Be 31
  • 32. Perfmon counters  Temp Tables Creation Rate (SQL Server 2005)  The number of temporary table or variables created/sec.  Temp Tables For Destruction (SQL Server 2005)  The number of temporary tables or variables waiting to be destroyed by cleanup system thread. 11/2/2009 Dubi Or Not To Be 32
  • 33. How to add space to TempDB?  ALTER DATABASE, the data file will return to the new size every time you restart the instance of SQL Server.  Set the recovery model of TempDB to SIMPLE.  Turn on auto-grow, but be careful, % can be dangers! based it on the speed of the I/O subsystem  BUT it is a good idea to turn off the auto-grow feature for the TempDB data files 11/2/2009 Dubi Or Not To Be 33
  • 34. Hardware  Generally, RAID 1+0 provides better write performance than any other RAID level providing data protection, including RAID 5.  Striping recommended  Separate from user databases  SQL Server 2008  CHECKSUM for new installs (Earlier versions – NONE, Not changeable)  On upgrade NONE still default  Recommend setting CHECKSUM after upgrade 11/2/2009 Dubi Or Not To Be 34
  • 35. File Placement  On a high-performance IO subsystem  Preferably on a separate spindle(s)  IO subsystem requirements not as strict  Durability not required (KB917047)  RAM Disk or IO subsystem with cache  multiple files on the same physical spindle or multiple devices? 35
  • 36. Number of Files  create as many files as needed to maximize disk bandwidth.  One of the best practice is to create one data file for each (virtual) CPU on the server  KB 328551 -  Trace flag 1118 switches allocations in TempDB from single-page at a time for the first 8 pages  create the files with equal sizing 11/2/2009 Dubi Or Not To Be 36
  • 37. equal sizing The equal sizing of data files is critical because the proportional fill algorithm is based on the size of the files. If data files are created with unequal sizes, the proportional fill algorithm tries to use the largest file more for GAM allocations instead of spreading the allocations between all the files, thereby defeating the purpose of creating multiple data files. 11/2/2009 Dubi Or Not To Be 37
  • 38. Moving TempDB from system disk Alter database TempDB modify file (name = tempdev, filename = „DEV:MyPathTempDB.mdf') Alter database TempDB modify file (name = templog, filename = „DEV:MyPathtemplog.ldf') Restart server 11/2/2009 Dubi Or Not To Be 38
  • 39. What about the log file?  Most operations in tempdb are not logged.  Operations on user objects are logged.  Sort operations in tempdb also require logging.  Estimating the log space:  similar to estimating the log file size for other databases.  Multi log files? 11/2/2009 Dubi Or Not To Be 39
  • 40. Moving TempDB from system disk  Be careful when you move the TempDB database because if the TempDB database cannot be created, SQL Server will not start. If the TempDB database cannot be created, start SQL Server by using the (-f) startup parameter and move the TempDB database to a valid location. 11/2/2009 Dubi Or Not To Be 40
  • 41. What about Shrinking files?  Auto shrink is not allowed for tempdb.  How to shrink the TempDB database in SQL Server http://support.microsoft.com/kb/307487 It is not recommended! 11/2/2009 Dubi Or Not To Be 41
  • 42. What about auto update stats?  disabling the auto update stats  Usually objects created in the TempDB are fairly small and, as such, the statistics will not reach the threshold that causes the statistics to update automatically.  However, you'll need to manually update statistics if you occasionally use large temporary objects.  What about “auto create statistics” 11/2/2009 Dubi Or Not To Be 42
  • 43. Indexing temporary table  Indexing temporary large temp tables greatly increases TempDB performance  use the normal CREATE INDEX command after the table has been created.  table variables cannot have indexes created on them. But can have a primary key defined upon creation using the DECLARE @variable TABLE command. 11/2/2009 Dubi Or Not To Be 43
  • 44. Restrictions  Adding filegroups.  Backing up or restoring the database.  Changing collation. The default collation is the server collation.  Changing the database owner. TempDB is owned by dbo.  Creating a database snapshot.  Dropping the database.  Dropping the guest user from the database.  Enabling change data capture. 11/2/2009 Dubi Or Not To Be 44
  • 45. Restrictions  Participating in database mirroring.  Removing the primary filegroup, primary data file, or log file.  Renaming the database or primary filegroup.  Running DBCC CHECKALLOC.  Running DBCC CHECKCATALOG.  Setting the database to OFFLINE.  Setting the database or primary filegroup to READ_ONLY. 11/2/2009 Dubi Or Not To Be 45
  • 46.  Working with tempdb in SQL Server 2005 http://technet.microsoft.com/en-us/library/cc966545.aspx  Capacity Planning for TempDB http://msdn.microsoft.com/en-us/library/ms345368.aspx  TempDB Database http://msdn.microsoft.com/en-us/library/ms190768.aspx  Concurrency enhancements for the TempDB database http://support.microsoft.com/kb/328551  How to shrink the TempDB database in SQL Server http://support.microsoft.com/kb/307487 11/2/2009 Dubi Or Not To Be 46
  • 47. END or AND ? D.O.N.T.B 11/2/2009 Dubi Or Not To Be 47