Database Maintenance
This chapter offers suggestions for the maintenance of the JICS database. Implementing a Service Improvement Plan for the SQL Server is recommended.
Objective
To automate SQL Server maintenance tasks (such as backups, index optimization, and statistics updates) using an Olla script for efficient performance.
Prerequisites
SQL Server Management Studio (SSMS) is installed.
Proper SQL Server user permissions are in place (e.g., System Admin or maintenance role).
Olla (or relevant scripting tool) has already been downloaded and set up.
Basic knowledge of SQL Server maintenance tasks.
Implement Olla Script for SQL Maintenance Jobs
This section explains a step-by-step process for implementing the Olla script for SQL Maintenance jobs. The SQL Server Maintenance Solution website is a trusted source to download the Olla script or tools.
Navigate to the SQL Server Maintenance Solution website by clicking the following link:
SQL Server Maintenance Solution
Open SQL Server Management Studio (SSMS).
Launch SSMS and connect to your SQL Server instance.
Enter your server credentials and ensure you have administrative rights.
Run the Olla script you downloaded to create jobs and stored procedures in the Master database.
Confirm the following stored procedures are created in the Master database and SQL Server Agent jobs folders by opening the applicable folders in the Object Explorer screen.
Open the Stored Procedures folder and ensure the following stored procedures are created:
dbo.DatabaseBackup
dbo.DatabaseIntegrityCheck
dbo.IndexOptimize
Open the SQL Server Agent's Jobs folder and ensure the following jobs are created:
DatabaseBackup - SYSTEM_DATABASES - FULL
DatabaseBackup - USER_DATABASES - DIFF
DatabaseBackup - USER_DATABASES - FULL
DatabaseBackup - USER_DATABASES - LOG
DatabaselntegrityCheck - SYSTEM_DATABASES
DatabaselntegrityCheck - USER_DATABASES
IndexOptimize - USER_DATABASES
Now, customize the Olla script and edit each job based on your requirements.
First, edit the backup jobs.
Edit the FULL backup job for user databases.
In the Object Explorer screen, right-click the Database Backup - USER_DATABASES - FULL job created above and select Job Properties.
On the Job Properties pop-up window, select the Steps page on the left.
Click the Edit button.
On the Job Step Properties pop-up window, paste the following script in the Command field:
EXECUTE dbo.DatabaseBackup @Databases = 'USER_DATABASES', @Directory = 'C:\Backup', @BackupType = 'FULL', @Verify ='Y'
Click the OK button.
Edit the Differential (DIFF) backup job for user databases.
In the Object Explorer screen, right-click the Database Backup - USER_DATABASES - DIFF job created above and select Job Properties.
On the Job Properties pop-up window, select the Steps page on the left.
Click the Edit button.
On the Job Step Properties pop-up window, paste the following script in the Command field:
EXECUTE dbo.DatabaseBackup @Databases = 'USER_DATABASES', @Directory = 'C:\Backup', @BackupType = 'DIFF', @Verify ='Y'
Click the OK button.
Edit the LOG backup job for user databases.
In the Object Explorer screen, right-click the Database Backup - USER_DATABASES - LOG job created above and select Job Properties.
On the Job Properties pop-up window, select the Steps page on the left.
Click the Edit button.
On the Job Step Properties pop-up window, paste the following script in the Command field:
EXECUTE dbo.DatabaseBackup @Databases = 'USER_DATABASES', @Directory = 'C:\Backup', @BackupType = 'LOG', @Verify ='Y'
Click the OK button.
Note
Replace the backup directory with your backup location for all types of backups.
Next, edit the Index Optimize and Stats Update job for user databases.
In the Object Explorer screen, right-click the Index Optimize - USER_DATABASES job created above and select Job Properties.
On the Job Properties pop-up window, select the Steps page on the left.
Click the Edit button.
On the Job Step Properties pop-up window, paste the following script in the Command field:
EXECUTE dbo.IndexOptimize @Databases = 'USER_DATABASES', @FragmentationLow = NULL, @FragmentationMedium = 'INDEX_REORGANIZE,INDEX_REBUILD_ONLINE,INDEX_REBUILD_OFFLINE', @FragmentationHigh = 'INDEX_REBUILD_ONLINE,INDEX_REBUILD_OFFLINE', @FragmentationLevel1 = 5, @FragmentationLevel2 = 30, @UpdateStatistics = 'ALL', @OnlyModifiedStatistics = 'Y'
Click the OK button.
Schedule the SQL Server Agent job.
In the Object Explorer screen, right-click the Database Backup - USER_DATABASES - FULL job created above and select Job Properties.
On the Job Properties pop-up window, click the Schedules page on the left.
Click the New... button to set up a maintenance schedule.
On the New Job Schedule pop-up window, set the frequency (daily, weekly, or monthly) and time for when the SQL Server Agent job should run.
Click the OK button.
Important
Jenzabar recommends that you schedule Index maintenance and Stats Update jobs to run during the weekends or non-business hours.
Monitor and validate the SQL Server Agent job.
Ensure the SQL Server Agent is running.
If the SQL Server Agent is not running, right-click SQL Server Agent in the Object Explorer screen and select Start.
Check the Job History.
After the job runs, right-click the job and select View History to check the results.
On the Log File Viewer pop-up window, ensure there are no errors, and the script has run successfully.