Time Travel, UNDROP and zero-copy cloning

Snowflake · Practical · 12 min

Recovering from a bad UPDATE or spinning up a full dev copy takes seconds once you know these features.

Because micro-partitions are immutable, Snowflake can keep old versions of a table around. Time Travel lets you query or restore data as it was within the retention period: 1 day by default, up to 90 days for permanent objects on Enterprise edition (DATA_RETENTION_TIME_IN_DAYS). Transient and temporary tables allow at most 1 day.

  • SELECT ... FROM t AT(TIMESTAMP => '2025-06-01 09:00'::TIMESTAMP_LTZ)
  • AT(OFFSET => -60*30): 30 minutes ago, in seconds.
  • BEFORE(STATEMENT => '<query id>'): just before a specific statement ran, ideal after a bad DELETE.
  • UNDROP TABLE | SCHEMA | DATABASE restores a dropped object.

After Time Travel ends, permanent tables enter a 7-day Fail-safe that only Snowflake Support can recover from. Both periods consume storage for changed data.

Zero-copy cloning creates a new table, schema or whole database that initially shares the original's micro-partitions: CREATE DATABASE dev CLONE prod. It completes in seconds or minutes regardless of size and costs no storage until either side changes data. Clones can be combined with Time Travel, CLONE t AT(...), to snapshot a point in time.

A common recovery move: clone the table as it was before the bad statement, check it, then swap it in with ALTER TABLE ... SWAP WITH ....

Example

-- Oops: a bad delete
DELETE FROM orders WHERE amount > 0;
SET bad_qid = LAST_QUERY_ID();

-- Look at the data just before that statement
SELECT COUNT(*) FROM orders BEFORE(STATEMENT => $bad_qid);     -- 1200

-- Restore: clone the old version, then swap it in
CREATE TABLE orders_restored CLONE orders BEFORE(STATEMENT => $bad_qid);
ALTER TABLE orders SWAP WITH orders_restored;

DROP TABLE orders_restored;   -- now holds the damaged version
UNDROP TABLE orders_restored; -- ...and could still be brought back

-- Full dev environment in seconds, no extra storage at first
CREATE DATABASE shop_dev CLONE shop;

Remember

  • AT / BEFORE query past data within the retention period
  • UNDROP restores dropped tables, schemas and databases
  • Clones share micro-partitions: instant and free until data diverges

Watch out for

  • Assuming Time Travel is a backup with unlimited history; it lasts only the retention period.

Check yourself

  1. What does CREATE DATABASE dev CLONE prod cost in storage immediately after it runs?

Sign in to answer, see the explanations, and get this lesson back as a quick review later.

Official docs: docs.snowflake.com/en/user-guide/data-time-travel