TempDB Best Practices, Advanced Configs. & Troubleshooting Omar Gonzalez Sr. DBA at Dell Fourth MeetUp DBA200.

Slides:



Advertisements
Similar presentations
Yukon – What is New Rajesh Gala. Yukon – What is new.NET Framework Programming Data Types Exception Handling Batches Databases Database Engine Administration.
Advertisements

SQL Server 2005 Implementation and Maintenance Chapter 10: Maintaining and Automating SQL Server.
SharePoint and SQL Server integration Demo: SQL Server Optimizing Configurations SQL Server 2014 for SharePoint 2013 Avoiding ginormous transaction.
1 - Oracle Server Architecture Overview
SQL Server 2005 Database Engine Sommarkollo Microsoft.
Chapter 9 Overview  Reasons to monitor SQL Server  Performance Monitoring and Tuning  Tools for Monitoring SQL Server  Common Monitoring and Tuning.
Module 8: Monitoring SQL Server for Performance. Overview Why to Monitor SQL Server Performance Monitoring and Tuning Tools for Monitoring SQL Server.
Database Configuration and Maintenance Database Configuration and Maintenance Exam / 30.
NovaBACKUP 10 xSP Technical Training By: Nathan Fouarge
SQL Server memory architecture and debugging memory Issues
Module 15: Monitoring. Overview Formulate requirements and identify resources to monitor in a database environment Types of monitoring that can be carried.
Building Highly Available Systems with SQL Server™ 2005 Vineet Gupta Evangelist – Data and Integration Microsoft Corp.
Module 8: Server Management. Overview Server-level and instance-level resources such as memory and processes Database-level resources such as logical.
Chapter 2: Designing Physical Storage MCITP Administrator: Microsoft SQL Server 2005 Database Server Infrastructure Design Study Guide (70-443)
Chapter Oracle Server An Oracle Server consists of an Oracle database (stored data, control and log files.) The Server will support SQL to define.
Module 3: Managing Database Files. Overview Introduction to Data Structures Creating Databases Managing Databases Placing Database Files and Logs Optimizing.
TEMPDB Capacity Planning. Indexing Advantages – Increases performance – SQL server do not have to search all the rows. – Performance, Concurrency, Required.
Architecture Rajesh. Components of Database Engine.
Oracle Tuning Ashok Kapur Hawkeye Technology, Inc.
Module 16: Performing Ongoing Database Maintenance
© 2008 Quest Software, Inc. ALL RIGHTS RESERVED. Perfmon and Profiler 101.
Srik Raghavan Principal Lead Program Manager Kevin Cox Principal Program Manager SESSION CODE: DAT206.
Troubleshooting SQL Server Performance: Tips &Tools Amit Khandelwal.
MISSION CRITICAL COMPUTING Siebel Database Considerations.
Oracle Architecture - Structure. Oracle Architecture - Structure The Oracle Server architecture 1. Structures are well-defined objects that store the.
TOP 10 Thinks you shouldn’t do with/in your database
Connect with life Praveen Srivatsa Founder and CEO – AstraSoft.NET Vinod Kumar Technology Evangelist – Databases and BI.
Copyright Sammamish Software Services All rights reserved. 1 Prog 140  SQL Server Performance Monitoring and Tuning.
Does the Optimistic Concurrency resolve your blocking problems Margarita Naumova, SQL Master Academy.
Linkedin: dennisegraham Dennis E Graham Reporting For SQL Health.
Configuring SQL Server for a successful SharePoint Server Deployment Haaron Gonzalez Solution Architect & Consultant Microsoft MVP SharePoint Server
A deep dive into SQL Server Plan Cache Management.
You Inherited a Database Now What? What you should immediately check and start monitoring for. Tim Radney, Senior DBA for a top 40 US Bank President of.
Oracle Database Architectural Components
Hitting the SQL Server “Go Faster” Button Rob Douglas #509 | Brisbane 2016.
SQL Server DBA Online TrainingSQL Server DBA Online Training.
SQL Database Management
Top 10 DBA mistakes that affect the SQL Server performance
Get the Most out of SQL Server Standard Edition
You Inherited a Database Now What?
Data, Space and Transaction Processing
Inside transaction logging
Hitting the SQL Server “Go Faster” Button
SQL Server Internals Overview
A Technical Overview of Microsoft® SQL Server™ 2005 High Availability Beta 2 Matthew Stephen IT Pro Evangelist (SQL Server)
Designing Database Solutions for SQL Server
Chapter Overview Understanding the Database Architecture
Introduction to SQL Server Management for the Non-DBA
Database Performance Tuning and Query Optimization
Dynamics AX Performance
The Vocabulary of Performance Tuning
Hitting the SQL Server “Go Faster” Button
Configuring SQL Server
Real world In-Memory OLTP
Wellington, SQLSaturday#706
Inside transaction logging
Turbo-Charged Transaction Logs
TEMPDB – INTERNALS AND USAGE
Configuring SQL Server
SQL Server Performance Tuning
It’s TEMPDB Why Should You Care?
The Vocabulary of Performance Tuning
You Inherited a Database Now What?
Chapter 11 Database Performance Tuning and Query Optimization
Transaction Log Performance Tuning
The Vocabulary of Performance Tuning
Using wait stats to determine why my server is slow
Inside the Database Engine
Inside the Database Engine
Presentation transcript:

