Est.

Guide

Snowflake Time Travel Guide: Retention, Queries and Recovery

How Snowflake Time Travel works: retention periods by edition and table type, querying past data with AT and BEFORE, restoring dropped objects, recovering from a bad load, and what it adds to storage.

Data Cloud Weekly Editors · Updated

Time Travel is Snowflake's built-in way back. For a set number of days after a row is changed or an object is dropped, Snowflake keeps the earlier state, and you can query it, clone it or restore it with plain SQL. Nothing has to be switched on: every account starts with a one-day window. This guide covers how long that window is for each kind of table, the SQL that reaches into it, a recovery runbook for a bad load or a bad UPDATE, and what it adds to your storage.

What Time Travel can and can't do

Within an object's retention period you can:

  • Query past data that has since been updated or deleted, with an AT or BEFORE clause after the table name.
  • Clone a table, schema or database as it was at a point in the past, with the same clause in CREATE ... CLONE.
  • Restore a dropped table, schema or database with UNDROP.

The clock starts when the data changes, not when the table was created: each change leaves Time Travel at the time of the change plus the retention period. After that, historical data from permanent tables moves into Fail-safe, where you can no longer query, clone or restore it yourself.

Two limits are worth knowing before you rely on it. A query against historical data uses the table's current schema, so a column dropped since is not brought back by a time-travel SELECT. And a retention period of 0 days turns Time Travel off for that object: if it is dropped, it cannot be restored.

Retention periods by edition and table type

The retention period is the DATA_RETENTION_TIME_IN_DAYS parameter. The default is 1 day. What you can set it to depends on your Snowflake edition and the kind of object:

ObjectStandard EditionEnterprise Edition and higherFail-safe after it
Permanent table, schema or database0 or 1 day0 to 90 days7 days
Transient table, schema or database0 or 1 day0 or 1 dayNone
Temporary table0 or 1 day0 or 1 dayNone

Which edition your account runs is on your Snowflake contract, or in Snowsight under the account's details. Snowflake's own reference for these limits is the Time Travel documentation.

Setting and checking retention

Retention is inherited downward: account, then database, then schema, then table. An object without its own setting takes its parent's, so changing a schema's retention changes every table in it that has none of its own.

-- On create
CREATE TABLE orders (id NUMBER, status STRING, updated_at TIMESTAMP_NTZ)
  DATA_RETENTION_TIME_IN_DAYS = 30;

-- Later
ALTER TABLE orders SET DATA_RETENTION_TIME_IN_DAYS = 7;

-- For everything new in a schema
ALTER SCHEMA analytics.core SET DATA_RETENTION_TIME_IN_DAYS = 14;

To see what a table actually has, read the retention_time column of SHOW TABLES (and SHOW SCHEMAS or SHOW DATABASES for containers). Adding HISTORY includes dropped objects:

SHOW TABLES IN SCHEMA analytics.core
  ->> SELECT "name", "retention_time" FROM $1 WHERE "retention_time" = 0;

An ACCOUNTADMIN can also set MIN_DATA_RETENTION_TIME_IN_DAYS on the account. It doesn't change anyone's setting, but the retention Snowflake applies becomes the larger of the two, which stops a single ALTER from quietly switching off recovery for a table that matters.

Changing retention also affects data already in Time Travel. Raising it keeps what is currently there for longer (data already in Fail-safe stays there). Lowering it moves anything older than the new period into Fail-safe, through a background process, so it can stay reachable for a while after the change.

Querying the past with AT and BEFORE

The clause goes straight after the table name and takes one of three anchors:

-- As of a moment (cast the string so the time zone is explicit)
SELECT * FROM orders
  AT(TIMESTAMP => '2026-11-14 09:00:00 -0800'::TIMESTAMP_TZ);

-- As of a number of seconds ago
SELECT * FROM orders AT(OFFSET => -60*30);

-- Just before a given statement ran
SELECT * FROM orders BEFORE(STATEMENT => '01b2c3d4-0000-1234-0000-000000000000');

BEFORE(STATEMENT => ...) is the most precise of the three when you know which statement did the damage: it shows the table exactly as it was before that query and after everything earlier. Timestamps are easy to get wrong by a time zone, so prefer a TIMESTAMP_TZ literal or a statement ID. If the point you ask for falls outside the retention period, the query fails with an error rather than returning partial data.

To find the statement ID, look in query history. The INFORMATION_SCHEMA.QUERY_HISTORY table function covers recent queries in the current database:

SELECT query_id, start_time, user_name, query_text
FROM TABLE(INFORMATION_SCHEMA.QUERY_HISTORY())
WHERE query_text ILIKE '%orders%'
  AND query_type IN ('UPDATE', 'DELETE', 'MERGE', 'INSERT', 'COPY')
ORDER BY start_time DESC;

Recovering from a bad load or a bad UPDATE

When a pipeline writes bad rows, or someone runs an UPDATE without a WHERE, the safest fix is to rebuild the table next to the live one, check it, then swap:

  1. Find the statement that caused the damage in query history and note its query ID.
  2. Clone the table as it was before it:
    CREATE TABLE orders_restored CLONE orders
      BEFORE(STATEMENT => '<query_id>');
    A clone is zero-copy: it points at the same micro-partitions until either table changes, so it is quick even on large tables.
  3. Compare the clone with the live table (row counts, a few known keys, the columns the bad statement touched) before anything else.
  4. Swap them in one statement, so readers never see a missing table:
    ALTER TABLE orders SWAP WITH orders_restored;
  5. Replay any good writes that landed after the bad one. Everything after the chosen point is not in the clone, so a pipeline that kept loading needs those batches again.
  6. Drop the old copy once you are sure; until then it is your undo.

