Home

Backup reads and writes

Prev Page Next Page

Introduction
Recovery models
Main backup types
Backing up the database files by copying
The transaction log
Transaction log restore sequence
Log sequence numbers
Truncating and shrinking the transaction log
Backing up the tail
Inside the transaction log
So, what's in a backup file?
Test: A full backup does not contain deleted data
Verifying backup files
Verifying backup files on a budget
Why you shouldn't rely on RESTORE VERIFYONLY
Cumulative backups
Recovering individual tables
Backup and restore history details
Backup reads and writes
Speeding up backups
Backup speed details
Speeding up restores
Restore state affects speed too
Backup and restore rights
Log shipping
Log shipping in SQL Server 2000
Setting up log shipping using Enterprise Manager
Checking the set up
Failover
Log shipping in SQL Server 2005
Setting up log shipping using Management Studio
Checking the set up
Log shipping status report
Failover
Log shipping in SQL Backup
Using the CopyTool utility
Failover
3rd party backup applications
VDI
VDI versions
VDI errors
SQL Backup - beyond compression
Restoring a chain of transaction log backups
Restoring to the latest possible state
Backing up multiple databases
Backup retention
Making a copy of the backup file
Backup file naming conventions
Restoring the latest backup set
Network resilience
Encryption
Integrated database verification
Database file relocation
Improved backup retention
RESTORE HELP
Common SQL Backup issues
Installation checklist
Setting up rights
Configuring service rights
Backup data
Hanging issues
Common backup and restore errors
Error 3201 - when performing a backup to a network share
Full database backup file is larger than database size
Error 3205 - Too many backup devices specified for backup or restore
Error 4305 - an earlier transaction log backup is required
Bringing a database that is in recovery or read-only mode online
Using bulk-logged recovery model but transaction log backup is still large
Error 14274 - unable to delete SQL Server Agent job
Error messages when restoring from different versions of SQL Server.



   What happens during a backup   

backupprocess01_a

During a backup, SQL Server creates one reader thread for each volume that the database files reside on.  The reader thread simply reads the contents of the files.  Each time that it reads a portion of the file, it stores them in a buffer.  There are multiple buffers in use, so the reader thread will keep on reading as long as there are free buffers to write to.  SQL Server also creates one writer thread for each backup device to write the contents of the buffers out to disk or tape.  The writer thread writes the data from the buffer to the disk or tape.  Once the data has been written, the buffer can be reused by the reader thread.

Thus, given the following command:

BACKUP DATABASE AdventureWorks TO

DISK = 'M:\backups\AdventureWorks_FULL_01.bak',
DISK = 'N:\backups\AdventureWorks_FULL_02.bak'

WITH BUFFERCOUNT = 10, MAXTRANSFERSIZE = 1048576

and assuming that AdventureWorks files are spread across three volumes, the backup process will proceed as follows:

backupprocess02_a

SQL Server does not distinguish between logical and physical volumes.  In the above example, if E:\, F:\ and G:\ are all partitions on the same physical drive, 3 reader threads are still used to read the data files.  If your disk cannot keep up with the read demands, the backup throughput will be adversely affected.

If the BUFFERCOUNT and MAXTRANSFERSIZE parameters are not used, SQL Server will dynamically determine the number of buffers to use and the size of each buffer.  The total memory used for the backup buffers will be BUFFERCOUNT x MAXTRANSFERSIZE (bytes) + some overheads.  This memory is allocated from the  non-buffer pool memory, also known as the MemToLeave memory.  If you specify values that are larger than what is available, SQL Server will raise the following error:

Server: Msg 701, Level 17, State 1, Line 1

There is insufficient system memory to run this query.
Server: Msg 3013, Level 16, State 1, Line 1

BACKUP DATABASE is terminating abnormally.

If you want to find out the size and quantity of the buffers used by SQL Server for a backup, you can turn on trace flags 3605 and 3213.  The values used are then recorded in the SQL Server log e.g.

2008-07-14 17:21:20.65 spid51    BufferPoolLimit:          100 MB
2008-07-14 17:21:20.65 spid51    Backup/Restore buffer configuration parameters
2008-07-14 17:21:20.65 spid51    Buffer count:             15
2008-07-14 17:21:20.65 spid51    Max transfer size:        983040
2008-07-14 17:21:20.65 spid51    Total buffer space:       14 MB
2008-07-14 17:21:20.65 spid51    Buffers per read stream:  15
2008-07-14 17:21:20.65 spid51    Buffers per write stream: 5
2008-07-14 17:21:20.65 spid51    Memory Limit:             100 MB



Discuss or comment on this article on our Facebook group.

 

 
Copyright 2008 - 2013 Yohz Ventures Sdn Bhd. All rights reserved.
All product and company names are trademarks or registered trademarks of their respective owners.