SQL Server 2012 Service Pack 3 CU3 Available

Microsoft has released SQL Server 2012 Service Pack 3 CU3, which is Build 11.0.6537. There are 23 hotfixes in the public fix list, some of which look pretty significant. If you are running SQL Server 2012, you should be on the SP3 branch by now (or at least be planning on doing so soon).

Microsoft also released SQL Server 2012 Service Pack 2 CU12, which is Build 11.0.5649. There are 8 hotfixes in the public fix list.

As you may be aware, Microsoft has changed their official stance about proactively installing Cumulative Updates, as explained in this post:

Announcing updates to the SQL Server Incremental Servicing Model (ISM)

This means that you should make a greater effort to try to stay as current as possible on Cumulative Updates, despite the extra effort that requires.

If you are still on the SQL Server 2012 RTM or SP1 branches, you are on an “unsupported service pack”, which is not a good place to be, for a number of reasons.

SQL Server Diagnostic Information Queries for April 2016

This month, I have some additional columns in several queries in the SQL Server 2016 set, along with additional comments and documentation in the SQL Server 2012, 2014 and 2016 sets.

Rather than having a separate blog post for each version, I have just put the links for all six major versions in this single post. There are two separate links for each version. The first one on the top left is the actual diagnostic query script, and the one below on the right is the matching blank results spreadsheet, with labeled tabs that correspond to each query in the set. 

Here are links to the latest versions of these queries for SQL Server 2016, 2014 and 2012:

SQL Server 2016 Diagnostic Information Queries (April 2016)

SQL Server 2016 Blank Results

SQL Server 2014 Diagnostic Information Queries (April 2016)

SQL Server 2014 Blank Results

SQL Server 2012 Diagnostic Information Queries (April 2016)

SQL Server 2012 Blank Results

Here are links to the most recent versions of these scripts for SQL Server 2008 R2 and older:

Since SQL Server 2008 R2 and older are out of Mainstream support from Microsoft (and because fewer of my customers are using these old versions of SQL Server), I am not going to be updating the scripts for these older versions of SQL Server every single month going forward.  I started this policy a while ago, and so far, I have not heard any complaints. I did update these queries slightly in January 2016 though.

SQL Server 2008 R2 Diagnostic Information Queries (CY 2016)

SQL Server 2008 R2 Blank Results

SQL Server 2008 Diagnostic Information Queries (CY 2016)

SQL Server 2008 Blank Results

SQL Server 2005 Diagnostic Information Queries (CY 2016)

SQL Server 2005 Blank Results

The basic instructions for using these queries is that you should run each query in the set, one at a time (after reading the directions for that query). It is not really a good idea to simply run the entire batch in one shot, especially the first time you run these queries on a particular server, since some of these queries can take some time to run, depending on your workload and hardware. I also think it is very helpful to run each query, look at the results (and my comments on how to interpret the results) and think about the emerging picture of what is happening on your server as you go through the complete set. I have some comments in the script on how to interpret the results after each query.

You need to click on the top left square of the results grid in SQL Server Management Studio (SSMS) to select all of the results, and then right-click and select “Copy with Headers” to copy all of the results, including the column headers to the Windows clipboard. Then you paste the results into the matching tab in the blank results spreadsheet.

About half of the queries are instance specific and about half are database specific, so you will want to make sure you are connected to a database that you are concerned about instead of the master system database. Running the database-specific queries while being connected to the master database is a very common mistake that I see people making when they run these queries.

Note: These queries are stored on Dropbox. I occasionally get reports that the links to the queries and blank results spreadsheets do not work, which is most likely because Dropbox is blocked wherever people are trying to connect.

I also occasionally get reports that some of the queries simply don’t work. This usually turns out to be an issue where people have some of their user databases in 80 compatibility mode, which breaks many DMV queries, or that someone is running an incorrect version of the script for their version of SQL Server.

It is very important that you are running the correct version of the script that matches the major version of SQL Server that you are running. There is an initial query in each script that tries to confirm that you are using the correct version of the script for your version of SQL Server. If you are not using the correct version of these queries for your version of SQL Server, some of the queries are not going to work correctly.

