DBA Diaries

Thoughts and experiences of a DBA working with SQL Server and MySQL

Andy Hayes is a DBA working with SQL Server since version 7.0. He has a wonderful wife and two beautiful children. He loves database technology, playing cricket, and blogging. He is passionate about sharing his experiences as a DBA and learning more to further his understanding and knowledge. You can follow me on Twitter, check out my Facebook page or follow me on Google+

SQL Server 2016 – What Are The New Features?

Posted on May 17, 2016 Written by Andy Hayes Leave a Comment

SQL Server 2016 New FeaturesSQL Server 2016 will be made available to purchase by the public on 1st June 2016 and if we compare this schedule with Microsoft’s plans of a major release every 2 years, this one comes 26 months after SQL Server 2014 which arrived on 1st April 2014.

So will the list of new features in SQL Server 2016 persuade businesses to upgrade?

This list is by no means complete and so I think I’ll be updating this list as I discover them.

As SQL Server will come in different versions, typically the more businesses are prepared to pay, the richer the feature set available.

  • Always Encrypted – as it says on the tin, the data is always encrypted. This means that access to encrypted data will only be available to the application using SQL Server. The client application has the encryption key and this is never passed to SQL Server.
  • Query Store – in older versions of SQL Server, query plans can be examined using DMV’s which interrogate the plan cache. Once the plans exit the cache, they are no longer visible for comparison anywhere. The query store provides a way to store older versions of execution plans allowing comparisons between old and new to be made. A nice one for those wanting to check performance of plans over time.
  • Live Query Statistics – allows the execution plan to be viewed live as the query is executing – nice!
  • Dynamic Data Masking – when switched on, this feature controls what data is masked from view to users who are not allowed to view it. For example confidential columns may be obscured from view to a group of unauthorized users but the other columns would be visible. Parts of columns may also be obscured from view.
  • Multiple TempDB Files – adding additional tempdb files is not a new feature as such and has been good practice to implement on multi-core machines. What has been added is the ability to do this upon installation of SQL Server.
  • Polybase – allows the querying of Hadoop or Azure blob storage data sets using T-SQL. It’s possible to write queries which join the relational data in SQL Server with the semi-structured data in Hadoop.
  • Row Level Security – access to row data can be restricted based on specified SQL logins. This will be done by filter predicates defined inside of inline table value functions. Security policies will ensure that the filters are executed.
  • R Support – this feature enables data scientists to run R code directly against the SQL Server. Data will no longer need to be exported separately to facilitate these kind of analytic operations.
  • Stretch Database – allows on premise databases to be extended into the cloud. Frequently used data would be stored on premise with older data stored offsite in an Azure database inside the cloud. A question one might ask is what if the on-premise location’s internet link goes down? Only a feature for organizations with good communications redundancy perhaps?
  • JSON Support – MySQL’s doing it in the latest 5.7 release, Postgres has been doing it for years, Oracle’s doing it and it’s coming soon in MariaDB. Relational database products are adapting to include support for JSON and SQL Server has joined the party. JSON data can be parsed and stored in relational format. Functions are included which allow for JSON to be queried and output results from queries can also be formatted as JSON.
  • Temporal Tables – helps to facilitate automatic row versioning. Every time a row is updated in the base table, a copy of the older version is made inside the temporal table. The temporal table is physical object inside of the database. It is separate to but linked to the base table.
  • Backup to Azure – on premise backups can be made to Azure blob storage.
  • Managed Backup – this is automated managed backup of your on-premise backups to Azure.

Improvements to existing features in SQL Server

“There is always room for improvement” and existing features have been enriched in places too. What I have been able to ascertain so far is is that there are improvements made to Columnstore Indexes, AlwaysOn and In-Memory OLTP. I’m sure I’ll discover more as I delve deeper.

A worthy release?

It certainly would appear that there are more features than what was included in SQL Server 2014 and if businesses were thinking of upgrading then this version would be well worth considering.

As ever, those decisions will be based around cost and requirements. There will still be businesses running on older versions of SQL Server no longer supported (2005 support finished ended as of April 12th 2016) and they are quite happy to do so because those versions do the job just fine.

For those businesses requiring a supported version, increased performance and some or all of the newer features but have been delaying upgrading, this release may be enough to persuade them to now move forward.

Filed Under: All Articles, SQL Server News Tagged With: sql server, sql server 2016