Where only a few rows were damaged, you can repair in place instead, by merging the old values back from orders BEFORE(STATEMENT => '<query_id>') on the table's key. Cloning is the better default when you are not sure how far the damage goes.

Schemas and databases clone the same way. A schema or database clone fails if the point you ask for is beyond the retention of any table inside it; IGNORE TABLES WITH INSUFFICIENT DATA RETENTION skips those tables instead. Internal stages and external tables are not cloned by a time-travel clone.

Restoring dropped tables, schemas and databases

SHOW TABLES HISTORY LIKE 'orders%' IN SCHEMA analytics.core;  -- dropped_on shows when
UNDROP TABLE orders;
UNDROP SCHEMA staging;
UNDROP DATABASE analytics;

UNDROP brings back the most recent dropped version, as it was just before the drop, under its old name. A few rules trip people up:

  • The name must be free. If a table called orders already exists (a pipeline recreated it, say), UNDROP fails. Rename the current one first, then undrop. A table dropped several times has one row per version in SHOW TABLES HISTORY; rename and undrop repeatedly to reach older versions.
  • Privileges. You need OWNERSHIP of the dropped object and CREATE on that object type in the schema or database it returns to.
  • Where it lands. Tables and schemas are restored into the current schema or database, so set your context first.
  • Containers set the clock. When a schema or database is dropped, the tables inside it are kept for the container's retention period, not their own. To keep a table's longer retention, drop the table on its own before dropping its schema.

Time Travel and streams

A stream reads a table's change history, which lives in the same retention window. If a stream is not consumed within the table's retention period it can become stale, and a stale stream has to be recreated, losing the changes it hadn't delivered. To help, Snowflake extends retention for a table with an unconsumed stream up to MAX_DATA_EXTENSION_TIME_IN_DAYS (14 days by default). The stale_after column of SHOW STREAMS says when each stream will go stale. If a pipeline can be paused longer than that (a long-running incident, a holiday freeze), raise the table's retention or the extension limit before it happens, not after. Our Snowflake streams guide covers staleness and how streams consume changes in full.

What it costs

Time Travel has no charge of its own, but the history it keeps is storage, billed like the rest of your storage, and permanent tables add 7 days of Fail-safe on top. The cost depends on how much a table changes, not only how big it is: Snowflake keeps what it needs to restore the rows that were updated or deleted, and full copies of tables that are dropped or truncated. A table truncated and reloaded every hour with a 30-day retention can hold many times its own size in history.

To see where it goes, query TABLE_STORAGE_METRICS:

SELECT table_catalog, table_schema, table_name,
       active_bytes, time_travel_bytes, failsafe_bytes
FROM SNOWFLAKE.ACCOUNT_USAGE.TABLE_STORAGE_METRICS
WHERE NOT deleted
ORDER BY time_travel_bytes + failsafe_bytes DESC
LIMIT 20;

Your storage rate depends on your contract, region and cloud; check it on your Snowflake order form or with your account team rather than estimating from someone else's numbers. Snowflake documents how history is counted in Storage costs for Time Travel and Fail-safe.

Fail-safe is not your backup

Fail-safe is the 7 days after Time Travel ends for permanent tables. You can't query it, set it or shorten it, and only Snowflake can recover data from it, through Snowflake Support; it exists for data lost to extreme operational failures, and a recovery can take hours to days. Plan recovery around Time Travel, and treat Fail-safe as Snowflake's last resort rather than a step in your runbook. Transient and temporary tables have no Fail-safe at all: once their (at most 1-day) retention ends, the history is gone.

A retention plan by table type

  • Raw landing and staging tables that a pipeline can reload from source: make them transient with 0 or 1 day. You save the history and Fail-safe storage, and the source is your backup.
  • Curated tables people query and edit (dimensions, facts, anything a dbt model or an analyst writes to): permanent, with enough days to cover the time it takes your team to notice a mistake. A long weekend plus a few days is a common starting point; pick the number from how long your own incidents take to spot.
  • High-churn tables rewritten in full on a schedule: keep retention short, or rebuild them from upstream instead of relying on history; check their time_travel_bytes first.
  • Tables with streams: retention at least as long as the longest gap between consumer runs you could see in an incident.
  • Account-wide: set MIN_DATA_RETENTION_TIME_IN_DAYS so no one can switch recovery off for a permanent table by accident, and don't set the account's own retention to 0.

Common questions

Is Time Travel on by default?

Yes. Every account has a 1-day retention period from the start, and it can't be turned off for the account as a whole; it can only be set to 0 per object, or as the account default for new objects.

How far back can I go?

Up to the object's retention period: at most 1 day on Standard Edition, and up to 90 days for permanent objects on Enterprise Edition and higher.

Can I time travel to before a column was dropped?

Not with a SELECT: historical queries use the current schema. Cloning the table at a point before the change gives you the table as it was then.

Does Time Travel work on views?

You can use AT and BEFORE on non-materialized views; they read the underlying tables at that point, within those tables' retention.

Related reading