Query 1
SQL and OS Version information for current instance (Version Info)
select@@servername AS[server name], @@version AS [sql server and os version info]; |
-- SQL Server 2016 RTM Branch Builds
-- Build Description Release Date -- 13.0.200.172 CTP 2.0 5/26/2015 -- 13.0.300.44 CTP 2.1 6/14/2015 -- 13.0.407.1 CTP 2.2 7/28/2015 -- 13.0.500.53 CTP 2.3 9/4/2015 -- 13.0.600.65 CTP 2.4 9/30/2015 -- 13.0.700.242 CTP 3.0 10/29/2015 -- 13.0.900.73 CTP 3.2 12/12/2015 -- 13.0.1000.276 CTP 3.3 1/27/2016 -- 13.0.1100.288 RC0 3/2/2016 -- 13.0.1200.242 RC1 3/18/2016 -- 13.0.1300.275 RC2 3/28/2016 -- 13.0.1400.361 RC3 4/11/2016 -- 13.0.1601.5 RTM 6/1/2016 |
Query 2
Get socket, physical core and logical core count from the SQL Server Error log.(Core Counts)
EXEC sys.Xp_readerrorlog 0, 1, N'detected', N'socket'; |
This query might take a few seconds if you have not recycled your error log recently.This can help you determine the exact core counts used by SQL Server and whether HT is enabled or not.It can also help you confirm your SQL Server licensing model.Be on the lookout for this message "using 20 logical processors based on SQL Server licensing" which means grandfathered Server/CAL licensing.This query will return no results if your error log has been recycled since the instance was last started.
Query 3
Get selected server properties(Server Properties)
SELECT Serverproperty('machinename') AS[machinename], Serverproperty('servername') AS[servername], Serverproperty('instancename') AS [instance], Serverproperty('isclustered') AS [isclustered], Serverproperty('computernamephysicalnetbios')AS [computernamephysicalnetbios], Serverproperty('edition') AS [edition], Serverproperty('productlevel') AS[productlevel], --what servicing branch (rtm/sp/cu) Serverproperty('productupdatelevel') AS[productupdatelevel], -- within a servicing branch, what cu# is applied Serverproperty('productversion') AS[productversion], Serverproperty('productmajorversion') AS[productmajorversion], Serverproperty('productminorversion') AS [productminorversion], Serverproperty('productbuild') AS[productbuild], Serverproperty('productbuildtype') AS[productbuildtype], -- is this a gdr or od hotfix (null if on a cu build) Serverproperty('productupdatereference') AS [productupdatereference], -- kb article number that is applicable for this build Serverproperty('processid') AS [processid], Serverproperty('collation') AS [collation], Serverproperty('isfulltextinstalled') AS[isfulltextinstalled], Serverproperty('isintegratedsecurityonly') AS[isintegratedsecurityonly], Serverproperty('filestreamconfiguredlevel') AS[filestreamconfiguredlevel], Serverproperty('ishadrenabled') AS[ishadrenabled], Serverproperty('hadrmanagerstatus') AS[hadrmanagerstatus], Serverproperty('isxtpsupported') AS [isxtpsupported], Serverproperty('instancedefaultdatapath') AS[instancedefaultdatapath], Serverproperty('instancedefaultlogpath') AS[instancedefaultlogpath], Serverproperty('ispolybaseinstalled') AS[ispolybaseinstalled], --new for sql server 2016 Serverproperty('isadvancedanalyticsinstalled') AS [isrservicesinstalled], - new FOR sql server 2016 serverproperty('buildclrversion') AS [build clrversion]; |
This gives you a lot of useful information about your instance of SQL Server, such as the ProcessID for SQL Server and your collation.Note: Some columns will be NULL on older SQL Server builds.
Query 4
Get instance-level configuration values for instance(Configuration Values)
SELECT NAME, value, |
Settings:automatic
soft-NUMA disabled (should be 0 in most cases),backup checksum default (should
be 1),backup compression default (should be 1 in most cases),clr enabled (only
enable if it is needed),cost threshold for parallelism (depends on your
workload),lightweight pooling (should be zero),max degree of parallelism
(depends on your workload and hardware),max server memory (MB) (set to an
appropriate value, not the default),optimize for ad hoc workloads (should be
1),priority boost (should be zero),remote admin connections (should be 1).
New configuration options for SQL Server 2016: allow polybase export (Allow INSERT into a Hadoop external table),automatic soft-NUMA disabled (Automatic soft-NUMA is enabled by default),external scripts enabled (Allows execution of external scripts, for R Services),hadoop connectivity (Configure SQL Server to connect to external Hadoop or Microsoft Azure storage blob data sources through PolyBase),polybase network encryption (Configure SQL Server to encrypt control and data channels when using PolyBase),remote data archive (Allow the use of the REMOTE_DATA_ARCHIVE data access for Stretch databases).
Query 5
Returns a list of all global trace flags that are enabled(Global Trace Flags)
DBCC tracestatus(-1); |
If no global trace flags are enabled, no results will be returned.It is very useful to know what global trace flags are currently enabled as part of the diagnostic process.Common trace flags that should be enabled in most cases.TF 3226 - Supresses logging of successful database backup messages to the SQL Server Error Log.The behavior of TF 1117, 1118 are enabled for tempdb in SQL Server 2016 by default.The behavior of TF 2371 is enabled by default in SQL Server 2016.
Query 6
Returns status of instant file initialization(IFI Status)
EXEC sys.Xp_readerrorlog 0, |
Query 7
SQL Server Process Address space info(Process Memory)(shows whether locked
pages is enabled, among other things)
SELECT physical_memory_in_use_kb / 1024 AS [sql server memory usage (mb)], large_page_allocations_kb, |
You want to see 0 for process_physical_memory_low.You want to see 0 for
process_virtual_memory_low.This indicates that you are not under internal
memory pressure.
Query 8
SQL Server Services information(SQL Server Services Info)
SELECT servicename, process_id, |
Tells you the account
being used for the SQL Server Service and the SQL Agent Service.Shows the
process_id, when they were last started, and their current status.Shows whether
you are running on a failover cluster instance.
Query 9
Get SQL Server Agent jobs and Category information(SQL Server Agent Jobs)
SELECT sj.NAME AS [jobname], sj.[description] AS [jobdescription], |
Gives you some basic information about your SQL Server Agent jobs, who owns
them and how they are configured.Look for Agent jobs that are not owned by
sa,Look for jobs that have a notify_email_operator_id set to 0 (meaning no
operator).Look for jobs that have a notify_level_email set to 0 (meaning
no e-mail is ever sent).
Query 10
Get SQL Server Agent Alert Information(SQL Server Agent Alerts)
SELECT NAME, event_source, |
Gives you some basic information about your SQL Server Agent Alerts (which are different from SQL Server Agent jobs).
Query 11
Windows information(Windows Info)
SELECT windows_release, windows_service_pack_level, |
Gives you major OS
version, Service Pack, Edition, and language info for the operating system,6.3
is either Windows 8.1, Windows 10 or Windows Server 2012 R2, Windows Server
2016,6.2 is either Windows 8 or Windows Server 2012,6.1 is either Windows 7 or
Windows Server 2008 R2,6.0 is either Windows Vista or Windows Server 2008.
Windows SKU codes: 4 is
Enterprise Edition,7 is Standard Server Edition,8 is Datacenter Server
Edition,10 is Enterprise Server Edition,48 is Professional Edition,1033 for
os_language_version is US-English.SQL Server 2014 requires Windows Server 2012
or newer.
Query 12
SQL Server NUMA Node information(SQL Server NUMA Info)
SELECT node_id, node_state_desc, |
Gives you some useful
information about the composition and relative load on your NUMA nodes.You want
to see an equal number of schedulers on each NUMA node.Watch out if SQL Server
2016 Standard Edition has been installed on a machine with more than 16 physical
cores.
Query 13
Good basic information about OS memory amounts and state(System Memory)
SELECT total_physical_memory_kb / 1024 AS[Physical Memory (MB)], available_physical_memory_kb / 1024 AS [Available Memory (MB)], |
You want to see "Available physical memory is high" for System Memory
State.This indicates that you are not under external memory pressure.You
can skip the next three queries if you know you don't have a clustered
instance.
Query 14
Shows you where the SQL Server failover cluster diagnostic log is located and how it is configured(SQL Server Error Log)
SELECT is_enabled, [path], |
Knowing this information
is important for troubleshooting purposes.Also shows you the location of other
error and diagnostic log files.
Query 15
Get information about your cluster nodes and their status(Cluster Node
Properties)
(if your database server is in a failover cluster)
SELECT nodename, status_description, |
Knowing which node owns the cluster resources is critical.Especially when you are installing Windows or SQL Server updates.You will see no results if your instance is not clustered.
Query 16
Get information about any AlwaysOn AG cluster this instance is a part of (Query 16)(AlwaysOn AG Cluster)
SELECT cluster_name, quorum_type_desc, |
You will see no results
if your instance is not using AlwaysOn AGs.
Query 17
Hardware information from SQL Server 2016(Hardware Info)
SELECT cpu_count AS [logical cpu count], scheduler_count, |
Gives you some good
basic hardware information about your database server.Cannot distinguish
between HT and multi-core. Note: virtual_machine_type_desc of HYPERVISOR does
not automatically mean you are running SQL Server inside of a VM.It merely
indicates that you have a hypervisor running on your host.Soft NUMA
configuration is a new column for SQL Server 2016.
Query 18
Get System Manufacturer and model number from SQLServer Error log(System
Manufacturer)
EXEC sys.Xp_readerrorlog 0, |
This can help you determine the capabilities and capacities of your database
server.Can also be used to confirm if you are running in a VM.This query might
take a few seconds if you have not recycled your error l.
Query 19
Get processor description from Windows Registry(Processor Description)
EXEC sys.Xp_instance_regread n'hkey_local_machine', |
Gives you the model
number and rated clock speed of your processor(s).Your processors may be
running at less than the rated clock speed due to the Windows Power Plan or
hardware power management.
Query 20
See if buffer pool extension(BPE)is enabled(BPE Configuration)
SELECT [path], state_description, |
BPE is available in both
Standard Edition and Enterprise Edition.It is a more interesting feature for
Standard Edition.
Query 21
Look at buffer descriptors to see BPE usage by database(BPE Usage)
SELECT Db_name(database_id) AS [database name], Count(page_id) AS [page count], |
You will see no results if BPE is not enabled or if there is no BPE usage.
Query 22
Get information on location, time and size of any memory dumps from SQL Server (Memory Dump Info)
SELECT [filename], creation_time, |
This will not return any
rows if you have.Not had any memory dumps (which is a good thing).
Query 23
File names and paths for all user and system databases on instance (Database Filenames and Paths)
SELECT Db_name([database_id]) AS [database name], [file_id], |
Things to look at:Are
data files and log files on different drives? Is everything on the C: drive?Is
TempDB on dedicated drives?Is there only one TempDB data file? Are all of the
TempDB data files the same size? Are there multiple data files for user
databases?Is percent growth enabled for any files (which is bad)?
Query 24
Volume info for all LUNS that have database files on the current instance (Volume Info)
SELECT DISTINCT vs.volume_mount_point, vs.file_system_type, |
Shows you the total and
free space on the LUNs where you have database files. Being low on free space
can negatively affect performance.
Query 25
Drive level latency information(Drive Level Latency)
SELECT tab.[drive], tab.volume_mount_point AS [volume mount point], |
Shows you the
drive-level latency for reads and writes, in milliseconds. Latency above
30-40ms is usually a problem.These latency numbers include all file activity
against all SQL Server.Database file on each drive since SQL Server was last
started.
Query 26
Calculates average stalls per read, per write, and per total input/output for each database file(IO Stalls by File)
SELECT Db_name(fs.database_id) AS |
Helps determine which
database files on the entire instance have the most I/O bottlenecks.This can
help you decide whether certain LUNs are overloaded and whether you might.Want
to move some files to a different location or perhaps improve your I/O
performance.These latency numbers include all file activity against each SQL
Server.Database file since SQL Server was last started.
Query 27
Look for I/O requests taking longer than 15 seconds in the five most recent SQL Server Error Logs(IO Warnings)
CREATE TABLE #iowarningresults ( |
Finding 15 second I/O
warnings in the SQL Server Error Log is useful evidence of:poor I/O performance
(which might have many different causes).Look to see if you see any patterns in
the results (same files, same drives, same time of day, etc.)
Query 28
Recovery model, log reuse wait description, log file size, log usage size (Database Properties)and compatibility level for all databases on instance
SELECT db.[name] AS [database name], db.recovery_model_desc AS [recovery model], |
Things to look at: How
many databases are on the instance?,What recovery models are they using?,What
is the log reuse wait description?,How full are the transaction logs?, What
compatibility level are the databases on?, What is the Page Verify Option?
(should be CHECKSUM),Is Auto Update Statistics Asynchronously enabled?,Make
sure auto_shrink and auto_close are not enabled!
Query 29
Missing Indexes for all databases by Index Advantage (Missing Indexes All Databases)
SELECT CONVERT(DECIMAL(18, 2), user_seeks * avg_total_user_cost * (
avg_user_impact * 0.01 )) AS |
Getting missing index information for all of the databases on the instance is very useful.Look at last user seek time, number of user seeks to help determine source and importance.Also look at avg_user_impact and avg_total_user_cost to help determine importance.SQL Server is overly eager to add included columns, so beware.Do not just blindly add indexes that show up from this query!!!
Query 30
Get VLF Counts for all databases on the instance(VLF Counts)
CREATE TABLE #vlfinfo ( |
High VLF counts can affect write performance and they can make full database restores and crash recovery take much longer.Try to keep your VLF counts under 200 in most cases (depending on log file size).
Query 31
Get CPU utilization by database (CPU Usage by Database)
WITH db_cpu_stats Helps determine which database is using the most CPU resources on the instance. |
Query 32
Get I/O utilization by database(IO Usage By Database)
WITH aggregate_io_statistics AS (SELECT Db_name(database_id) AS [database name], |
Helps determine which
database is using the most I/O resources on the instance.
Query 33
Get total buffer usage by database for current instance(Total Buffer Usage by
Database).This make take some time to run on a busy instance.
WITH aggregatebufferpoolusage AS (SELECT Db_name(database_id) AS |
Tells you how much memory (in the buffer pool).Is being used by each database on the instance.Clear Wait Stats with this command:
DBCC sqlperf('sys.dm_os_wait_stats', clear); |
Query 34
Isolate top waits for server instance since last restart or wait statistics
clear(Top Waits)
WITH [waits] AS (SELECT wait_type, |
Cumulative wait stats
are not as useful on an idle instance that is not under load or performance
pressure.
Query 35
Get a count of SQL connections by IP address(Connection Counts by IP Address)
SELECT ec.client_net_address, es.[program_name], |
This helps you figure where your database load is coming from and verifies connectivity from other machines.
Query 36
Get Average Task Counts (run multiple times)(Avg Task Counts)
SELECT Avg(current_tasks_count) AS [avg task count], Avg(work_queue_count) AS [avg work queue count], |
Sustained values above
10 suggest further investigation in that area.High Avg Task Counts are often
caused by blocking/deadlocking or other resource contention.Sustained
values above 1suggest further investigation in that area.High Avg Runnable Task
Counts are a good sign of CPU pressure.High Avg Pending DiskIO Counts are
a sign of disk pressure.
Query 37
Detect blocking (run multiple times)(Detect Blocking)
SELECT t1.resource_type AS [lock type], Db_name(resource_database_id) AS [database], |
Helps troubleshoot
blocking and deadlocking issues.The results will change from second to second
on a busy system.You should run this query multiple times when you see signs of
blocking.
Query 38
Get CPU Utilization History for last 256 minutesm (in one minute intervals)
(CPU Utilization History)This version works with SQL Server 2016
DECLARE @ts_now BIGINT = (SELECT cpu_ticks / ( cpu_ticks / ms_ticks ) FROM sys.dm_os_sys_info WITH (nolock)); |
Look at the trend over the entire period.Also look at high sustained Other
Process CPU Utilization values.
Query 39
Get top total worker time queries for entire instance (Top Worker Time Queries)
SELECT TOP(50) |
Helps you find the most expensive queries from a CPU perspective across the
entire instance.Can also help track down parameter sniffing issues.
Query 40
Page Life Expectancy (PLE) value for each NUMA node in current instance(PLE by NUMA Node)
SELECT @@servername AS [server name], [object_name], |
PLE is a good
measurement of memory pressure.Higher PLE is better. Watch the trend over time,
not the absolute value.This will only return one row for non-NUMA systems.
Query 41
Memory Grants Pending value for current instance(Memory Grants Pending)
SELECT @@servername AS [server name], [object_name], |
Run multiple times, and run periodically is you suspect you are under memory pressure.Memory Grants Pending above zero for a sustained period is a very strong indicator of internal memory pressure.
Query 42
Memory Clerk Usage for instance(Memory Clerk Usage).Look for high value for
cachestore_sqlcp (ad-hoc query plans)
SELECT TOP(10) mc.[type] AS [memory clerk type], |
MEMORYCLERK_SQLBUFFERPOOL
was new for SQL Server 2012. It should be your highest consumer of memory.
CACHESTORE_SQLCP SQL Plans:These are cached SQL statements or batches
that aren't in stored procedures, functions and triggers.Watch out for high
values for CACHESTORE_SQLCP.CACHESTORE_OBJCP Object Plans.These are
compiled plans for stored procedures, functions and triggers.
Query 43
Find single-use, ad-hoc and prepared queries that are bloating the plan cache (Ad hoc Queries)
SELECT TOP(50) [text] AS [querytext], cp.cacheobjtype, |
Gives you the text, type and size of single-use ad-hoc and prepared queries that waste space in the plan cache.Enabling 'optimize for ad hoc workloads' for the instance can help (SQL Server 2008 and above only).Running DBCC FREESYSTEMCACHE ('SQL Plans') periodically may be required to better control this.Enabling forced parameterization for the database can help, but test first!
Query 44
Get top total logical reads queries for entire instance (Top Logical Reads Queries)
| SELECT TOP(50) Db_name(t.[dbid]) AS [database name], LEFT(t.[text], 50) AS [short query text] , qs.total_logical_reads AS [total logical reads], qs.min_logical_reads AS [min logical reads], qs.total_logical_reads / qs.execution_count AS [avg logical reads], qs.max_logical_reads AS [max logical reads], qs.min_worker_time AS [min worker time], qs.total_worker_time / qs.execution_count AS [avg worker time], qs.max_worker_time AS [max worker time], qs.min_elapsed_time AS [min elapsed time] , qs.total_elapsed_time / qs.execution_count AS [avg elapsed time], qs.max_elapsed_time AS [max elapsed time] , qs.execution_count AS [execution count], qs.creation_time AS [creation time] -- ,t.[text] as [complete query text], qp.query_plan as [query plan] -- uncomment out these columns if not copying results to excel FROM sys.dm_exec_query_stats AS qs WITH (nolock) CROSS apply sys.Dm_exec_sql_text(plan_handle) AS t CROSS apply sys.Dm_exec_query_plan(plan_handle) AS qp ORDER BY qs.total_logical_reads DESC OPTION (recompile); |
Helps you find the most expensive queries from a memory perspective across the entire instance.Can also help track down parameter sniffing issues.
Years of Experience
Gratified Students
Training Batches
Training Hours
Please subscribe our technical blog to get recent updates.