How to Find I/O Usage Per Database in SQL Server

Posted on May 15, 2016 Written by Andy Hayes 3 Comments

If you’re looking at performance and trying to understand I/O on a per database level in SQL Server, sadly there is not a report in Management Studio that you can run from those available.

It will need some T-SQL to pull out this information from an existing DMV – sys.dm_io_virtual_file_stats.

The information returned by the DMV is data which has been recorded since the SQL Server was last restarted and so it is therefore cumulative data.

It helps the DBA to understand where the I/O distribution is across databases at both the data and log file level.

Let’s take a look at I/O at the database level using this T-SQL:

WITH IO_Per_DB
AS
(SELECT 
  DB_NAME(database_id) AS Db
  , CONVERT(DECIMAL(12,2), SUM(num_of_bytes_read + num_of_bytes_written) / 1024 / 1024) AS TotalMb
 FROM sys.dm_io_virtual_file_stats(NULL, NULL) dmivfs
 GROUP BY database_id)

 SELECT 
    Db
    ,TotalMb
    ,CAST(TotalMb / SUM(TotalMb) OVER() * 100 AS DECIMAL(5,2)) AS [I/O]
FROM IO_Per_DB
ORDER BY [I/O] DESC;

On my test instance this produces the following output:

find io usage per database in sql server

I can see that the top I/O consumer is the sample MS database AdventureWorks and this is because I’ve been running some simple SELECT’s against the tables. If I start running queries against the others, the distribution will quickly change so it’s important not to assume anything about the results without regular sampling.

Take some scenario where workload patterns are constant across the day and the results do not change much. Then in the evening some large job runs which reads a lot of data from a database which is otherwise not very active during the day. At that time of the day, that database may show up at the top of the report having generated a lot of I/O. However after this time, normal workloads would resume and the results will change again.

Looking at I/O usage at the database file level in SQL Server

The results above are very high level. If you want to look in more detail, for example at the data file level, you can run something like this:

WITH IO_Per_DB_Per_File
AS
(SELECT 
    DB_NAME(dmivfs.database_id) AS Db
  , CONVERT(DECIMAL(12,2), SUM(num_of_bytes_read + num_of_bytes_written) / 1024 / 1024) AS TotalMb
  , CONVERT(DECIMAL(12,2), SUM(num_of_bytes_read) / 1024 / 1024) AS TotalMbRead
  , CONVERT(DECIMAL(12,2), SUM(num_of_bytes_written) / 1024 / 1024) AS TotalMbWritten
  , CASE WHEN dmmf.type_desc = 'ROWS' THEN 'Data File' WHEN dmmf.type_desc = 'LOG' THEN 'Log File' END AS DataFileOrLogFile
 FROM sys.dm_io_virtual_file_stats(NULL, NULL) dmivfs
 JOIN sys.master_files dmmf ON dmivfs.file_id = dmmf.file_id AND dmivfs.database_id = dmmf.database_id
 GROUP BY dmivfs.database_id, dmmf.type_desc)

 SELECT 
    Db
  , TotalMb
  , TotalMbRead
  , TotalMbWritten
  , DataFileOrLogFile
  , CAST(TotalMb / SUM(TotalMb) OVER() * 100 AS DECIMAL(5,2)) AS [I/O]
FROM IO_Per_DB_Per_File
ORDER BY [I/O] DESC;

I’ve included some extra columns here to help display the megabytes read and written as well as the data file the I/O was generated against.

In the following results, I ran an update against one of the larger tables to help demonstrate. You can see the log file for the AdventureWorks db saw some activity and the distribution of I/O is now more transparent.

find io usage per database per data file in sql server

Filed Under: All Articles, SQL Server Performance Tagged With: performance, sql server

How to Get SQL Server Developer Edition for Free

Posted on May 14, 2016 Written by Andy Hayes Leave a Comment

sql server developer edition is freeSQL Server Developer Edition – whether you are wanting to learn the product at home to advance your career or you need a copy for your enterprise to test and develop on, it’s historically been a good investment for relatively little cost.

Personally for home use, I have always downloaded the evaluation versions of SQL Server that expire after 6 months. That’s kind of annoying as after that time, you need to either activate the installation with a purchased licence key or reinstall the product. I’ve preferred to do this because for personal use, I have still been reluctant to spend the money on the development version. The hassle of backing up anything I have done and re-installing has been better for me than spending the money.

