2. SQL Server Storage Architecture
2. SQL Server Storage Architecture
Performance Strategies
Storage-Tiering Strategies
After :
Log Truncation
Log truncation occurs automatically after the
following events
Under the simple recovery model, after a
checkpoint.
Under the full recovery model or bulk-logged
recovery model, after a log backup, if a
checkpoint has occurred since the previous
backup.
Write-Ahead Transaction Log
SQL Server reads data pages into buffer cache when data must
be retrieved.
When a page is modified in the buffer cache, it is not
immediately written back to disk; instead, the page is marked
as dirty.
A data page can have more than one logical write made before
it is physically written to disk.
For each logical write, a transaction log record is inserted in the
log cache that records the modification.
The log records must be written to disk before the associated
dirty page is removed from the buffer cache and written to disk.
Writing a modified data page from the buffer cache to disk is
called flushing the page
Log records are written to disk when the log buffers are flushed
The Log Chain
A continuous sequence of log backups is called a log
chain. A log chain starts with a full backup of the
database.
a new log chain is only started when the database is
backed up for the first time or after the recovery model
is switched from simple recovery to full or bulk-
logged recovery.
To restore a database up to the point of failure, the log
chain must be intact. That is, an unbroken sequence of
transaction log backups must extend up to the point of
failure.
Checkpoints and the Active Portion of
the Log
Checkpoints flush dirty data pages from the buffer
cache of the current database to disk. This minimizes
the active portion of the log that must be processed
during a full recovery of a database.
During a full recovery, the following types of actions
are performed:
o The log records of modifications not flushed to disk before
the system stopped are rolled forward.
o All modifications associated with incomplete transactions,
such as transactions for which there is no COMMIT or
ROLLBACK log record, are rolled back.
Checkpoint Operation
A checkpoint performs the following processes in
the database:
Writes a record to the log file, marking the start of the
checkpoint.
Stores information recorded for the checkpoint in a chain of
checkpoint log records (include Minimum Recovery LSN).
The checkpoint records also contain a list of all the active
transactions that have modified the database.
If the database uses the simple recovery model, marks for reuse
the space that precedes the MinLSN.
Writes all dirty log and data pages to disk.
Writes a record marking the end of the checkpoint to the log
file.
Writes the LSN of the start of this chain to the database boot
page.
Activities that cause a Checkpoint
A CHECKPOINT statement is explicitly executed.
A minimally logged operation is performed in the database.
Database files have been added or removed by using ALTER
DATABASE.
An instance of SQL Server is stopped by a SHUTDOWN
statement or by stopping the SQL Server (MSSQLSERVER)
service.
An instance of SQL Server periodically generates automatic
checkpoints in each database to reduce the time that the
instance would take to recover the database.
A database backup is taken.
An activity requiring a database shutdown is performed.