4
3/11/2014 SQL Server Backup, Integrity Check, Index and Statistics Maintenance http://ola.hallengren.com/ 1/4 Menu Home SQL Server Backup SQL Server Integrity Check SQL Server Index and Statistics Maintenance Downloads Frequently Asked Questions Version History Organizations that Use the Solution Sign Up for the Newsletter License Contact Awards SQL Server Maintenance Solution SQL Server Backup, Integrity Check, and Index and Statistics Maintenance The SQL Server Maintenance Solution comprises scripts for running backups, integrity checks, and index and statistics maintenance on all editions of Microsoft SQL Server 2005, SQL Server 2008, SQL Server 2008 R2, and SQL Server 2012. The solution is based on stored procedures, the sqlcmd utility, and SQL Server Agent jobs. I designed the solution for the most missioncritical environments, and it is used in many organizations around the world. Numerous SQL Server community experts recommend the SQL Server Maintenance Solution, which has been a Gold winner in the 2013 , 2012 , 2011 , and 2010 SQL Server Magazine Awards. The SQL Server Maintenance Solution is free . “The best starting point for building your own maintenance plan is the comprehensive and free script from Ola Hallengren. That’s what I recommend to my clients.” Paul S. Randal Getting Started Download MaintenanceSolution.sql . This script creates all the objects and jobs that you need. Learn more about using the SQL Server Maintenance Solution: DatabaseBackup : SQL Server Backup DatabaseIntegrityCheck : SQL Server Integrity Check IndexOptimize : SQL Server Index and Statistics Maintenance Sign up for the newsletter to be alerted about updates to the solution. SQL Server 2014 CTP Microsoft has made a Community Technology Preview (CTP) version available of SQL Server 2014. The CTP version contains partition level online index rebuilds, lock priorities for online index rebuilds, backup encryption, and many other features. I have a CTP version of the SQL Server Maintenance Solution with support for these features. Please contact me to get the CTP version, if you are doing testing on SQL Server 2014. SQL Server 2012 The SQL Server Maintenance Solution supports SQL Server 2012. One new feature in SQL Server 2012 is AlwaysOn Availability Groups. This feature supports multiple replicas of a database. Secondary replicas

SQL Server Backup, Integrity Check, Index and Statistics Maintenance

Embed Size (px)

Citation preview

Page 1: SQL Server Backup, Integrity Check, Index and Statistics Maintenance

3/11/2014 SQL Server Backup, Integrity Check, Index and Statistics Maintenance

http://ola.hallengren.com/ 1/4

Menu

Home

SQL Server Backup

SQL Server Integrity Check

SQL Server Index andStatistics Maintenance

Downloads

Frequently Asked Questions

Version History

Organizations that Use theSolution

Sign Up for the Newsletter

License

Contact

Awards

 

 

SQL Server Maintenance Solution

SQL Server Backup, Integrity Check, and Indexand Statistics Maintenance

The SQL Server Maintenance Solution comprises scripts for runningbackups, integrity checks, and index and statistics maintenance on alleditions of Microsoft SQL Server 2005, SQL Server 2008, SQL Server2008 R2, and SQL Server 2012. The solution is based on storedprocedures, the sqlcmd utility, and SQL Server Agent jobs. I designedthe solution for the most mission­critical environments, and it is used inmany organizations around the world. Numerous SQL Servercommunity experts recommend the SQL Server Maintenance Solution,which has been a Gold winner in the 2013, 2012, 2011, and 2010 SQLServer Magazine Awards. The SQL Server Maintenance Solution is free.

“The best starting point for building your own maintenance planis the comprehensive and free script from Ola Hallengren. That’swhat I recommend to my clients.” ­ Paul S. Randal

Getting Started

Download MaintenanceSolution.sql. This script creates all the objectsand jobs that you need.

Learn more about using the SQL Server Maintenance Solution:

DatabaseBackup: SQL Server BackupDatabaseIntegrityCheck: SQL Server Integrity CheckIndexOptimize: SQL Server Index and Statistics Maintenance

Sign up for the newsletter to be alerted about updates to the solution.

SQL Server 2014 CTP

Microsoft has made a Community Technology Preview (CTP) versionavailable of SQL Server 2014. The CTP version contains partition levelonline index rebuilds, lock priorities for online index rebuilds, backupencryption, and many other features. I have a CTP version of the SQLServer Maintenance Solution with support for these features. Pleasecontact me to get the CTP version, if you are doing testing on SQLServer 2014.

SQL Server 2012

The SQL Server Maintenance Solution supports SQL Server 2012.

One new feature in SQL Server 2012 is AlwaysOn Availability Groups.This feature supports multiple replicas of a database. Secondary replicas

Page 2: SQL Server Backup, Integrity Check, Index and Statistics Maintenance

3/11/2014 SQL Server Backup, Integrity Check, Index and Statistics Maintenance