The good news is that this has changed as Microsoft have announced that SQL Server Developer Edition is now free to download. I think this is only a good thing for increasing the adoption of SQL Server.

You need to register to Visual Studio Dev Essentials to get access to this download. It is also free to register. 🙂

In my opinion Microsoft appears to be making a number of good strategic decisions of late (Visual Studio Community, SQL Server on Linux, .NET on Linux etc) and this move is consistent with their apparent direction of making their products more accessible and compatible on systems which are not running a form of the Windows operating system.

For more information on this topic, check out this official post from Microsoft.

Filed Under: All Articles, SQL Server News Tagged With: sql server, sql server 2016

How to List CPU Usage Per Database in SQL Server

Posted on May 14, 2016 Written by Andy Hayes 2 Comments

As a DBA there may be a time when you want to try and ascertain how much CPU time each of your databases is consuming. This is useful to complement high CPU investigations or to just try and understand which of your databases overall is the highest CPU consumer over time.

The out of the box reporting that Management Studio provides is sadly missing this report so we have to run some T-SQL to extract it.

As with other DMV’s, the statistics produced are only available from the time when the SQL Server was started and can change over the course of the day. It’s important to remember that these are cumulative figures and may not correlate to any current spike in CPU performance caused by some heavy query.

The DMV can only report on the data that is available in the plan cache. If the plan cache is experiencing lots of churn, the report becomes less accurate.

If you want to track this data over time, you will need to capture data at regular intervals and persist it to some kind of logging table or file.

So here is some code to do it:

WITH CPU_Per_Db
AS
(SELECT 
 dmpa.DatabaseID
 , DB_Name(dmpa.DatabaseID) AS [Database]
 , SUM(dmqs.total_worker_time) AS CPUTimeAsMS
 FROM sys.dm_exec_query_stats dmqs 
 CROSS APPLY 
 (SELECT 
 CONVERT(INT, value) AS [DatabaseID] 
 FROM sys.dm_exec_plan_attributes(dmqs.plan_handle)
 WHERE attribute = N'dbid') dmpa
 GROUP BY dmpa.DatabaseID)
 
 SELECT 
 [Database] 
 ,[CPUTimeAsMS] 
 ,CAST([CPUTimeAsMS] * 1.0 / SUM([CPUTimeAsMS]) OVER() * 100.0 AS DECIMAL(5, 2)) AS [CPUTimeAs{96f5cbaad583fb885ff5d18ecce5734bf1e8596949521e20c290401929518f75}]
 FROM CPU_Per_Db
 ORDER BY [CPUTimeAsMS] DESC;

This is what the results looks like on my test instance.

find cpu usage per database in sql server

I hope you found this useful 🙂

Filed Under: All Articles, SQL Server Performance Tagged With: performance, sql server

  • « Previous Page
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • …
  • 22
  • Next Page »

Categories

  • All Articles (82)
  • Career Development (8)
  • MySQL Administration (18)
  • MySQL Performance (2)
  • SQL Server Administration (24)
  • SQL Server News (3)
  • SQL Server Performance (14)
  • SQL Server Security (3)
  • SQL Tips and Tricks (19)

Top 10 Popular Posts

  • Using sp_change_users_login to fix SQL Server orphaned users
  • How to shrink tempdb
  • MySQL SHOW USERS? – How to List All MySQL Users and Privileges
  • How to Transfer Logins to Another SQL Server or Instance
  • How to Delete Millions of Rows using T-SQL with Reduced Impact
  • T-SQL – How to Select Top N Rows for Each Group Using ROW_NUMBER()
  • New T-SQL features in SQL Server 2012 – OFFSET and FETCH
  • How to Kill All MySQL Processes For a Specific User
  • Using exec sp_who2 to help with SQL Server troubleshooting
  • How to move tempdb

Recent Posts

  • How to Setup MySQL Master Master Replication
  • How To Use SQL to Convert a STRING to an INT
  • How to set up MySQL Replication Tutorial
  • How to Use SQL CASE for Conditional Logic in Your SQL Queries
  • Using ISNULL in SQL Server to Replace NULL Values

Search

Connect

  • Twitter
  • Facebook
  • Google+
  • RSS

About

  • Cookie Policy
  • Disclaimer
  • About
Copyright © ‘2021’ DBA Diaries built on the Genesis Framework

This site uses cookies. We assume you are happy with cookies but click the link if you are not. Close