3. SQL SERVER BUILDS
Microsoft periodically (currently,
every eight weeks) releases a cumulative update (CU) for SQL Server.
Each update is a collection of typically 10–40 hotfixes for SQL Server
that is released as an integrated setup package. About every 12–18
months, Microsoft releases a service pack for a particular major
version of SQL Server, such as SQL Server 2012. When a SQL Server
service pack is released, it means that you have a new release branch
of that major version of SQL Server, which has its own separate
cumulative updates. You need to know what release branch your SQL
Server instance is on, so that you know which cumulative update to
download and install.
Knowing the build number and compile date and
time for your instance tells you how old your SQL Server instance is,
which is very important. Microsoft originally releases a new major
version of SQL Server as the release to manufacturing (RTM) build, which is what you get from a DVD or .iso
image of the product. Many organizations install the RTM build of a
major version SQL Server, but never update their SQL Server instances
to a newer build, which I think is a huge mistake. I firmly believe
that you should make a concerted effort to keep your SQL Server
instances up to date with the most current service packs and cumulative
updates.
For example, if you installed a new instance of SQL Server 2008 R2 from an .iso
image that you downloaded from Microsoft, you would have Build 1600, in
the RTM branch. If you then installed SQL Server 2008 R2 SP1, you would
have Build 2500, in the Service Pack 1 branch. Any further cumulative
updates on this instance would have to be from the Service Pack 1
branch until you moved to a later service pack for SQL Server 2008 R2.
This discussion is important for several reasons.
First, if you are running on a very old build of a major version of SQL
Server, you are much more likely to encounter defects that have been
fixed in newer builds of that version, which makes your life as a DBA
more difficult. Second, Microsoft eventually retires older release
branches (usually one year after the next service pack is released). If
you are on a retired release branch, there will be no more cumulative
updates for that release branch; and if you ever have to call Microsoft
CSS to open a support case, you will receive only limited
troubleshooting support until you get on a release branch that is still
fully supported. Don’t let this happen to you!
Making the effort to watch for SQL Server service
packs and cumulative updates, checking the fix list, downloading them,
testing them, and deploying them in your production environment is a
beneficial exercise for you and your organization. Deploying these
updates using a planned, rolling upgrade strategy enables you to
complete the deployments with minimal service interruptions, and it
forces you to exercise some of your high-availability (HA),
disaster-recovery (DR) infrastructure while keeping your servers up to
date. I think this is much better than being a DBA who is overly
hesitant to apply any SQL Server updates because you are afraid you
might break something.
The next query you want to run, shown in Listing 3, will give you a little more information about your operating system on the database server, including the language.
LISTING 3: Windows information
-- Windows information (SQL Server 2012)
SELECT windows_release, windows_service_pack_level,
windows_sku, os_language_version
FROM sys.dm_os_windows_info WITH (NOLOCK) OPTION (RECOMPILE);
-- Gives you major OS version, Service Pack, Edition,
-- and language info for the operating system
The preceding query simply gives you a little
more specific information about the operating system, in a form that is
easier to filter and parse than what you get from SELECT @@VERSION. Now that you know more about your operating system, you can start to gather some hardware information.
The query shown in Listing 4
indicates how many logical processors you have, the hyperthread ratio
of the processors, how many physical CPUs you have, and how much
physical memory you have in your database server. It also indicates
whether you are running in a virtual machine and when SQL Server was
last started. Unfortunately, the hyperthread ratio does not distinguish
between logical and physical cores in each physical processor. For
example, the laptop used to write this article on is a dual-core
processor with hyperthreading, and the hyperthread ratio is 4. If my
laptop were a quad-core without hyperthreading, my hyperthread ratio
would also be 4. Especially with the new, core-based licensing in SQL
Server 2012 Enterprise Edition, it is important to distinguish between
true physical cores and logical cores. Fortunately, the next two
queries will help clear up this confusion.
LISTING 4: Hardware information
-- Hardware information from SQL Server 2012 (new virtual_machine_type_desc)
-- (Cannot distinguish between HT and multi-core)
SELECT cpu_count AS [Logical CPU Count], hyperthread_ratio AS [Hyperthread
Ratio],cpu_count/hyperthread_ratio AS [Physical CPU Count],
physical_memory_kb/1024 AS [Physical Memory (MB)],
affinity_type_desc, virtual_machine_type_desc, sqlserver_start_time
FROM sys.dm_os_sys_info WITH (NOLOCK) OPTION (RECOMPILE);
-- Gives you some good basic hardware information about your database server
The query shown next in Listing 5
simply reads the SQL Server Error Log to get the manufacturer and model
number of your database server. If you are a true hardware geek like
me, simply knowing that you have a Dell PowerEdge R710 server tells you
quite a bit by itself, without having to look anything else up.
Otherwise, you can do some research with your favorite search engine to
find out more details about your server after you know the manufacturer
and model number.
LISTING 5: Server manufacturer and model
-- Get System Manufacturer and model number from
-- SQL Server Error log. This query might take a few seconds
-- if you have not recycled your error log recently
EXEC xp_readerrorlog 0,1,"Manufacturer";
-- This can help you determine the capabilities
-- and capacities of your database server
Knowing the manufacturer and model of your
database server enables you to find out important things about it, such
as how many processor sockets it has, how many memory slots it has, and
how many and what type of PCI-E expansion slots it has. It also tells
you what type of processors (Intel or AMD), and what generation(s) of
processors, that server model supports.
Now that you know how many physical processors
and how many logical cores are visible to your database server, you
need to find out the exact model number of the processor(s) in your
database server. Once you know this, you can use your favorite search
engine to determine each processor’s exact specifications, including
how many physical cores it has, whether it supports hyperthreading,
TurboBoost, or TurboCore, how large the L2 and L3 cache is, and the
rated clock speed of the processor. The query in Listing 6 returns the processor description and the rated clock speed from the Windows Registry.
LISTING 6: Processor description
-- Get processor description from Windows Registry
EXEC xp_instance_regread
’HKEY_LOCAL_MACHINE’,
’HARDWARE\DESCRIPTION\System\CentralProcessor\0’,
’ProcessorNameString’;
-- Gives you the model number and rated clock speed of your processor(s)
It is very important to know the rated clock
speed of the processors in your database server, as it is possible that
your processors are not running at their full speed at all times due to
some form of power management. By default, Windows Server 2008 and
Windows Server 2008 R2 use the Balanced Windows Power Plan. This means
that when the processors are not under a high workload, they reduce
their clock speed to reduce their electrical power usage. This is great
for extending the battery life on laptops, and it is good for reducing
electrical power usage in desktop systems and even web servers.
Unfortunately, power management is not such a great option for database
servers. That’s because when the processor sees a sudden increase in
workload, it responds by increasing the clock speed back to full speed.
That sounds good so far, but this response to the spike in the workload
does not happen quickly enough to avoid a negative effect on query
performance. Some short duration, relatively inexpensive queries may
not even trigger the throttle-up mechanism, so they are executed while
the processor is still running at reduced speed.
In my experience, I have typically seen a 20–25%
hit to performance for OLTP workloads when using the Windows default
Balanced power plan instead of the High Performance power plan. It
depends on which processor you are using, with Intel Nehalem and
Westmere processors being
particularly vulnerable. Even with the High Performance power plan, it
is still possible that your database server is being affected by
hardware power management, controlled from the main system BIOS.
To avoid this problem, first make sure your
database servers are using the High Performance power plan, not the
Balanced power plan. This setting can be changed dynamically, with no
reboot of Windows required. Second, use CPU-Z, a free tool available
from cpuid.com
to determine the actual clock speed at which your processors are
running. If you are using the High Performance power plan and your
processor is still not running at full speed, you need to go into the
main system BIOS and change its power management settings to either OS
control, or to be disabled completely. Depending on your organization,
you may have to get your system administrator to make this change for
you, as it requires a reboot of the server to get into the main BIOS
configuration.