Recommendation for SQL Maintenance
Please Read First: While Portal Architects assumes no responsibility for supporting customer SQL installations we have created a series of recommendations on how to configure a basic SQL maintenance plan. These steps will maintain the performance of the SkySync database by reorganizing the database indexes and update statistics on the tables as a nightly job. While this recommendation is for the SkySync database, you can configure maintenance plans to include any other databases under your administration at your own discretion.
For the purposes of this guide we are assuming that the name of your database is “SkySync’. If have used an alternate name please insert that name in the guide as necessary
The Methods described will only work with SQL Express and Full SQL both sets of instructions are below depending on the type of Database you will need. It should be noted that for SQL CE which is the default installation the steps below are unnecessary.
SQL Express Database
Here are the necessary step-by-step instructions to create the task for a SQL Express database.
1) Verify the current database configuration.
a) On the machine which hosts your SQL node open your Microsoft SQL Server Management Studio (SSMS) and connect to the database server instance where the SkySync database is installed.
b) Right click on your database named “SkySync” (or the Name you gave it) and select "Properties".
c) Under the Files tab there is a table which includes the path which is where your “.mdf” and “log.ldf” files are located. You will need this path information later.
Note: If you navigate to that directory you can see the current sizes of both files.
d) Under the Options tab make sure the recovery model is set to simple. (This will keep your transaction log from growing. If you want to do Full you will need to back your “.ldf” transaction log file.).
2) Download and apply the maintenance script to the database.
a) In a browser, open the following URL: https://ola.hallengren.com and then download the free to use SQL Server script “MaintenanceSolution.sql”. While this is a 3rd party script which we are not affiliated with, we believe it is an excellent solution.
b) Open the SQL script file which will load the contents into your Microsoft SQL Server Management Studio query window.
c) Execute the script which will create the stored procedures in your master database.
d) In the object explorer under "Databases" expand the following trees: System Databases, Programmability, and Stored Procedures. The following four maintenance stored procedures should have been added:
i) dbo.CommandExecute
ii) dbo.DatabaseBackup
iii) dbo.DatabaseIntegrityCheck
iv) dbo.IndexOptimize
3) Create several system tasks to back up the database and rebuild the indexes.
a) Creation of a nightly backup task.
a) Create a text file with the following name “DatabaseBackup.txt”
i) Add the following lines to the file.
@echo off sqlcmd -E -S .\SQLEXPRESS -d master -Q "EXECUTE dbo.DatabaseBackup @Databases = 'SkySync', @Directory = N'C:\Backup', @BackupType = 'FULL', @LogToTable = 'Y'" -b -o C:\temp\BackupDatabase.txt