ALTER DATABASE SET SNAPSHOT
Overview
ALTER DATABASE ... SET SNAPSHOT TO overwrites a target database with the contents of a selected snapshot. You can restore from a snapshot created by the same database or from another database you own. For background on snapshots and retention, see the snapshots guide.
caution
This replaces the current contents of the target database. If you want to inspect a snapshot before overwriting, use CREATE DATABASE ... FROM ... to clone it first.
Syntax
ALTER DATABASE <target_database> SET SNAPSHOT TO (
SNAPSHOT_ID '<snapshot_id>' [, DATABASE_NAME '<source_database>']
| SNAPSHOT_TIME '<timestamp>' [, DATABASE_NAME '<source_database>']
| SNAPSHOT_NAME '<snapshot_name>'
);
Options
| Option | Type | Description |
|---|---|---|
| SNAPSHOT_ID | UUID | Restores to the snapshot with this ID. The source database is inferred unless DATABASE_NAME is provided. |
| SNAPSHOT_TIME | TIMESTAMP | Restores to the newest snapshot created at or before this timestamp. Uses the target database unless DATABASE_NAME is provided. |
| SNAPSHOT_NAME | STRING | Restores to a named snapshot. Only valid for snapshots created with CREATE SNAPSHOT <name> .... |
| DATABASE_NAME | STRING | Source database for SNAPSHOT_ID or SNAPSHOT_TIME. Not allowed with SNAPSHOT_NAME. |
Notes
- Only one snapshot selector can be used per statement.
DATABASE_NAMEis only valid withSNAPSHOT_IDorSNAPSHOT_TIME. It is not allowed withSNAPSHOT_NAME.SNAPSHOT_TIMEpicks the newest snapshot created at or before the timestamp. Use UTC; the recommended format isYYYY-MM-DD HH:MM:SS[.ffffff].- Automatic and unnamed snapshots are only available if
snapshot_retention_daysis greater than 0. Named snapshots are retained until they are unnamed. SeeALTER DATABASE. - To list snapshots and their IDs, query
MD_INFORMATION_SCHEMA.DATABASE_SNAPSHOTS. - This statement applies to MotherDuck native storage databases. DuckLake databases do not support snapshot restore.
Examples
Restore to a snapshot ID (source database inferred):
ALTER DATABASE my_db SET SNAPSHOT TO (SNAPSHOT_ID 'c204ce3b-f3fd-4677-8a05-e8680648cf27');
Restore to a snapshot ID from a specific source database (extra safety):
ALTER DATABASE my_db SET SNAPSHOT TO (
DATABASE_NAME 'prod_db',
SNAPSHOT_ID 'c204ce3b-f3fd-4677-8a05-e8680648cf27'
);
Restore to a snapshot by time from the same database:
ALTER DATABASE my_db SET SNAPSHOT TO (SNAPSHOT_TIME '2025-07-29 14:30:25');
Restore to a snapshot by time from another database:
ALTER DATABASE my_db SET SNAPSHOT TO (
DATABASE_NAME 'prod_db',
SNAPSHOT_TIME '2025-07-29 14:30:25'
);
Restore to a named snapshot:
ALTER DATABASE my_db SET SNAPSHOT TO (SNAPSHOT_NAME 'prod_backup');