Quantcast
Viewing all articles
Browse latest Browse all 3160

SQL Server Health Check Checklist

AnySQL Server DBA worth their salt have their own checklist through which they routinely go to make sure that all systems are up and running. Below we willshare with you some crucial points related to SQL Server health check.

Here we willdiscuss two ways, how to composeSQL Server health check checklist. You can performall checks manually, using T-SQL Commands, or simply use Automated Health Check from SqlBak. Here it goes.

SQL Server Service Health Check

The first thing you need to ensureis that all your SQL Server services are alive. Of course, if you are able to successfullyconnect to SQL Server instance it means that it is alive, but still, you can check the status of all your SQL Server services using the following commands:

exec master.dbo.xp_servicecontrol 'QUERYSTATE', 'mssqlServer'
exec master.dbo.xp_servicecontrol 'QUERYSTATE', 'SQLServerAgent'
exec master.dbo.xp_servicecontrol 'QUERYSTATE', 'SQLBrowser'
Here you can check which services are running and which stopped:
Image may be NSFW.
Clik here to view.
SQL Server Health Check Checklist

Of course, it’s a bit weird to run this query manually every hour, isn’t it? As a developer, you should probably think about creating some simple application or a batch file that will check thestatus of your SQL Server and notify you if something goes wrong.

SqlBak users don’t need any additional application though. It performs regular checks and sends alerts in the event of service failure.


Image may be NSFW.
Clik here to view.
SQL Server Health Check Checklist

SQL Server Backup Health Check

Another thing you need to check is database backups. Again, you can do it either manually or withSqlBak.

To check it manually you can use the following two usefulqueries. The first one checks yourfull backups and the second one checks alltransaction logbackups:

SELECT d.name AS "Database",
ISNULL(CONVERT(VARCHAR,b.backupdate,120),'NEVER') AS "Last Full Backup"
FROM sys.databases d
LEFT JOIN (SELECT database_name,type,MAX(backup_finish_date) backupdate FROM backupset
WHERE type LIKE 'D'
GROUP BY database_name,type) b on d.name=b.database_name
WHERE (backupdate IS NULL OR backupdate < getdate()-1)
SELECT d.name AS "Database",
ISNULL(CONVERT(VARCHAR,b.backupdate,120),'NEVER') AS "Last Log Backup"
FROM sys.databases d
LEFT JOIN (SELECT database_name,type,MAX(backup_finish_date) backupdate FROM backupset
WHERE type LIKE 'L'
GROUP BY database_name,type) b on d.name=b.database_name
WHERE recovery_model = 1
AND (backupdate IS NULL OR backupdate < getdate()-1)

As a result you will see alist of databases that either do not have any backups at all or have not been backed up in the past 24 hours:


Image may be NSFW.
Clik here to view.
SQL Server Health Check Checklist

Howeverif you useSqlBak to backup your databases, you don’t need to check your SQL Server database backups manually all the time. You will be notified automatically if any or your scheduled backups failed.

At the same time, if you want to see the status of all backup jobs you can open yourDashboard page and check the “Last Run” column. If the last backup succeeded there will be “Success” sign and if it failed, then “Failed”.


Image may be NSFW.
Clik here to view.
SQL Server Health Check Checklist

In addition, you can check the entire database backup history by clicking on the backup job you need:


Image may be NSFW.
Clik here to view.
SQL Server Health Check Checklist

Check for Available Disk Space

One ofthe trickiestproblems DBA may face is insufficient disk space. If you run out of free disk space it will not only slow your server downbut also may cause multiple errors and application failures. And the most dangerous thing here is that it may happen when you least expect it (for example in the midst of your vacation).

You cancheck free disk space using a simple windows command:

fsutil volume diskfree c:

or with a bit more complicated WMI command:

wmic /node:"%COMPUTERNAME%" LogicalDisk Where DriveType="3" Get DeviceID,FreeSpace|find /I "c:"

If you need you can check how much free disk space is left using the following SQL Server statement:

exec master.dbo.xp_fixeddrives
Image may be NSFW.
Clik here to view.
SQL Server Health Check Checklist

But why not letSqlBak do it for you automatically? It has a nice feature that will perform hourly checks and alert you viaemail when free disk space crosses the threshold you set.

Additionally, SqlBak’s Health Check dashboard allows you to easily determine what folders and filesoccupy your disk:
Image may be NSFW.
Clik here to view.
SQL Server Health Check Checklist

Check for free memory available for SQL Server

Besides monitoringserver’s free disk space you also need to take note ofhow much free memory is available on your server. If the amount of free memory is approaching some critical value you need to take steps to free it.

To check your server’s memory withSQL you can use the following syntax:

SELECT available_physical_memory_kb/1024 as "Total Memory MB",
available_physical_memory_kb/(total_physical_memory_kb*1.0)*100 AS "% Memory Free"
FROM sys.dm_os_sys_memory
Image may be NSFW.
Clik here to view.
SQL Server Health Check Checklist

Check the size of the transaction log

Thetransaction logis one of thecrucial aspects of every database. It is used to keep all transactions prior to committing the data into the data file. Depending on the numberof transactions it may happen that transaction logs grow quite large and not knowing what is in the transaction log or how much space is occupied by it can cause some problems.

To get the size of transaction logs you can run the following query:

DBCC SQLPERF(LOGSPACE)
Image may be NSFW.
Clik here to view.
SQL Server Health Check Checklist

SqlBak Automatic Health Check can help you here as well asit monitors how much space does the transaction log occupy for each database:
Image may be NSFW.
Clik here to view.
SQL Server Health Check Checklist

Check for Index Fragmentation

Besides fragmentation at the file system level it’s also possible to have fragmentation within the data and log files, in the structures that store the log, table and index data. This also may lead to asignificant drop in database performance.

You can usethe system function sys.dm_db_index_physical_stats to detect fragmentation in data and indexes of the specified table or view in SQL Server. Run the following query

SELECT OBJECT_NAME(OBJECT_ID), index_id,index_type_desc,index_level,
avg_fragmentation_in_percent,avg_page_space_used_in_percent,page_count
FROM sys.dm_db_index_physical_stats
(DB_ID(N'<YOUR DATABASE>'), NULL, NULL, NULL , 'SAMPLED')
ORDER BY avg_fragmentation_in_percent DESC

Viewing all articles
Browse latest Browse all 3160

Trending Articles