1. THE IMPORTANCE OF A SQL SERVER HEALTH CHECK
One of the first things you should do
with a new or unfamiliar database server is collect as much information
as possible about that server — from the details of the hardware and
storage subsystem, to the operating system, up to the SQL Server
instance itself. You need to know what you are dealing with — whether
it is a poorly configured, “ancient” server with a completely
inadequate storage subsystem, or, hopefully something much better. This
information is a critical starting point for focusing your efforts to
properly manage and optimize your database servers. As a database
professional, there is really no excuse for not knowing the hardware
and configuration details about each of your database servers.
One roadblock that many database administrators
face in collecting this type of information is the bureaucracy within
their company or organization. Quite often, someone else in a different
department is in charge of provisioning and managing the actual
database server hardware and operating system on the database servers.
This person is usually a system administrator or system engineer. In
larger organizations, a SAN administrator is often in charge of the
storage subsystems. These other people, who often have different
priorities than you, and usually have relatively little knowledge of
SQL Server, can be big obstacles in your quest to gather important
information about your database servers. They may view your
information-gathering efforts as an unwelcome invasion of their
territory and area of expertise, and thus may be reluctant to cooperate
with you.
I have often asked other DBAs to tell me about
how a particular database server is configured and what type of
hardware and storage it is using, only to get vague and nearly useless
answers that will not enable evaluation of a server or solve a
performance problem. Many DBAs are not allowed to actually log on to
the desktop of their database servers, and are completely at the mercy
of their system administrator and SAN administrator for all server and
storage configuration and management. Because of this, many DBAs are
completely in the dark about anything they cannot easily see from SQL
Server Management Studio (SSMS), and they have very little information
about the details of their server hardware and storage subsystems. I
think this type of organizational policy is a huge mistake, as it
greatly hinders the overall effectiveness of database administrators.
If you are faced with this type of situation as a DBA, you should make
every effort to properly improve the matter by reaching out to your
counterparts in other departments to explain what needs to be done and
why it is important. Policies can often be changed, so don’t just
accept the situation!
However, regardless of any bureaucratic or
organizational obstacles in your way, you can still use techniques from
within SQL Server Management Studio (SSMS) to gather most of what you
need to do a relatively comprehensive SQL Server health check. One of
the most useful and easy to use techniques is to run a standard set of
dynamic management view (DMV) and dynamic management function (DMF)
queries to gather health-check information about your servers,
instances, and databases.
2. RUNNING DMV AND DMF QUERIES
Since they were first introduced in SQL
Server 2005, DMVs and DMFs have been useful tools for easily gathering
a wealth of valuable information about your hardware, a SQL Server
instance, or individual databases in an instance. With each new version
of SQL Server, enhancements have been made to these DMVs and DMFs that
increase their utility. SQL Server 2012 is no exception, and offers a
number of completely new DMVs and DMFs that you can take advantage of
during a SQL Server health check.
This set of queries is designed to be run on SQL
Server 2012. Most of the queries will also work on SQL Server 2008 R2
Service Pack 1 or later, but some will not because Microsoft made a few
late-breaking changes to some DMVs in SQL Server 2012. Some of the
queries will also run on SQL Server 2005, SQL Server 2008, and pre-SP1
builds of SQL Server 2008 R2; but the older your version of SQL Server,
the fewer of these queries are going to work for you.
In order to run most DMV and DMF queries, you
need the VIEW SERVER STATE permission on your SQL Server instance. You
will already have this permission if you have system administrator
rights within a SQL Server instance, but you should probably create a
dedicated login and matching user that has VIEW SERVER STATE permission
for use by non-administrators or monitoring applications. Once you have
the rights to run DMV and DMF queries, you are ready to get started.
I strongly recommend that you run each of the
queries in the following sections one at a time, after reading the
background and instructions first. After you get the results of each
query, take a few moments to peruse them to ensure that they make
sense. Check the notes about how to interpret the results, and consider
what you are seeing and whether the results seem to reinforce or
contradict other results and metrics that you may have gathered. It’s a
good idea to save the results of these queries in individual, labeled
tabs in a spreadsheet so that you have a baseline and a record of the
changing results over time.
For these server- and instance-level queries, it
does not really matter to which database on the instance you are
connected. Once you reach the database-specific queries starting at
Listing 15-32, don’t forget to change your database context to the
particular database you are interested in. This may seem obvious, but I
have seen many people run an entire set of database-specific queries
while they are still pointed at the master database. This will give you
a wealth of useless information about the master database!
First, you want to find out exactly what version,
edition, and build of SQL Server you have running on your instance of
SQL Server. You also want to know whether it is x64 or x86 and what
operating system you are running on. One very simple, non-DMV query,
shown in Listing 1, gives you all that information, including the compile date and time of your SQL Server build.
LISTING 1: SQL Server and operating system information
-- SQL and OS Version information for current instance
SELECT @@VERSION AS [SQL Server and OS Version Info];
-- SQL Server 2012 Builds
-- Build Description
-- 11.00.1055 CTP0
-- 11.00.1103 CTP1
-- 11.00.1540 CTP3
-- 11.00.1515 CTP3 plus Test Update
-- 11.00.1750 RC0
-- 11.00.1913 RC1
-- 11.00.2300 RTM
-- 11.00.2316 RTM CU1
-- 11.00.2325 RTM CU2
-- 11.00.2809 SP1 CTP3 (un-supported in production)
A sample of the results you will get from the preceding query is shown in Listing 2.
LISTING 2: SQL Server and operating system results
Microsoft SQL Server 2012 RC0 - 11.0.1750.32 (X64) Nov 4 2011 17:54:22 Copyright
(c) Microsoft Corporation Enterprise Evaluation Edition (64-bit) on Windows NT 6.1
<X64> (Build 7601: Service Pack 1)
This set of results tells you that you
are using the x64 Enterprise Evaluation Edition of SQL Server 2012
Release Candidate 0 (RC0), build 1750 running on x64 Windows NT 6.1
Service Pack 1 (which could be either Windows Server 2008 R2 SP1 or
Windows 7 SP1). For a production SQL Server instance, you would want to
be running Windows Server 2008 R2 or Windows Server 2012, which are x64
only, rather than on Windows 7. Knowing the version, edition, and build
of your SQL Server instance helps you determine what features are
available within SQL Server. For example, data compression is available
only in Enterprise Edition, so if you have Standard Edition or Business
Intelligence Edition of SQL Server 2012, you cannot use data
compression.