What is DB Snapshot?
Snapshots are read only and are a very good option for reporting
purposes. All the reporting related hits could be made on the snapshot
instead of on the the actual database, and the burden on the active
database could be minimized. Also, as snapshots are read only, chances
of any undesired updates by the subscriber (who reads data for reports
etc.) could be negated.
A database snapshot is a read-only, static view of a SQL Server database (the source database).It is transactionally consistent with the source
database as of the moment of the snapshot's creation and always resides on the same server instance as its source
database. As the source database is updated, the database snapshot is
updated. Therefore, the longer a database snapshot exists, the more
likely it is to use up its available disk space.
Multiple snapshots can exist on a given source database. Each database
snapshot persists until it is explicitly dropped by the database owner.
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 that
is 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.
To store the copied original pages, the snapshot uses one or more sparse files.
Initially, a sparse file is an essentially empty file that contains no
user data and has not yet been allocated disk space for user data. As
more and more pages are updated in the source database, the size of the
file grows.
Below is the link to code for creating a DB snapshot and also dropping a existing DB snapshot
Create and Drop Snapshot
References:
https://www.codeproject.com/Articles/211100/Database-Snapshot-in-MS-SQL-Server
https://docs.microsoft.com/en-us/sql/relational-databases/databases/database-snapshots-sql-server
References:
https://www.codeproject.com/Articles/211100/Database-Snapshot-in-MS-SQL-Server
https://docs.microsoft.com/en-us/sql/relational-databases/databases/database-snapshots-sql-server
Comments
Post a Comment