http://ola.hallengren.com/ 2/4

Sponsors

can be readable and they can also be used for backup.

SQL Server 2012 also supports online rebuilding of indexes withvarchar(max), nvarchar(max), varbinary(max), or XML data types orlarge CLR types.

Intelligent Index Maintenance

The SQL Server Maintenance Solution lets you intelligently rebuild orreorganize only the indexes that are fragmented. In the IndexOptimizeprocedure, you can define a preferred index maintenance operation foreach fragmentation group. Take a look at this code:

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

In this example, indexes that have a high fragmentation level will berebuilt, online if possible. Indexes that have a medium fragmentationlevel will be reorganized. Indexes that have a low fragmentation levelwill remain untouched.

Update Statistics

The IndexOptimize procedure can also be used to update statistics. Youcan choose to update all statistics, statistics on indexes only, or statisticson columns only. You can also choose to update the statistics only if anyrows have been modified since the most recent statistics update.

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'

Solve “No Current Database” Issues

Most DBAs have experienced the error message “BACKUP LOG cannot beperformed because there is no current database backup” or “Cannotperform a differential backup for database, because a current databasebackup does not exist”. These errors usually occur when you havecreated a new database or changed the database recovery model from

Page 3: SQL Server Backup, Integrity Check, Index and Statistics Maintenance

3/11/2014 SQL Server Backup, Integrity Check, Index and Statistics Maintenance

http://ola.hallengren.com/ 3/4

Simple to Full. The answer is to determine, before you run the backup,whether a differential or transaction log backup can be performed. Youcan use the DatabaseBackup procedure’s @ChangeBackupType option tochange the backup type dynamically if a differential or transaction logbackup cannot be performed.

Here’s an example of how to use the @ChangeBackupType option:

EXECUTE dbo.DatabaseBackup@Databases = 'USER_DATABASES',@Directory = 'C:\Backup',@BackupType = 'LOG',@Verify = 'Y',@ChangeBackupType = 'Y',@CleanupTime = 24

Back up to Multiple Files

Databases are becoming larger and larger. You can tune theperformance of SQL Server backup compression, by using multiplebackup files, and the BUFFERCOUNT and MAXTRANSFERSIZE options.The DatabaseBackup procedure supports these options:

EXECUTE dbo.DatabaseBackup@Databases = 'USER_DATABASES',@Directory = 'C:\Backup, D:\Backup, E:\Backup, F:\Backup',@BackupType = 'FULL',@Compress = 'Y',@BufferCount = 50,@MaxTransferSize = 4194304,@NumberOfFiles = 4,@CleanupTime = 24

Run Integrity Checks of Very Large Databases

The SQL Server Maintenance Solution has been designed to do integritychecks of very large databases. In the DatabaseIntegrityCheckprocedure you can choose do the checks on the database level, thefilegroup level, or the table level. It also supports limiting the checks tothe physical structures of the database:

EXECUTE dbo.DatabaseIntegrityCheck@Databases = 'USER_DATABASES',@CheckCommands = 'CHECKDB',@PhysicalOnly = 'Y'

SQL Server Community Awards

For the past four years, the SQL Server Maintenance Solution has beenvoted as Best Free Tool in the SQL Server Magazine Awards:

2014 Microsoft Most Valuable Professional (MVP) ­ SQL Server

Page 4: SQL Server Backup, Integrity Check, Index and Statistics Maintenance

3/11/2014 SQL Server Backup, Integrity Check, Index and Statistics Maintenance

http://ola.hallengren.com/ 4/4

2014 Simple­Talk and SQL Server Central Tribal Awards: BestFree Script2013 SQL Server Magazine Community Choice: Best Free Tool,Gold award2012 SQL Server Magazine Community Choice: Best Free Tool,Gold award2011 SQL Server Magazine Editors’ Best: Best Free Tool, Silveraward2011 SQL Server Magazine Community Choice: Best Free Tool,Gold award“Hands down, one of the best tools out there! If you’reresponsible for a database, you should be using Ola’s scripts. It’svery comprehensive, is efficient with resources, has numerousoptions, and is a brilliant piece of SQL coding!”2010 SQL Server Magazine Editors’ Best: Best Free Tool, Bronzeaward2010 SQL Server Magazine Community Choice: Best Free Tool,Gold award

The Solution in the News and on the Web

I hosted a session about the SQL Server Maintenance Solution onSQLBits IX, in October 2011.

SQL PASS had a session about the SQL Server Maintenance Solutionduring the 24 Hours of PASS 2010 online conference.

SQL Server Magazine featured an article about the SQL ServerMaintenance Solution in its November 2008 issue (PDF version).

SimpleTalk featured an article about the SQL Server MaintenanceSolution in July 2010.

Feel free to contact me if you have any questions. Thank you for tryingout the solution.

© 2013 Ola Hallengren | E­mail: [email protected] | Sweden