You are on page 1of 5

Top 10 SQL Server DBA Daily Checks

By Senior SQL Server Architect and Former MS Data Platform MVP Artemakis Artemiou
v2.1 (Sep 2018) Powered by SQLNetHub
www.sqlnethub.com

1. Check SQL Server Instance Uptime


--In SQL Server 2008 or later you can also base your query on:
--SELECT sqlserver_start_time FROM sys.dm_os_sys_info
SELECT
create_date AS LastStartTime,
DATEDIFF(HOUR,create_date,GETDATE()) AS HoursSinceLastRestart,
CASE WHEN DATEDIFF(HOUR,create_date,GETDATE())>=24 THEN '100%' ELSE CON-
CAT(CAST(CAST(ROUND((DATEDIFF(HOUR,create_date,GETDATE())/0.24),2) AS NUMERIC(12,2)) AS
VARCHAR(10)),'%') END AS UpTimePercentageInLast24Hours
FROM sys.databases
WHERE name = 'tempdb';
GO

2. Check Last Full, Differential and Log Backup Times


SELECT d.[Name] AS DatabaseName,
LastFullBackUpTime=(SELECT MAX(bs.backup_finish_date) FROM msdb.dbo.backupset bs WHERE
bs.[database_name]=d.[name] AND bs.[type]='D'),
LastDiffBackUpTime=(SELECT MAX(bs.backup_finish_date) FROM msdb.dbo.backupset bs WHERE
bs.[database_name]=d.[name] AND bs.[type]='I'),
LastLogBackUpTime=(SELECT MAX(bs.backup_finish_date) FROM msdb.dbo.backupset bs WHERE
bs.[database_name]=d.[name] AND bs.[type]='L')
FROM sys.databases d
ORDER BY 1;
GO

3. Check Failed SQL Agent Jobs in the Last 24 Hours


SELECT sj.[name] AS "Failed Job Name", sh.run_date,sh.[message]
FROM msdb.dbo.sysjobhistory sh INNER JOIN msdb.dbo.sysjobs sj ON sj.job_id =
sh.job_id
WHERE sh.run_status=0 AND DATEDIFF(dd,cast (cast (sh.run_date AS VARCHAR(20)) AS
DATE),GETDATE())=0
GROUP BY sj.[name],sh.run_date,sh.message
GO

4. Check Current Log for Failed Logins


EXEC sp_readerrorlog 0, 1, 'Login failed';
GO

5. Check for Blocked Processes


USE [master];
GO

SELECT r.session_id, r.blocking_session_id,


r.wait_type, r.wait_time,
r.wait_resource, r.transaction_isolation_level,
r.[lock_timeout], st.[text] AS BlockedSQLStatement
FROM sys.dm_exec_requests r CROSS APPLY sys.dm_exec_sql_text(r.sql_handle) AS st
WHERE blocking_session_id <> 0;
GO
6. Check Top N Queries Based on Average CPU Time
USE [Database_Name]
GO
SELECT TOP 10 qStatsFinal.query_hash AS "Query Plan Handle" ,
SUM(qStatsFinal.total_worker_time) / SUM(qStatsFinal.execution_count) AS
"Average CPU Time (ms)" ,
SUM(qStatsFinal.execution_count) AS "Execution Count",
SUM(qStatsFinal.total_logical_reads) AS "Total Logical Reads",
SUM(qStatsFinal.total_logical_writes) AS "Total Logical Writes",
SUM(qStatsFinal.total_physical_reads) AS "Total Physical Reads",

MAX(qStatsFinal.statement_text) AS "Statement Text"


FROM ( SELECT qStats.* ,
SUBSTRING(
sqlText.text ,
( qStats.statement_start_offset / 2 ) + 1,
(( CASE statement_end_offset
WHEN -1 THEN DATALENGTH(sqlText.text)
ELSE qStats.statement_end_offset
END - qStats.statement_start_offset ) / 2 ) + 1) AS
statement_text
FROM sys.dm_exec_query_stats AS qStats
CROSS APPLY sys.dm_exec_sql_text(qStats.sql_handle) AS sqlText
) AS qStatsFinal
GROUP BY qStatsFinal.query_hash
ORDER BY 2 DESC;
GO

7. Check Drive Volumes Space


SELECT
volume_mount_point AS "Drive Letter/Mount Point",
CAST(ROUND(MAX(total_bytes)/1024.0/1024.0/1024.0,2) AS INT) AS "Disk Size (GB)",
CAST(ROUND(MAX(available_bytes)/1024.0/1024.0/1024.0,2) AS INT) AS "Free Space (GB)"
FROM sys.master_files AS f
CROSS APPLY sys.dm_os_volume_stats(f.database_id, f.file_id)
GROUP BY volume_mount_point
ORDER BY 3 DESC
GO

8. Check Index Fragmentation


USE [DatabaseName];
GO

SELECT DB_NAME() AS DatabaseName ,


s.[object_id] ,
o.name AS ObjectName ,
index_type_desc ,
s.avg_fragmentation_in_percent
FROM sys.dm_db_index_physical_stats(DB_ID(DB_NAME()), NULL, NULL, NULL, NULL) s
JOIN sys.objects o ON o.object_id = s.object_id
WHERE avg_fragmentation_in_percent <> 0
ORDER BY avg_fragmentation_in_percent DESC;
GO
9. Patch Management
You need keep your SQL Server instances up to date with the latest service packs and cumulative updates (CUs), after of
course you first test them in a Test Environment.
Service packs fix possible bugs, introduce new functionality and enhance security.
To see the latest updates for all SQL Server versions, you can visit the Update Center for Microsoft SQL Server
Also, for checking out what the latest service pack is for any SQL Server version, you can check out this free service by
SQLNetHub.

10. Self-Education and Improvement


Technology is evolving rapidly. So as database technologies. We live in a dynamic, technological environment. A good
DBA must get self-educated on a daily basis, not only about security patches and service packs, but also for many other
things that have to do with technology.
For example, you need to know about the latest SQL Server tools, related technologies, features, and so on.
This is the purpose of SQLNetHub: to help you stay up to date with anything that has to with SQL Server! From high-
quality articles on SQL Server, data access and .NET, to useful SQL Server tools and eBooks, SQLNetHub can help you with
your quest to comprehensive SQL Server knowledge!

But wait! There’s more!


Be more productive when working with SQL Server!
Check SQLNetHub’s Software Solutions and see how they can help!

Snippets Generator
How can Snippets Generator help you?
• You can create or modify SQL snippets for SQL
Server.
• You can create snippets from either from scratch
or by using snippet templates.
• Use snippet templates library.
• Syntax highlighting.
DBA Security Advisor
How can DBA Security Advisor help you?
• You can check your SQL Server instances and
databases for security risks and high-risk
configurations.
• You get remediation actions and guidance via
easy-to-understand recommendations.
• You get rich reports and statistics.

Dynamic SQL Generator


How can Dynamic SQL Generator help you?
• You can convert static SQL Server SQL code to
dynamic and vice versa.
• You can parse SQL Server SQL code for syntax
checking as well as perform other operations.
• You can modify existing SQL files.
• You can use a SQL scripts library.
In-Memory OLTP Simulator
How can In-Memory OLTP Simulator help you?
• You can easily benchmark SQL Server’s In-Memory
OLTP Engine against your own workload.
• Get rich performance statistics, trend analysis, and
more.
• Two modes of execution: (i) Simulation Mode, (ii)
Benchmark Mode

Check all our software solutions!

You might also like