A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://learn.microsoft.com/en-us/sql/relational-databases/databases/database-snapshots-sql-server below:

Database Snapshots (SQL Server) - SQL Server

Applies to: SQL Server

A database snapshot is a read-only, static view of a SQL Server database (the source database). It's transactionally consistent with the source database as of the snapshot's creation and always resides on the same server instance as its source database. While database snapshots provide a read-only view of the data in the same state as when the snapshot was created, the size of the snapshot file grows as changes are made to the source database.

While database snapshots can be beneficial during major schema upgrades and allow for reverting to a previous state, it's crucial to understand that snapshots don't replace the need for regular backups. You can't back up or restore database snapshots, which means they should be used with a robust backup strategy to ensure data protection and recovery if there is data loss or corruption.

Database snapshots are created with the CREATE DATABASE T-SQL syntax, using the AS SNAPSHOT OF syntax.

Multiple snapshots can exist on a given source database. Each database snapshot persists until the database owner explicitly drops it.

Note

Database snapshots are unrelated to snapshot backups, Transact-SQL snapshot backups, snapshot isolation of transactions, or snapshot replication.

Feature Overview

Database snapshots operate at the data page level. Before a page of the source database is modified for the first time, the original page is copied from the source database to the snapshot. The snapshot stores the original page, preserving the data records as they existed when the snapshot was created. The same process is repeated for every page being modified for the first time. To the user, a database snapshot appears never to change because read operations on a database snapshot always access the original data pages, regardless of where they reside.

The snapshot stores the copied original pages using one or more sparse files. Initially, a sparse file is an empty file that contains no user data and hasn't yet been allocated disk space for user data. The file size grows as more pages are updated in the source database. The following figure illustrates the effects of two contrasting update patterns on the size of a snapshot. Update pattern A reflects an environment in which only 30 percent of the original pages are updated during the life of the snapshot. Update pattern B reflects an environment in which 80 percent of the original pages are updated during the life of the snapshot.

Benefits Terms and definitions

Database snapshots in SQL Server involve several key terms and definitions. A database snapshot is a read-only, static view of a database (referred to as the source database) at a specific point in time. The source database is the original database on which the snapshot is based, and it must remain online and accessible for the snapshot to be usable. Sparse files store the original pages of the source database that have been modified since the snapshot was created. These files are initially empty and grow as changes occur in the source database. Understanding these terms is essential for effectively managing and utilizing database snapshots in SQL Server.

Database snapshot

A transactionally consistent, read-only, static view of a database (the source database).

Source database

For a database snapshot, the database on which the snapshot was created. Database snapshots are dependent on the source database. The snapshots of a database must be on the same server instance as the database. Furthermore, if that database becomes unavailable for any reason, its snapshots become unavailable.

Sparse file

The NTFS file system provides a file that requires much less disk space than would otherwise be needed. A sparse file is used to store pages copied to a database snapshot. When first created, a sparse file takes up little disk space. As data is written to a database snapshot, NTFS allocates disk space gradually to the corresponding sparse file.

Prerequisites

The source database, which can use any recovery model, must meet the following prerequisites:

Limitations on the source database

As long as a database snapshot exists, the following limitations exist on the snapshot's source database:

Limitations on Database snapshots

Database snapshots depend on the source database and don't protect against disk errors or corruption. Therefore, while they can be useful for reporting purposes or during schema changes, they should complement, not replace, regular backup practices. If you need to restore the source database to the point where you created a database snapshot, implement a backup policy that enables you to do that.

The following limitations apply to database snapshots:

When a page getting updated on the source database is pushed to a snapshot, if the snapshot runs out of disk space or encounters some other error, it becomes suspect and must be deleted.

Database snapshots don't support FILESTREAM filegroups. If FILESTREAM filegroups exist in a source database, they're marked as offline in its database snapshots, and the snapshots can't be used to revert the database.

Note

A SELECT statement that is executed on a database snapshot must not specify a FILESTREAM column; otherwise, the following error message will be returned: Could not continue scan with NOLOCK due to data movement.

Disk space

Database snapshots consume disk space. If a database snapshot runs out of disk space, it's marked as suspect and must be dropped. (The source database, however, isn't affected; actions on it continue normally.)

However, snapshots are highly space-efficient compared to a full copy of a database. A snapshot requires only enough storage for the pages that change during its lifetime. Generally, snapshots are kept for a limited time, so their size isn't a significant concern.

However, the longer you keep a snapshot, the more likely it's to use up available space. The maximum size to which a sparse file can grow is the corresponding source database file size at the time of the snapshot creation. A database snapshot must be deleted (dropped) if it runs out of disk space.

Note

Except for file space, a database snapshot consumes roughly as many resources as a database.

Offline filegroups

Offline filegroups in the source database affect database snapshots when you try to do any of the following:


RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4