Presentation is loading. Please wait.

Presentation is loading. Please wait.

Tempdb More Permanent than you think

Similar presentations


Presentation on theme: "Tempdb More Permanent than you think"— Presentation transcript:

1

2 Tempdb More Permanent than you think
Paresh Motiwala PMP® LinkedIN: pareshmotiwala Facebook: Paresh Motiwala DBA, Project Manager, Singer, Photographer and Speaker(potty trained) Tempdb More Permanent than you think

3 My other topics Digital Forensics Database Forensics
From DBA to PM in 60 mins flat Why are DBAs afraid to use tools? Copy Data Virtualization/Management Setting up your BI infrastructure Network or perish SQL Best Practices document SSIS SSRS Three Oracle DBAs and three SQL DBAs are traveling by train to a conference. At the station, the three Oracle DBAs each buy tickets and watch as the three SQL DBAs buy only a single ticket. "How are three people going to travel on only one ticket?" asks a Oracle DBA. "Watch and you'll see," answers the SQL DBA. They all board the train. The Oracle DBAs take their respective seats but all three SQL DBAs cram into a rest room and close the door behind them. Shortly after the train has departed, the conductor comes around collecting tickets. He knocks on the rest room door and says, "Ticket, please." The door opens just a crack and a single arm emerges with a ticket in hand. The conductor takes it and moves on. The Oracle DBAs saw this and agreed it was quite a clever idea. So after the conference, the Oracle DBAs decide to copy the SQL DBAs on the return trip and save some money. When they get to the station, they buy a single ticket for the return trip. To their astonishment, the SQL DBAs don't buy a ticket at all. "How are you going to travel without a ticket?" asks one perplexed ORACLE DBAs. "Watch and you'll see," answers an SQL DBA and they board the train the three Microsoft employees cram into a rest room and the three Apple engineers cram into another one nearby. The train departs. Shortly afterward, one of the SQL DBAs leaves his rest room and walks over to the rest room where the Oracle DBAs are hiding. He knocks on the door and says, "Ticket, please".

4 Tempdb- Who should attend?
DBAs Developers Managers People who think they are DBAs

5 Tempdb- Agenda for the day
Tempdb – General info Restrictions What takes up space in Tempdb? Allocation of Tempdb Performance Improvement Trace Flag 1117/ Trace Flag Tempdb configuration Tempdb contention Backup/Restore/Relocation/Snapshot of Tempdb Some tips for minimizing use of Tempdb Is your Tempdb configured correctly? Enhancements in SQL 2016

6 Tempdb- General Info DBID- 2 Initial Weight – 8MB, 1 MB -Till SQL 2014
Collation – Same as that of the database server

7 Tempdb- Restrictions Adding file groups
Backing up or restoring the database* Creating a database snapshot* Changing the database owner. Tempdb is owned by sa Changing collation Dropping the database Dropping the guest user

8 Tempdb- Restrictions (Continued…)
Enabling change data capture Participating in database mirroring Removing the primary file group, primary data file, or log file Renaming the database or primary file group Running DBCC CHECKALLOC Running DBCC CHECKCATALOG Setting the database to OFFLINE Setting the database or primary file group to READ_ONLY

9 Tempdb- What takes up space in Tempdb
From a feature perspective, here are the features in SQL Server that use space from tempdb. Query Triggers Snapshot isolation and read committed snapshot (RCSI) MARS(Multiple Active Result Sets) Online index creation Temporary tables, table variables, and table-valued functions DBCC CHECKDB

10 Tempdb- What takes up space in Tempdb (Continued…)
LOB parameters Cursors Service Broker and event notification XML and LOB variables Query notifications Database mail Index creation User-defined functions

11 Tempdb- Allocation changes
In SQL Server 2005 When it is dropped Subsequent temp table creations ,allocation system was changed for Tempdb to reduce the possibility of contention. There is now a cache of temp tables instead of all the pages being de-allocated completely, one IAM page and one data page are left allocated, will look in the cache to see if they can just grab a pre-created temp table ‘off the shelf’. If so, this avoids accessing the allocation bitmaps completely. This can lead to a big drop in contention, as long as the temp tables can be cached, and the query plan being dropped from memory doesn’t cause the cached temp table to be removed.

