Snowflake

Snowflake Time Travel: The Complete Guide

2026-03-21
更新: 2026-03-27
NicheeLab Editorial Team

Time Travel is the core data-protection feature of Snowflake. It lets you access the past state of tables, schemas, and databases so you can recover from mistakes and query historical data. The three points that come up most often on the exam are: past-point-in-time queries with the AT/BEFORE clause, object restoration with UNDROP, and retention control with DATA_RETENTION_TIME_IN_DAYS.

Retention Period and Edition Differences

The Time Travel retention period is controlled by the DATA_RETENTION_TIME_IN_DAYS parameter. This value can be set at the account, database, schema, and table levels, and lower-level settings override higher-level ones.

EditionPermanent TableTransient TableTemporary Table
Standard0-1 day0-1 day0-1 day
Enterprise and above0-90 days0-1 day0-1 day
-- Set retention to 90 days at the table level
ALTER TABLE analytics.orders
  SET DATA_RETENTION_TIME_IN_DAYS = 90;

-- Set retention at the schema level (becomes the default for tables under it)
ALTER SCHEMA analytics
  SET DATA_RETENTION_TIME_IN_DAYS = 30;

-- Check the current setting
SHOW PARAMETERS LIKE 'DATA_RETENTION_TIME_IN_DAYS'
  IN TABLE analytics.orders;

Past-Point-in-Time Queries with AT/BEFORE

The AT clause returns the state at the specified point in time, while the BEFORE clause returns the state immediately before the specified point. There are three patterns: timestamp, offset, and Statement ID.

Timestamp Specification

-- AT: get the state at the specified timestamp
SELECT *
FROM analytics.orders
  AT (TIMESTAMP => '2026-03-27 09:00:00'::TIMESTAMP_NTZ);

-- BEFORE: get the state immediately before the specified timestamp
SELECT *
FROM analytics.orders
  BEFORE (TIMESTAMP => '2026-03-27 09:00:00'::TIMESTAMP_NTZ);

Offset Specification

-- Get the state from 30 minutes ago
SELECT *
FROM analytics.orders
  AT (OFFSET => -60 * 30);

-- Get the state from 2 hours ago
SELECT COUNT(*) AS row_count_2h_ago
FROM analytics.orders
  AT (OFFSET => -60 * 60 * 2);

Statement ID Specification

-- Get the state immediately before a specific DML statement (ideal for mistake recovery)
SELECT *
FROM analytics.orders
  BEFORE (STATEMENT => '01b12345-0600-1234-0000-abcdef012345');

Statement IDs are available from the QUERY_HISTORY view. If you accidentally run an UPDATE/DELETE, specifying that Statement ID in a BEFORE clause lets you roll back to the exact state immediately before that operation.

Data Recovery Patterns Using Time Travel

-- Pattern 1: recover from a bad UPDATE (CLONE + SWAP)
CREATE TABLE analytics.orders_restored
  CLONE analytics.orders
  BEFORE (STATEMENT => '01b12345-0600-1234-0000-abcdef012345');

-- After verifying the restored table, swap the tables
ALTER TABLE analytics.orders RENAME TO analytics.orders_backup;
ALTER TABLE analytics.orders_restored RENAME TO analytics.orders;

-- Pattern 2: recover only specific rows (partial recovery)
INSERT INTO analytics.orders
SELECT * FROM analytics.orders
  BEFORE (STATEMENT => '01b12345-0600-1234-0000-abcdef012345')
WHERE order_id IN (1001, 1002, 1003);

UNDROP TABLE / SCHEMA / DATABASE

Dropped objects can be restored with UNDROP as long as they are still within the retention period. UNDROP is available at three levels: table, schema, and database.

-- Restore a table
DROP TABLE analytics.orders;
UNDROP TABLE analytics.orders;

-- Restore a schema (also restores every table under it)
DROP SCHEMA analytics;
UNDROP SCHEMA analytics;

-- Restore a database (also restores every schema and table under it)
DROP DATABASE sales_db;
UNDROP DATABASE sales_db;

If an object with the same name has already been re-created, UNDROP fails. In that case, rename the existing object first and then run UNDROP.

-- Restore procedure when a table with the same name already exists
ALTER TABLE analytics.orders RENAME TO analytics.orders_new;
UNDROP TABLE analytics.orders;

Relationship with Fail-safe

Fail-safe is an additional 7-day data-protection layer that takes over after the Time Travel period ends. It is fundamentally different from Time Travel and cannot be operated on by users directly.

Comparison ItemTime TravelFail-safe
Operated byUser (via SQL)Snowflake Support only
Period0-90 days (configurable)Fixed 7 days (after Time Travel)
Applicable tablesPermanent / Transient / TemporaryPermanent only
Storage costCost of change historyCost of change history (Permanent only)
Recovery methodAT/BEFORE clause, UNDROP, CLONEContact Snowflake Support