TempDB Best Practices, Advanced Configs. & Troubleshooting Omar Gonzalez Sr. DBA at Dell Fourth MeetUp DBA200

About my experience Job Experience: Web Developer at Grupo Alica.NET/DB Developer at Coca-Cola.NET Support & SQL DBA at TCS DBA & Web Admin at Intel – contractor DB Admin Advisor at Dell Sr. DBA & HealthCare DB Team Lead at Dell

What is TempDB? TempDB is a system database in SQL Server Tempdb globally stores both internal and user objects and the temporary tables, objects, and stored procedures that are created during SQL Server operation. The tempdb can become overloaded in terms of space available and excessive DDL/DML operations. This can cause unrelated applications running on the server to slow down or fail.

Common Issues Running out of storage space in tempdb Queries that run slowly due to the I/O bottleneck in tempdb Excessive DDL operations leading to a bottleneck in the system tables Allocation contention. Metadata contention.

TempDB Usage User Objects Table and index Global and local temp tables Table variables Internal Objects Has Joins Sorts Cursors (session scope) LOB usage (batch scope) Version Store Online indexing Triggers Snapshot-based isolation levels Row versioning Free Space

Monitoring Space Space used = Internal + User + VersionStore Free Space = Reserved space – Space used NOTE: These calculations don’t account for pages in mixed extents. *DEMO

Trace Flag T1118 Trace flag 1118 forces uniform extent allocations instead of mixed page allocations. The trace flag is commonly used to assist in TEMPDB scalability by avoiding SGAM and other allocation contention points. Blocking and performance problems may occur when you enable trace flag 118 in SQL Server 2005 if the temporary table creation workload is high. Fixed in SQL 2005 with SP2 + KB936185, or with SP3. New feature in SQL Server 2016 allows to specify uniform extents at DB level instead of instance level (trace), by an alter statement. ALTER DATABASE tempdb SET MIXED_PAGE_ALLOCATION OFF; This option is OFF by default, this option is ON for all system DBs. TempDB is the only system DB that supports OFF.

TempDB Space Usage – User Objects BreakDown Siginificant space used by user objects may indicate poor designated queries, most of the time queries used for import-export or for processing purposes. TempDB used as a staging area OLAP / Data WareHouses You can use the sys.dm_db_file_space_usage dynamic management view to monitor the disk space used by the user objects, internal objects, and version stores in the tempdbfiles. sys.dm_db_file_space_usage Additionally, to monitor the page allocation or deallocation activity in tempdb at the session or task level, you can use the sys.dm_db_session_space_usage andsys.dm_db_task_space_usage dyna mic management views. These views can be used to identify large queries, temporary tables, or table variables that are using a large amount of tempdb disk space. sys.dm_db_session_space_usagesys.dm_db_task_space_usage

TempDB Space Usage – Internal Objects BreakDown Work Table LOB usage, large object data type Text, Ntext, Image, Varchar(MAX), NVarchar(MAX), FileStream, XML String functions such as SUBSTRING, REPLICATE UDF (User Defined Functions) Cursors Use set-based functionality instead temporary LOB storage is batch scoped and cursor worktable is session scoped Sort Runs Hash Joins or known as Work File ALTER INDEX WITH REBUILD, SORT_IN_TEMPDB = ON; Service Broker performs caching of objects in the context of query execution. The size is approx. 1 KB per dialog. Used by Database Mail and Event notifications DBCC CHECKDB Run DBCC CHECKDB WITH ESTIMATEONLY Space required = Largest index + “index create memory” option Min memory per query option has precedence over the index create memory option.

TempDB Space Usage – Version Store Triggers Snapshot-based isolation levels based on row versioning Online maintenance ALTER INDEX WITH REORGANIZE; ALTER INDEX WITH REBULID, ONLINE=ON; BulkLoad Operations CTE

TempDB Config. Recommendations Part 1 Size it properly Avoid small sizes and small growths Minimum growth for MB TempDB, 10 MB When TempDB is above 100 MB use a growth of at least 10% or equivalent in MBs. Work around to presizing it. Enable Trace flag 1117 to grow all files in a filegroup equally. It not only impacts TempDB but all other DBs on the instance.

TempDB Config. Recommendations Part 2 Set recovery model to SIMPLE Automatically reclaims log space Create as many files as needed to maximize disk bandwith. As a general rule, create one file per core, up to 8 files. Make each data file the same size; this allows for optimal proportional-fill performance. Put the tempdb database on a fast I/O subsystem. Use disk striping if there are many directly attached disks. Add faster or additional I/O controllers. Add more cache for the controllers. Update SAN software for disks Align it to 64 KB allocation unit size, cluster size.