If you want to understand how to better run and interpret these queries, you should consider listening to my three latest Pluralsight courses, which are SQL Server 2014 DMV Diagnostic Queries – Part 1SQL Server 2014 DMV Diagnostic Queries – Part 2 and SQL Server 2014 DMV Diagnostic Queries – Part 3. All three of these courses are pretty short and to the point, at 67, 77, and 68 minutes respectively. Listening to these three courses is really the best way to thank me for maintaining and improving these scripts…

Please let me know what you think of these queries, and whether you have any suggestions for improvements. Thanks!

Hewlett Packard Enterprise Persistent Memory

Hewlett Packard Enterprise (HPE) has announced a new product that uses non-volatile DIMMs (NVDIMMs), which they are calling Persistent Memory. This short video gives a high level view of how it works, via a whiteboard time lapse. The initial product is an 8GB module which has 8GB of DRAM backed by 8GB of flash for $899.00, which is pretty pricey!

 

Figure 1: HPE 8GB NVDIMM

HPE has a blog post with some more details about their SQL Server testing using NVDIMMs.

They compared the OLTP database performance of a SQL Server database running on an HP DL360 Gen9 server in two scenarios. The details they provide are frustratingly incomplete. They don’t specify what version of SQL Server, what operating system, what type of SSDs, etc.

First Scenario:

  • Data file(s) on six 400GB SSDs
  • Log file on two mirrored SSDs (so two SSDs in RAID 1)
  • 970K transactions/minute
  • 373 µs log write latency

Second Scenario:

  • Data file(s) on six 400GB SSDs
  • Log file on two mirrored SSDs, with two mirrored NVDIMMs as a write-back cache in front of the SSDs
  • 1.08M transactions/minute
  • 181 µs log write latency

 

DB OLTP.jpg

Figure 2: HPE SQL Server Testing with NVDIMMs

 

These results are actually not as impressive as I would expect on the surface, so I would be very curious to more details behind their testing. For example, was their workload previously limited by how fast it could write to the transaction log? After they started using NVDIMMs, did they run into a different bottleneck, such as CPU utilization?

I also want to know more details how this is implemented, with existing server models and existing operating systems. It looks like there is a driver that excludes the DIMM slots that are being used by NVDIMMs from being visible to the operating system as conventional memory, and instead makes them available as a write-back cache layer for an existing storage device. It looks like you can combine multiple NVDIMMs into a single, mirrored cache layer in front of a single storage device. This seems pretty similar in concept to the hardware memory cache in a RAID controller.

This might be pretty useful if you have a workload that is actually seeing bottlenecks writing to a transaction log (or perhaps you have multiple databases with log files on the same logical drive), and you don’t want to use the Delayed Durability feature in SQL Server 2014 and newer or the In-memory OLTP features in SQL Server 2014 Enterprise Edition and newer.

Eight Different Ways to Clear the SQL Server Plan Cache

Nearly anytime you see the command DBCC FREEPROCCACHE mentioned in a blog post, magazine article or book, you usually get some sort of a scary warning about how you should not use it on a production system, or else life as we know it will end. For example, Books Online says this:

Use DBCC FREEPROCCACHE to clear the plan cache carefully. Freeing the plan cache causes, for example, a stored procedure to be recompiled instead of reused from the cache. This can cause a sudden, temporary decrease in query performance. For each cleared cachestore in the plan cache, the SQL Server error log will contain the following informational message: “SQL Server has encountered %d occurrence(s) of cachestore flush for the ‘%s’ cachestore (part of plan cache) due to ‘DBCC FREEPROCCACHE’ or ‘DBCC FREESYSTEMCACHE’ operations.” This message is logged every five minutes as long as the cache is flushed within that time interval.

I would argue that running DBCC FREEPROCCACHE does not cause that much distress with a modern processor, even on a very busy OLTP system. It will cause a pretty minor CPU spike for a few seconds on most systems as the query plans get recompiled as they are executed. It can actually be pretty useful for resetting the cached_time time for sys.dm_exec_procedure_stats so that it is the same for most of the stored procedures in your normal workload. That makes it easier to pick out your most expensive queries or stored procedures on a cumulative basis when you are looking at things like total worker time or total logical reads.

Having said all that, I want to show a few methods for clearing all or part of the plan cache that are somewhat less impactful on the system. Running DBCC FREEPROCCACHE is kind of a brute force approach, so if you are concerned about that, you can run one of the variations shown below:

