13. Recovery-Configuration Properties
The recovery-configuration properties, as shown in Table 13, are used to set recovery options in SQL Server.
Table 13 Recovery-Configuration Properties
The recovery options determine how SQL Server
handles transactions and the transaction log, and how the transaction
log is backed up.
Recovery Model
SQL Server 2012 uses a recovery model
to configure several settings that work together to control how the
transaction log behaves regarding file growth and recovery
possibilities. The three recovery model options are as follows:
- Simple: The transaction log contains only transactions that
are not yet written to the data file. This option does not provide
up-to-the-minute recovery.
- Bulk-Logged: The transaction log contains all DML operations, but bulk insert operations are only marked, not logged.
- Full: The transaction log contains all changes to the data file. This option provides the greatest recovery potential.
You can set the recovery option in code with the ALTER DATABASE SET RECOVERY command.
In Management Studio, you can change the recovery
model by selecting Simple, Bulk-logged, or Full in the Recovery Model
drop-down list in the Database Properties Options tab .
To set the recovery model AdventureWorks2012 sample database to Bulk-Logged in code, do the following:
ALTER DATABASE AdventureWorks2012 SET RECOVERY BULK_LOGGED;
Page Verify
Even though SQL Server works with 8KB
data pages, the operating system I/O writes in 512-byte sectors.
Therefore, a failure might occur in the middle of a data-page write,
resulting in only some of the 512-byte sectors to be written to disk.
This is known as a torn page. You can tell SQL Server to tell you if a
torn page occurs by using the PAGE_VERIFY database option.
The PAGE_VERIFY database option can be set to one of the following values:
- CHECKSUM: This is the default level for PAGE_VERIFY.
With this option, SQL Server calculates a checksum over the contents of
each page and stores the value in the page header when a page is
written to disk. When the page is read from disk, the checksum is
recalculated and compared to the original checksum value.
- TORN_PAGE_DETECTION: This
option instructs SQL Server to toggle a bit on each 512-byte sector
with each write operation. If all the sectors were written to disk,
then all the detection bits should be identical. If, on recovery, any
of the bits are different, then SQL Server can detect the torn-page
condition and mark the database as suspect.
- NONE: Database page writes do not generate a CHECKSUM or TORN_PAGE_DETECTION value.
To change the PAGE_VERIFY option, you can either use Management Studio or T-SQL-code. In Management Studio, you can change PAGE_VERIFY by selecting CHECKSUM, TORN_PAGE_DETECTION, or NULL in the Page Verify box on the Database Properties Options tab .
Using T-SQL-code, you can use the following command to set the PAGE_VERIFY option for the AdventureWorks2012 sample database to TORN_PAGE_DETECTION:
ALTER DATABASE AdventureWorks2012 SET PAGE_VERIFY TORN_PAGE_DETECTION;
Tip
To view the page verification level of a database, query the page_verify_option_desc column in the sys.databases catalog view.
Media Retention
The media retention option sets the number of days to retain each backup set. The default value for media retention is 0 days. This option helps protect backups from being overwritten until the specified number of days has elapsed.
In Management Studio, you can set the media retention
server configuration option by entering the number of days to retain
each backup media in the Default Backup Media Retention (in Days) box
on the Server Properties Database Settings tab .
To set media retention to 10 days in code, do the following:
EXEC sp_configure ‘show advanced options', 1;
RECONFIGURE;
EXEC sp_configure ‘media retention', 10;
RECONFIGURE;
Backup Compression
Backup compression is a feature
introduced in the SQL Server 2008 Enterprise Edition. Although
initially introduced as an Enterprise Edition feature, starting with
SQL Server 2008 R2 backup compression became supported by the Standard
and all higher editions.
In Management Studio, to compress new backups by default set backup compression default by checking the Compress backup check box on the Server Properties Database Settings tab (refer to Figure 8).
To set backup compression default in code, do the following:
EXEC sp_configure ‘backup compression default', 1
RECONFIGURE
Note
After installation, new backups are
uncompressed by default. Backup compression can greatly reduce the
backup sizes and backup/restore times. But this improvement is not
free. Backup compression significantly increases the CPU usage that may
impact other operations on the server. Hence, you should test this
feature thoroughly to understand the pros and cons before implementing
in your production SQL Server.
Recovery Interval
The recovery interval
server configuration option controls when SQL Server issues checkpoints
for each database. A checkpoint flushes dirty pages from the buffer
cache of the database to disk. Checkpoints are done when SQL Server
estimates that the recovery time will be longer than the specified recovery interval. The estimated duration applies only to the REDO (roll forward) phase of the recovery and not to the UNDO (roll backward) phase. The default value for this option is 0, which implies that this option is automatically configured by SQL Server.
Best Practice
Leave the recovery interval option to the default value of 0. If you do change the recovery interval, then be sure to test it thoroughly and evaluate all other performance tuning opportunities first.
If you insist on changing the recovery interval
option, you can either use Management Studio or T-SQL-code. In
Management Studio, you can set the recovery interval
server configuration option by entering the maximum number of minutes
per database to recover databases in the Recovery Interval (Minutes)
box on the Server Properties Database Settings tab (refer to Figure 8).
Using T-SQL-code, the following command sets the recovery interval server configuration option to 5 minutes:
EXEC sp_configure ‘show advanced options', ‘1';
RECONFIGURE;
EXEC sp_configure ‘recovery interval', 5;
RECONFIGURE;