| title | Accelerated database recovery | Microsoft Docs | ||
|---|---|---|---|
| ms.date | 08/12/2019 | ||
| ms.prod | sql | ||
| ms.prod_service | backup-restore | ||
| ms.technology | backup-restore | ||
| ms.topic | conceptual | ||
| helpviewer_keywords |
|
||
| author | mashamsft | ||
| ms.author | mathoma | ||
| ms.reviewer | kfarlee | ||
| monikerRange | >=sql-server-ver15||=sqlallproducts-allversions |
[!INCLUDEtsql-appliesto-ss-xxxx-xxxx-xxx-md]
ADR is off by default in [!INCLUDEsql-server-2019], and can be controlled using DDL syntax:
ALTER DATABASE [DB] SET ACCELERATED_DATABASE_RECOVERY = {ON | OFF}
[(PERSISTENT_VERSION_STORE_FILEGROUP = { filegroup name }) ];
Use this syntax to control whether the feature is on or off, and designate a specific filegroup for the persistent version store (PVS) data. If no filegroup is specified, the PVS will be stored in the PRIMARY filegroup.
The ADR feature is based on having changes versioned, with different versions of a data element kept in the PVS. There are considerations to locating where the PVS is located and in how to manage the size of the data in the PVS.
ALTER DATABASE [MyDatabase] SET ACCELERATED_DATABASE_RECOVERY = ON;
GOIn this case, when the PVS filegroup is not specified, the PRIMARY filegroup holds the PVS data.
Before running this script, create the filegroup.
ALTER DATABASE [MyDatabase] SET ACCELERATED_DATABASE_RECOVERY = ON
(PERSISTENT_VERSION_STORE_FILEGROUP = [VersionStoreFG])ALTER DATABASE [MyDatabase] SET ACCELERATED_DATABASE_RECOVERY = OFF;
GOEven after the ADR feature is disabled, there will be versions stored in the persistent version store that are still needed by the system for logical revert.
You may need to move the location of the PVS to a different filegroup for a variety of reasons. For example, PVS may require more space, or faster storage.
Changing the location of the PVS is a three-step process.
-
Turn the ADR feature off.
ALTER DATABASE [MyDatabase] SET ACCELERATED_DATABASE_RECOVERY = OFF; GO
-
Wait until all of the versions stored in the PVS can be freed
In order to be able to turn on ADR with a new location for the persistent version store, you must first make sure that all of the version information has been purged from the previous PVS location. In order to force that cleanup to happen, run the command:
EXEC sys.sp_persistent_version_cleanup [database name]
sys.sp_persistent_version_cleanupstored procedure is synchronous, meaning that it will not complete until all version information is cleaned up from the current PVS. Once it completes, you can verify that the version information is indeed removed by querying the DMVsys.dm_persistent_version_store_statsand examining the value ofpersistent_version_store_size_kb.SELECT DB_Name(database_id), persistent_version_store_size_kb FROM sys.dm_tran_persistent_version_store_stats where database_id = [MyDatabaseID]
When the value of persistent_version_store_size_kb is 0, you can re-enable the ADR feature, configuring the PVS to be located in the new filegroup.
-
Turn on ADR specifying the new location for PVS
ALTER DATABASE [MyDatabase] SET ACCELERATED_DATABASE_RECOVERY = ON (PERSISTENT_VERSION_STORE_FILEGROUP = [VersionStoreFG])
Query sys.dm_tran_persistent_version_store_stats to check PVS sizes.
Check % of DB size. Also note the difference from typical size.
PVS is considered large if it's significantly larger than baseline or if it is close to 50% of the size of the database.
-
Retrieve
oldest_active_transaction_idand check whether this transaction has been active for a really long time by queryingsys.dm_tran_database_transactionsbased on the transaction ID.Active transactions prevent cleaning up PVS.
-
If the database is part of an availability group, check the
secondary_low_water_mark. This is the same as thelow_water_mark_for_ghostsreported bysys.dm_hadr_database_replica_states. Querysys.dm_hadr_database_replica_statesto see whether one of the replicas is holding this value behind, since this will also prevent PVS cleanup. -
Check
min_transaction_timestamp(oronline_index_min_transaction_timestampif the online PVS is holding up) and based on that checksys.dm_tran_active_snapshot_database_transactionsfor the columntransaction_sequence_numto find the session that has the old snapshot transaction holding up PVS cleanup. -
If none of the above applies, then it means that the cleanup is held by aborted transactions. Check the last time the
aborted_version_cleaner_last_start_timeandaborted_version_cleaner_last_end_timeto see if the aborted transaction cleanup has completed. Theoldest_aborted_transaction_idshould be moving higher after the aborted transaction cleanup completes. -
If the aborted transaction hasn’t completed successfully recently, check the error log for messages reporting
VersionCleanerissues.