12 Tempdb- Performance Improvements
Temporary tables and table variables may be cached. Allocation page latching protocol is improved. Logging overhead for Tempdb is reduced. Setup adds multiple Tempdb data files during a new instance installation. By default, setup will add as many Tempdb files as the CPU count or 8, whichever is lower. 2. This reduces the number of UP (update) latches that are used. 3. This reduces disk I/O bandwidth consumption on the Tempdb log file. 4. This task can be accomplished with the new UI input control on the Database Engine Configuration section and a command line parameter /SQLTempdbFILECOUNT. SQL DBA and Pot of Gold joke.

13 Tempdb- Trace Flags Trace Flag 1118 - FULL EXTENTS ONLY KB 2154845
Trace Flag 1117 – Grow all files in a file group equally

14 Tempdb- Configuration?
Capacity planning for Tempdb  Create SQL server job to monitor Tempdb size at peak and non peak time Execute queries or your workload one by one. Execute index maintenance operations, such as rebuilding indexes on large tables. In fact, you must monitor Tempdb size regularly to forecast the trend and predict requirements proactively. Creating a report showing trending will be a good idea for this. In Azure, for IAAS never ever ever put anything on D Drive, including Tempdb TDE also encrypts Tempdb that can lower your server wide performance. Placement of Tempdb files Tempdb # of files myth 1. is always a typical question for every DBA. Determining the right size for Tempdb in a new production environment or existing environment depends on many factors. The problem, there is no thumb rule. Based on requirements, server usages, user database size, table size, existing workload, SQL Server features etc. you should plan capacity. You can also analyze the existing workload by performing these tasks in a SQL Server test environment. First, set autogrow on for Tempdb. This will help you to determine the size of Tempdb at the end No. of Cores Data files recommended <8 = No. of Cores >=8 to <32 = No. of Cores/2 >=32 = No. of Cores/4

15 Copy Data Virtualization: Method to Backup TempDB or any database
Mount Staging Disk on Server Mounted via FC or iSCSI Copy Incremental Changes Microsoft VSS + Actifio CBT Driver Unmount Staging Disk on Server Snapshot Staging Disk on Actifio App APIs FC / iSCSI SQL SERVER Dedup Snapshot DAS STORAGE ARRAY NAS/FILESERVER COPYRIGHT © 2014 ACTIFIO

16 Tempdb- Snapshot/Backup/Restore
Copy Data Management/Virtualization E Master Copy Clone Production V O P 1. Why would you take copies of tempdb? S

17 Tempdb- SQL 2016 Enhancements
Traceflag now enabled Traceflag now enabled So how will you size the Tempdb now? These out-of-the-box enhancements for tempdb in SQL Server 2016 reduces tempdb contention issues by default by having multiple tempdb data files. This helps reduce contention on the PFS, GAM and SGAM pages. Don't forget to make sure that you size your data files to your workload, as that is not done automatically. Trace flags 1118 and 1117 were available in versions prior to SQL Server 2016, however, you had to manually enable them. With SQL Server 2016, this benefit is available for tempdb out of the box. The user experience for tempdb should be drastically improved for users of SQL Server 2016.

18 Tempdb – SQL 2016 Enhancements

19 Tempdb- Minimizing TembDB Utilization
Use fewer #temp tables variables Minimize concurrent index maintenance, and avoid the SORT_IN_Tempdb option if it isn't needed Thoroughly test the use of snapshot /RC isolation levels Balance between # of temp tables against a large query Avoid overuse of LOB types (max types, XML, etc) as local variables Avoid unnecessary cursors Try to avoid spools Don't use MARS Avoid enabling triggers for bulk operations Keep transactions short and sweet Don't set Tempdb to be everyone's default database CTE abuse leads to performance degradation 4. (e.g. large CTEs that are referenced multiple times in the query) 6. don't just turn it on for all databases since you've been told it's better than NOLOCK (it is, but it isn't free)

20 Tempdb- Summary Tempdb – Birth Chart/Horoscope Restrictions
Allocation of Tempdb -- Performance Improvement Trace Flag 1117 / Trace Flag 1118 Configuration of Tempdb Backup/Restore/Relocation/Snapshot of Tempdb Some tips for minimizing use of Tempdb Is your Tempdb configured correctly?

21 Tempdb- Bibliography BOL Paul White’s blog 8.

22 Remember, Paresh for President 2016
Tempdb- Muchas Gracias Remember, Paresh for President 2016


Download ppt "Tempdb More Permanent than you think"

Similar presentations


Ads by Google