Providing a SQL Server Express edition with a solid maintenance plan

Providing a SQL Server Express edition with a solid maintenance plan

One of the challenges of using the free express editions of SQL Server is the lack of the SQL Agent.

This means that creating a functioning maintenance plan is a bit more of a challenge then on a regular SQL Server instance. Luckily for us Ola Hallengren created his maintenance plan in such a way that it can easily be altered to make it usable for SQL express editions.

Ok let’s get started.

Creating the repository database

First things first, start with downloading Ola’s excellent maintenance scripts from his website, this ensures that you have the latest and greatest version. In this post I won’t explain all the parameters as Ola has an excellent wiki for all his

Personally I try to limit the creation of custom objects into the system databases, so I prefer creating a smaller database to contain all my DBA related objects. In this documentation we’ll use the name DBA_Express for this database.

151216b

Minor changes to Ola’s script

Changing the database from master to DBA_Express

151216c

Changing default behavior

151216d

It seems illogical to create the jobs as the agent is not running on a SQL Express, but I have a very good reasons to do so. It indeed doesn’t create any jobs on a SQL Express, but it doesn’t throw any errors neither so we can use this script on any SQL Edition

Scripts

Luckily for us Ola’s scripts are designed to run command line, so we’ll us the example scripts provided in his documentation to create 5 bat files. For this purpose, I have created the folder [D:\MSSQL\Maintenanceplan] where we can store these files. For Logging we create the [D:\MSSQL\Maintenanceplan\Log] folder

Backups

First things first, as a DBA backups is our main concern, so I’ll start with that. Please note that I’m against storing the backups on the same drive as the database files, but in this case I have no other choice. This directory will be backed up by using robocopy backups from that drive to a safe location.

Full Backups

151216e

Diff Backups

151216f

Log Backups

151216g

Cheating with compression

As an express edition doesn’t support backup compression and these servers tend to be rather thin provisioned it can be useful to compress the backup folder by using NTFS compression. As SQL Express database are limited to 10GB, and are seldom that big you could do this to save space. Don’t forget to turn it off once you go to a higher edition of SQL though, because you’ll hit the limit of NTFS compression quite fast on higher edition of SQL Server.

Index Rebuilds

Secondary let’s script our index and statistics maintenance, as this is an express edition I won’t bother splitting it up between indexes and statistics. Also we don’t bother including the online options as they are only supported in Enterprise editions.

151216h

Database Integrity

And then last but certainly not least, our database integrity checks. Again we are taking a special approach for express editions as we are not making any differentiation between system and user databases unlike on normal instances.

151216i

Adding the scripts to the windows scheduler

Start the windows task scheduler

151216j

Select Create Basic Task

151216k

Give your task a self-explaining name

151216l

Select your frequency

151216m

Select a moment

151216n

Select an Action

151216o

Point the action to the cmd files we created earlier on

151216p

Don’t forget to select to open the properties window before you select Finish

151216q

Make sure that your job will run with an account with the appropriate rights on both windows and SQL Server.

151216z

Make sure you test your newly created job, and then proceed to create the other schedules.

Special Remarks for the Log backups

As you cannot create a schedule that runs several times a day, you’ll have to create multiple log backup schedules that run daily.

151216y