-- Eight different ways to clear the plan cache
-- Glenn Berry
-- SQLskills.com
    


-- Example 1 ***********************
-- Remove all elements from the plan cache for the entire instance 
DBCC FREEPROCCACHE;


-- Example 2 ***********************
-- Flush the plan cache for the entire instance and suppress the regular completion message
-- "DBCC execution completed. If DBCC printed error messages, contact your system administrator." 
DBCC FREEPROCCACHE WITH NO_INFOMSGS;


-- Example 3 ***********************
-- Flush the ad hoc and prepared plan cache for the entire instance
DBCC FREESYSTEMCACHE ('SQL Plans');


-- Example 4 ***********************
-- Flush the ad hoc and prepared plan cache for one resource pool

-- Get Resource Pool information
SELECT name AS [Resource Pool Name], cache_memory_kb/1024.0 AS [cache_memory (MB)], 
        used_memory_kb/1024.0 AS [used_memory (MB)]
FROM sys.dm_resource_governor_resource_pools;

-- Flush the ad hoc and prepared plan cache for one resource pool
DBCC FREESYSTEMCACHE ('SQL Plans', 'LimitedIOPool');


-- Example 5 **********************
-- Flush the entire plan cache for one resource pool

-- Get Resource Pool information
SELECT name AS [Resource Pool Name], cache_memory_kb/1024.0 AS [cache_memory (MB)], 
        used_memory_kb/1024.0 AS [used_memory (MB)]
FROM sys.dm_resource_governor_resource_pools;


-- Flush the plan cache for one resource pool
DBCC FREEPROCCACHE ('LimitedIOPool');
GO


-- Example 6 **********************
-- Remove all elements from the plan cache for one database (does not work in SQL Azure) 

-- Get DBID from one database name first
DECLARE @intDBID INT;
SET @intDBID = (SELECT [dbid] 
                FROM master.dbo.sysdatabases 
                WHERE name = N'AdventureWorks2014');

-- Flush the plan cache for one database only
DBCC FLUSHPROCINDB (@intDBID);



-- Example 7 **********************
-- Clear plan cache for the current database

USE AdventureWorks2014;
GO
-- Clear plan cache for the current database
-- New in SQL Server 2016 and SQL Azure
ALTER DATABASE SCOPED CONFIGURATION CLEAR PROCEDURE_CACHE;



-- Example 8 **********************
-- Remove one query plan from the cache

USE AdventureWorks2014;
GO

-- Run a stored procedure or query
EXEC dbo.uspGetEmployeeManagers 9;

-- Find the plan handle for that query 
-- OPTION (RECOMPILE) keeps this query from going into the plan cache
SELECT cp.plan_handle, cp.objtype, cp.usecounts, 
DB_NAME(st.dbid) AS [DatabaseName]
FROM sys.dm_exec_cached_plans AS cp CROSS APPLY sys.dm_exec_sql_text(plan_handle) AS st 
WHERE OBJECT_NAME (st.objectid)
LIKE N'%uspGetEmployeeManagers%' OPTION (RECOMPILE); 

-- Remove the specific query plan from the cache using the plan handle from the above query 
DBCC FREEPROCCACHE (0x050011007A2CC30E204991F30200000001000000000000000000000000000000000000000000000000000000);

 

SQL Server 2012 Service Pack 3 CU2 Available

On March 21, 2016, Microsoft released SQL Server 2012 Service Pack 3 CU2, which is Build 11.0.6523.0. This Cumulative Update has 20 hotfixes in the Public fix list, which is a relatively low number for a SQL Server 2012 Cumulative Update.

If you are running SQL Server 2012, I think you should be moving to the SP3 branch pretty soon, if you have not done so already. The SP2 branch is still supported until November 2016, but the RTM and SP1 branches are no longer supported.

Here are links to the Microsoft CU lists for both current Service Packs.

SQL Server 2012 SP2 build versions

SQL Server 2012 SP3 build versions

SQL Server Diagnostic Information Queries for March 2016

This month, I have one new query in the SQL Server 2016 set, along with additional comments and documentation in the SQL Server 2012, 2014 and 2016 sets.

Rather than having a separate blog post for each version, I have just put the links for all six major versions in this single post. There are two separate links for each version. The first one on the top left is the actual diagnostic query script, and the one below on the right is the matching blank results spreadsheet, with labeled tabs that correspond to each query in the set. 

