DBA Hub

📋Steps in this guide1/6

MS SQL Server – Recovery models

MS SQL Server – Recovery models

sqlserver configurationintermediate
by MSSQL
14 views
1

Overview

MS SQL Server – Recovery models i) Simple recovery model            – Full and Differential backup ii) Bulk-logged recovery model – Full, differential and log backup iii) Full recovery model                 – Full, differential and log backup i) Simple recovery model            – Full and Differential backup ii) Bulk-logged recovery model – Full, differential and log backup iii) Full recovery model                 – Full, differential and log backup
2

Section 2

1. Types of Recovery Models i) Simple recovery model -- Simple recovery model every transaction will be logged into the transaction log file, but at regular intervals the transaction log file will be TRUNCATED whenever a CHECKPOINT operation occurs.

Code/Command (click line numbers to comment):

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
i) Simple recovery model
-- Simple recovery model every transaction will be logged into the transaction log file, but at regular intervals the transaction log file will be TRUNCATED whenever a CHECKPOINT operation occurs.
-- Generally used in Development environment where Database Priority/Point-in-time priority is less
-- Not supported Transaction log backups
-- No Point-in-time recovery possible
-- Data loss chances are more
ii) Bulk-logged recovery model
-- In Bulk-logged recovery model every transaction will be logged into the transaction log file, but bulk insert operations are minimally logged.
-- Supports transaction log backups 
-- No automatic Truncate of Transaction log.
-- Chances of data loss if bulk insert operations fail
-- May or may not be possible to perform point-in-time recovery
-- Disk consumption will be high when normal transactions but in bulk Disk consumption will be low
iii) Full recovery model
-- In FULL recovery model every transaction will be logged into the transaction log file.
-- This recovery model is generally used in Production databases
-- Supports transaction log backups 
-- No automatic Truncate of Transaction log.
-- Minimal/No Data Loss. 
-- Point-in-time Recovery
-- Performance Overhead and large transactions at times can take more time.
-- The downside of this model is that it can consume a lot of disk space very fast.
-- Make sure setup regular T-Log Backup, so that after T-Log backup it will truncate T-Log (space will be released)
3

Section 3

ii) Bulk-logged recovery model -- In Bulk-logged recovery model every transaction will be logged into the transaction log file, but bulk insert operations are minimally logged. iii) Full recovery model -- In FULL recovery model every transaction will be logged into the transaction log file. -- Minimal/No Data Loss. -- Point-in-time Recovery 2. Find recovery model
4

Section 4

a) Using SSMS (GUI) b) Using T-SQL
Step 4

Code/Command (click line numbers to comment):

1
2
3
4
5
6
7
8
TEST (Database) -- Right Click --- Properties

USE master;
GO
select [name], DATABASEPROPERTYEX([name],'recovery') As RecoveryModel
from sysdatabases
where name  in ('master','model','tempdb','msdb','test')
GO
5

Section 5

3. Change Recovery model a) Using SSMS (GUI) b) Using T-SQL
6

Section 6

USE MASTER; GO ALTER DATABASE TEST SET RECOVERY FULL; GO -- SET RECOVERY MODEL TO SIMPLE USE MASTER; GO ALTER DATABASE TEST SET RECOVERY SIMPLE; GO Caution: Your use of any information or materials on this website is entirely at your own risk. It is provided for educational purposes only. It has been tested internally, however, we do not guarantee that it will work for you. Ensure that you run it in your test environment before using. Caution: Your use of any information or materials on this website is entirely at your own risk. It is provided for educational purposes only. It has been tested internally, however, we do not guarantee that it will work for you. Ensure that you run it in your test environment before using.
Step 6

Code/Command (click line numbers to comment):

1
2
3
4
5
6
7
8
9
10
-- SET RECOVERY MODEL TO FULL
USE MASTER;
GO
ALTER DATABASE TEST SET RECOVERY FULL;
GO
-- SET RECOVERY MODEL TO SIMPLE
USE MASTER;
GO
ALTER DATABASE TEST SET RECOVERY SIMPLE;
GO

Comments (0)

Please to add comments

No comments yet. Be the first to comment!