Data Protection Timeline

|<── Time Travel (0-90 days) ──>|<── Fail-safe (7 days) ──>|
|  Users can freely query / restore  | Snowflake Support only |

Example: Enterprise Edition / DATA_RETENTION = 90 days / Permanent Table
  -> Up to 97 days of data protection (90 + 7)

Example: Standard Edition / DATA_RETENTION = 1 day / Permanent Table
  -> Up to 8 days of data protection (1 + 7)

Example: Transient Table (all editions)
  -> Up to 1 day of Time Travel, no Fail-safe

Data Protection by Table Type

Table TypeTime TravelFail-safePrimary Use
Permanent (default)0-90 days7 daysProduction data and tables that need protection
Transient0-1 dayNoneIntermediate tables and regeneratable data
Temporary0-1 dayNoneTemporary work limited to a single session

Managing Storage Cost

  • TABLE_STORAGE_METRICS: use the ACCOUNT_USAGE.TABLE_STORAGE_METRICS view to check ACTIVE_BYTES / TIME_TRAVEL_BYTES / FAILSAFE_BYTES per table
  • Optimize retention period: shorten DATA_RETENTION_TIME_IN_DAYS for less critical tables to reduce storage cost
  • Use Transient Tables: use Transient Tables for regeneratable data such as ETL intermediate tables to avoid Fail-safe cost

Check Your Understanding

Data Protection

問題 1

While using Enterprise Edition, you accidentally deleted some rows from a table with a bad DELETE statement. You have already identified the offending Statement ID from QUERY_HISTORY. Which is the most appropriate way to recover the data?

  1. Access Fail-safe to retrieve the data from before the deletion
  2. Use BEFORE (STATEMENT => '<statement_id>') to CLONE the table and insert the needed rows from the restored table
  3. Set DATA_RETENTION_TIME_IN_DAYS to 0 and then run UNDROP TABLE
  4. Restore the deleted data from INFORMATION_SCHEMA.COPY_HISTORY

正解: B

BEFORE (STATEMENT => ...) lets you access the table state immediately before the offending DELETE. Creating a restored table with CLONE and then INSERTing only the deleted rows back into the original table is the most appropriate approach. Fail-safe cannot be operated on directly by users, and COPY_HISTORY is a file-load history that cannot be used to recover from DML operations.

Frequently Asked Questions

How much does storage cost increase when I extend the Time Travel retention period?

Extending the Time Travel retention period causes Snowflake to retain micro-partition change history for the entire window, which incurs additional storage cost. The exact increase depends on how often DML runs and how much data changes. For tables with frequent UPDATE/DELETE operations, each operation preserves the pre-change micro-partitions, so a 90-day retention setting can consume several times more storage than a 1-day setting. We recommend regularly monitoring the TIME_TRAVEL_BYTES column in the TABLE_STORAGE_METRICS view.

When I restore with UNDROP, are table privileges (GRANTs) and Clustering Keys also restored?

Yes. UNDROP TABLE restores not only the table data but also metadata such as the GRANT privileges assigned to the table, Clustering Keys definitions, comments, and tags. UNDROP SCHEMA / UNDROP DATABASE likewise restores every object inside the schema or database along with its privilege information. However, UNDROP fails if an object with the same name already exists, so you must first rename the existing object with ALTER TABLE ... RENAME TO.

Can Time Travel be used on Transient Tables and Temporary Tables?

Transient Tables support up to 1 day of Time Travel (DATA_RETENTION_TIME_IN_DAYS = 0 or 1) but have no Fail-safe period. Temporary Tables also support up to 1 day of Time Travel within a session and are automatically dropped when the session ends. Even on Enterprise Edition, Transient and Temporary Tables are capped at 1 day of retention; extending retention up to 90 days is only possible for Permanent Tables.

Check what you learned with practice questions

Practice with certification-focused question sets

無料で問題を解いてみる
Author

NicheeLab Editorial Team

NicheeLab editorial team focused on data engineering and cloud certification learning. Content is structured around practical study needs and official exam domains.


Related articles
Snowflake

Snowflake Certifications: All 11 Exams Explained (2026)

Every SnowPro certification — Associate, Core, Specialty, Ad...

Snowflake

Snowflake Exam Difficulty Ranking: All 11 Certs Compared (2026)

All 11 SnowPro exams ranked by difficulty with study-time es...

Snowflake

Snowflake Study Guide: Fastest Pass Route by Exam (2026)

How to pass SnowPro certifications efficiently — official ma...

Snowflake

SnowPro Core (COF-C03): Complete Exam Guide (2026)

Pass the SnowPro Core exam — six domains, scope, sample ques...

Snowflake

SnowPro Associate Platform (SOL-C01): Complete Guide (2026)

The entry-level SnowPro Associate exam — scope, weighting, s...

Browse all Snowflake articles (103)
© 2026 NicheeLab All rights reserved.