TempDB Config. Recommendations Part 3 Put the tempdb database on disks that differ from those that are used by user databases. Reduce I/O waits Make sure SWAP or pagefile is not on the same drive as TempDB. Increase I/O bandwith by adding more physical drives to the disk array and/or replace current disks with faster drives. SSD for StandAlone or SSD for TempDB in cluster SQL 2012 Set PAGE_VERIFY option to CHECKSUM starting in SQL Server In earlier versions of SQL Server, the PAGE_VERIFY option is set to NONE for the tempdb database and cannot be modified. In SQL 2008, the default value is CHECKSUM. For upgrades from SQL 2005 the default remains as NONE. When set to CHECKSUM, the PAGE_VERIFY option discovers damaged database paged caused by disk I/O path errors and reports these errors

Maintenance Tasks Set all the data files to the same size DBCC SHRINKFILE: Page 1: could not be moved because it is a work table page. Reduce VLFs Add/move files Monitor space Did I mention monitor space?

How can I monitor my TempDB? Check for free space at the DB Generate custom alerts Create events Create response jobs Make notifications Run periodic reports Schedule auto-growths

Common Performance Counters Avg. Disk Sec/Read Avg. Disk Sec/Write Physical Disk: %Disk Time Physical Disk: %Idle Time

Common Errors Codes 1101/1105 – Any session must allocate space in tempdb – The version store is full. Usually appears after a 1101 or 1105 error – The version store is forced to shrink because tempdb is full 3958/3966 – A transaction cannot find the required version record in tempdb.

Common Related Issues – High DB locks What is it? SH-DATABASE lock Symptoms General rule, keep less than 1K locks Sys.dm_tran_locks Fix/Resolution SQL 2008 SP3 CU17 SQL 2008 R2 SP2 CU13 SQL 2012 SP1 CU9 SQL 2014 CU1

Common Related Issues – High WRITELOG waits What is it? Long waits for SQL to write information into the transactional log file of the DB (LDF). The log pool is an in-memory cache of the transaction log. By default, log pool uses a single global PMO (Pointer to Memory Object) for all databases. When many threads try to write logs by using the log pool, all the threads have to wait for the pointer to a memory object resulting in contention. What is LSN? Symptoms Long WRITELOG waits detected on sys.dm_os_wait_stats DMV Long recovery times at AOAG Long rollback times at transactional replication General long recovery time after reboots or after restoring DBs If you saw this also check for high VLFs

Common Related Issues – High WRITELOG waits Fix/Resolution SQL 2012 SP1 CU3 + Enable trace flag T9024 If the issues persist even after enabling trace flag T9024, you can also enable trace flag T8048 which partitions the pointer to memory object at CPU level. SQL 2012 SP3 SQL 2014 RTM + Enable trace flag T9024 If the issues persist even after enabling trace flag T9024, you can also enable trace flag T8048 which partitions the pointer to memory object at CPU level. SQL 2014 SP1

Common Related Issues – High CPU waits What is it ? Talk about the phases of a process, RUNNABLE, RUNNING, SUSPENDED How can I monitor it? Dm_os_wait_stats CMEMTHREAD than-8-cpus-presented-per-numa-node-may-need-trace-flag-8048/ than-8-cpus-presented-per-numa-node-may-need-trace-flag-8048/ If SQL 2008/2008R2 & CPUs>8. Think about enabling T8048. SOS_SUSPEND_QUEUE CXPACKET Fix/Resolution DO NOT change max worker threads Check/Change MAXDOP instead & its associated cost Evaluate and determinate if you have the adequate number of CPUs and cores Check if any network offload settings are enabled. Most of those features are too old and have seen environments with issues when there are more than 32 cores present.

Common Related Issues – OS Level Update BIOS version Apply OS hotfix as per KB Power Plan Check that it is not set as Power Saving Mode for Prod instances, put it at least on Balanced mode, High Performance is preferred. Follow KB to disable Advanced Power Management in the system’s BIOS for VMs

Common Related Issues – Query Level Check for top queries by CPU, disk, etc. Optimization for Ad-Hoc Workloads SQL compilations per second SQL re-compilations per second SPs WITH RECOMPILE option. Reduce contention at DB level This action will minimize locking contention while protecting transactions from dirty reads of uncommitted data modifications. ALTER DATABASE SET ALLOW_SNAPSHOT_ISOLATION ON ALTER DATABASE SET READ_COMMITTED_SNAPSHOT ON

Common Related Issues – Memory Pressure Buffer Cache Hit Ratio Page Life Expectancy Checkpoint pages/sec Lazywrites/sec DBCCs DBCC FREESYSTEMCACHE(‘SQL Plans’) DBCC FRESSIONCACHE DBCC DROPCLEANBUFFERS DBCC FREESYSTEMCACHE(‘All’) DBCC FREEPROCCACHE; --WARNING! DBCC SQLPERF(‘sys.dm_os_latch_stats’, CLEAR) DBCC SQLPERF(‘sys.dm_os_wait_stats’, CLEAR)

Sources: Optimizing tempdb Performance Capacity Planning for TempDB Troubleshooting Insufficient Disk Space in tempdb Recommendations to reduce allocation contention in SQL Server tempdb database

Q & A Thank You!!!