Here are links to the latest versions of these queries for SQL Server 2016, 2014 and 2012:

SQL Server 2016 Diagnostic Information Queries (March 2016)

SQL Server 2016 Blank Results

SQL Server 2014 Diagnostic Information Queries (March 2016)

SQL Server 2014 Blank Results

SQL Server 2012 Diagnostic Information Queries (March 2016)

SQL Server 2012 Blank Results

Here are links to the most recent versions of these scripts for SQL Server 2008 R2 and older:

Since SQL Server 2008 R2 and older are out of Mainstream support from Microsoft (and because fewer of my customers are using these old versions of SQL Server), I am not going to be updating the scripts for these older versions of SQL Server every single month going forward.  I started this policy a while ago, and so far, I have not heard any complaints. I did update these queries slightly in January 2016 though.

SQL Server 2008 R2 Diagnostic Information Queries (CY 2016)

SQL Server 2008 R2 Blank Results

SQL Server 2008 Diagnostic Information Queries (CY 2016)

SQL Server 2008 Blank Results

SQL Server 2005 Diagnostic Information Queries (CY 2016)

SQL Server 2005 Blank Results

The basic instructions for using these queries is that you should run each query in the set, one at a time (after reading the directions for that query). It is not really a good idea to simply run the entire batch in one shot, especially the first time you run these queries on a particular server, since some of these queries can take some time to run, depending on your workload and hardware. I also think it is very helpful to run each query, look at the results (and my comments on how to interpret the results) and think about the emerging picture of what is happening on your server as you go through the complete set. I have some comments in the script on how to interpret the results after each query.

You need to click on the top left square of the results grid in SQL Server Management Studio (SSMS) to select all of the results, and then right-click and select “Copy with Headers” to copy all of the results, including the column headers to the Windows clipboard. Then you paste the results into the matching tab in the blank results spreadsheet.

About half of the queries are instance specific and about half are database specific, so you will want to make sure you are connected to a database that you are concerned about instead of the master system database. Running the database-specific queries while being connected to the master database is a very common mistake that I see people making when they run these queries.

Note: These queries are stored on Dropbox. I occasionally get reports that the links to the queries and blank results spreadsheets do not work, which is most likely because Dropbox is blocked wherever people are trying to connect.

I also occasionally get reports that some of the queries simply don’t work. This usually turns out to be an issue where people have some of their user databases in 80 compatibility mode, which breaks many DMV queries, or that someone is running an incorrect version of the script for their version of SQL Server.

It is very important that you are running the correct version of the script that matches the major version of SQL Server that you are running. There is an initial query in each script that tries to confirm that you are using the correct version of the script for your version of SQL Server. If you are not using the correct version of these queries for your version of SQL Server, some of the queries are not going to work correctly.

If you want to understand how to better run and interpret these queries, you should consider listening to my three latest Pluralsight courses, which are SQL Server 2014 DMV Diagnostic Queries – Part 1SQL Server 2014 DMV Diagnostic Queries – Part 2 and SQL Server 2014 DMV Diagnostic Queries – Part 3. All three of these courses are pretty short and to the point, at 67, 77, and 68 minutes respectively. Listening to these three courses is really the best way to thank me for maintaining and improving these scripts…

You can also come listen to me discuss these queries in great detail, over the course of over three hours by coming to SQLintersection Spring 2016 – Orlando, FL – April 16-22, 2016, which will be a lot of fun!

Please let me know what you think of these queries, and whether you have any suggestions for improvements. Thanks

New TPC-H Benchmarks Comparing SQL Server 2016 to SQL Server 2014

There are two new TPC-H benchmark submissions on SQL Server 2016. This is interesting, because one of these new submissions (from March 9, 2016) is from Lenovo, for a System x3850 X6 running on SQL Server 2016. Lenovo has a previous submission, from May 1, 2015, for an identical model system running on SQL Server 2014. Both systems are running on Windows Server 2012 R2 Standard Edition. Both of these submissions are for 3000GB databases, which is very important when you are comparing score results.

So here are the results:

SQL Server 2016               969,504 QphH@3000GB

SQL Server 2014               700,392 QphH@3000GB

This shows a 38.4% score increase on identical hardware, which is quite impressive.

Both of these systems have four Intel Xeon E7-8890 v3 (Haswell-EX) 18-core processors, and 3 TB of RAM. Both systems have Intel HT enabled. Diving into the full-disclosure report for each submission, the storage subsystem for each of these submissions is virtually identical. For both systems, the storage is mostly flash-based, with a combination of internal drives and PCIe add-in cards (AIC). No SAN used here!

The key point is that they stored their six data files and their tempdb files across six, independent 3.2 TB PCIe flash AICs, which they describe as “3200GB Enterprise Value io3 Flash Adapter”. I believe that these must be SanDisk Fusion-io Memory SX350-3200 devices. Lenovo also describes the storage subsystem like this in the full-disclosure report:

The OS was stored on a RAID-1 protected array of 2 physical drives. The database files were
stored on 6 non-raided Enterprise io3 Flash drives. The log was stored on a 4-disk Raid10 array.

One thing I noticed was some minor inconsistencies between the Executive Summary and the FDR about the storage subsystem details for where the transaction log file is stored on the March 9, 2016 submission. I think this is just a copy/paste error, and log file performance is not important for this type of benchmark anyway.

Microsoft has been publishing a series of blog posts that outline some of the performance and scalability improvements in SQL Server 2016 on the CSS Engineers blog.

SQL Server Countdown

Microsoft is putting out some silly, but funny videos to promote their Data Driven Event on March 10, 2016 at 10AM EST. The very short videos have a collection of well-known Microsoft employees, and other SQL Server notables, such as our own Kimberly Tripp, being “blown away” as Microsoft SQL Server 2016 goes supersonic.

You can sign up to get additional information about the event here.

Here are the individual videos that have been released so far:

Jos de Bruijn, Senior Program Manager

Rama Raman, Senior Software Engineer

Kimberly Tripp, SQL Server MVP

Matthew Roche, Senior Program Editor 

Lindsey Allen, Principal PM Manager

Argenis Fernandez, SQL Server MVP, MCM

Tobias Ternstrom, Principal PM Manager

Scott Guthrie, Executive VP, Cloud and Enterprise

Shawn Bice, Director, Database Systems

Using ALTER DATABASE SCOPED CONFIGURATION in SQL Server 2016

On March 7, 2016, Microsoft announced the availability of the RC0 Build of SQL Server 2016. One of the new features in the RC0 Build is Database Scoped Configurations, which gives you the ability to easily make several database-level configuration changes for things that were previously configured at the instance-level.

These include:

    • Setting MAXDOP for an individual database
    • Setting the query optimizer cardinality estimation model for an individual database (independent of the database compatibility level)
    • Enable or disable parameter sniffing for an individual database
    • Enable or disable query optimization hotfixes for an individual database (equivalent to TF 4199)
    • The ability to clear the plan cache for an individual database (without using a DBCC command)

If you are using AlwaysOn Availability Groups, the first four commands can also be used to affect the database-level configuration setting for ALL of the secondary database copies that are in a AG. You can set these values for just the Primary database, set the values in the secondary database(s) to the same value as the Primary database, or set the values in the secondary database(s) to different values from the Primary database.

There is also a new DMV, sys.database_scoped_configurations, which lets you see the configuration values for the current database, including the values for the Primary database and the secondary databases (if that database is part of an AlwaysOn AG). I have examples of these commands in the code in Figure 1.

   1: -- Database scoped T-SQL Commands in SQL Server 2016 RC0

   2: -- Glenn Berry

   3: -- SQLskills.com

   4:  

   5:  

   6:  

   7: -- Get database scoped configuration values for current database 

   8: SELECT configuration_id, name, [value] AS [value_for_primary], value_for_secondary

   9: FROM sys.database_scoped_configurations WITH (NOLOCK) OPTION (RECOMPILE);

  10:  

  11: -- ALTER DATABASE SCOPED CONFIGURATION (Transact-SQL)

  12: -- https://msdn.microsoft.com/en-us/library/mt629158.aspx

  13:  

  14: -- The commands for the secondary database affect ALL secondary databases in an AlwaysOn AG

  15:  

  16: USE [CHECKDBTest]

  17: GO

  18:  

  19: -- Enable legacy Cardinality Estimation for Primary database

  20: -- Equivalent to using TF 4136, except this is only for this database

  21: ALTER DATABASE SCOPED CONFIGURATION 

  22: SET LEGACY_CARDINALITY_ESTIMATION = ON;

  23: GO

  24:  

  25: -- Enable legacy Cardinality Estimation for Secondary database

  26: ALTER DATABASE SCOPED CONFIGURATION FOR SECONDARY 

  27: SET LEGACY_CARDINALITY_ESTIMATION = ON;

  28: GO

  29:  

  30: -- Set legacy Cardinality Estimation for the Secondary database(s) to the same value as the Primary database

  31: -- This is the default setting

  32: ALTER DATABASE SCOPED CONFIGURATION FOR SECONDARY 

  33: SET LEGACY_CARDINALITY_ESTIMATION = PRIMARY;

  34: GO

  35:  

  36:  

  37:  

  38: -- Disable parameter sniffing for Primary database

  39: ALTER DATABASE SCOPED CONFIGURATION SET PARAMETER_SNIFFING = OFF;

  40: GO

  41:  

  42: -- Disable parameter sniffing for Secondary database

  43: ALTER DATABASE SCOPED CONFIGURATION FOR SECONDARY SET PARAMETER_SNIFFING = OFF;

  44: GO

  45:  

  46: -- Set parameter sniffing for the Secondary database(s) to the same value as the Primary database

  47: -- This is the default setting

  48: ALTER DATABASE SCOPED CONFIGURATION FOR SECONDARY    

  49: SET PARAMETER_SNIFFING = PRIMARY;

  50: GO

  51:  

  52:  

  53:  

  54: -- Enable query optimizer fixes for Primary database

  55: -- Equivalent to using TF 4199, except this is only for this database

  56: ALTER DATABASE SCOPED CONFIGURATION 

  57: SET QUERY_OPTIMIZER_HOTFIXES = ON;

  58: GO

  59:  

  60: -- Enable query optimizer fixes for Secondary database

  61: ALTER DATABASE SCOPED CONFIGURATION FOR SECONDARY 

  62: SET QUERY_OPTIMIZER_HOTFIXES = ON;

  63: GO

  64:  

  65:  

  66: -- Set MAXDOP for Primary database

  67: ALTER DATABASE SCOPED CONFIGURATION 

  68: SET MAXDOP = 4;

  69: GO

  70:  

  71: -- Set MAXDOP for Secondary database(s)

  72: ALTER DATABASE SCOPED CONFIGURATION FOR SECONDARY 

  73: SET MAXDOP = 4;

  74: GO

  75:  

  76: -- Set MAXDOP for the Secondary database(s) to the same value as the Primary database

  77: -- This is the default setting

  78: ALTER DATABASE SCOPED CONFIGURATION FOR SECONDARY 

  79: SET MAXDOP = PRIMARY; 

  80:  

  81:  

  82: -- Clear plan cache for current database (only possible for Primary database)

  83: ALTER DATABASE SCOPED CONFIGURATION CLEAR PROCEDURE_CACHE;

  84: GO

Figure 1: Example Database Scoped Configuration Commands in SQL Server 2016

 

 

 

Countdown to DEVintersection/SQLintersection in Orlando

As I have recently posted, I will be presenting three regular sessions and a full-day workshop at the DEVintersection/SQLintersection conference in Orlando, FL on April 16-22, 2016. As the conference get’s closer, I am starting to get more excited about it, reminding me of how I used to feel in my younger days as a developer and DBA. Getting away from work for a few days and being able to focus completely on something you are passionate about, surrounded by many like-minded people has always been a good way to recharge my motivation.

Richard Campbell of DotNetRocks and RunAsRadio has been recording some DEVintersection/SQLintersection “countdown” sessions on Channel 9, and the first five are available from the links below:

Watching short videos like this helps build and maintain the enthusiasm while I wait for the conference! The Doug Seven video is particularly good, prompting me to order an Adafruit Microsoft Internet of Things Pack for Raspberry Pi 2 kit just now…

SQL_Spr16_300x250_v5

You can register for the conference and additional workshops here. If you register by March 21, 2016, you will get (depending on which package you sign up for), your choice of a Microsoft Band 2, a $200.00 hotel gift card, a Microsoft Surface 3, or a Microsoft XBOX One. You can also get a $50.00 discount on your registration if you the use the discount code “BERRY” when you sign up.