Home / Data Platform / Warehouses

Data PlatformCheat sheetIntermediate

Snowflake streams cheat sheet: offsets, stale streams and consuming changes safely

Create, inspect and consume Snowflake streams without losing changes - offsets, METADATA$ columns, stale_after, advancing a stream on purpose and recovering a stale one.

Deepak Bhardwaj8 min read

Applies toSnowflake (all editions), standard and append-only streams on tables, views and dynamic tables

When you need this

A stream is a change-tracking pointer (an offset) on a table or view. Most stream incidents come from three things: the offset didn't move when you thought it would, it moved when you didn't want it to, or the stream went stale and the changes can no longer be read. This sheet covers the commands for each case.

Create and inspect

-- Standard stream: inserts, updates and deletes
CREATE STREAM raw.orders_strm ON TABLE raw.orders;

-- Append-only: inserts only, cheaper to read on high-churn tables
CREATE STREAM raw.events_strm ON TABLE raw.events APPEND_ONLY = TRUE;

-- Include the rows that already exist as inserts in the first read
CREATE STREAM raw.customers_strm ON TABLE raw.customers SHOW_INITIAL_ROWS = TRUE;

-- Start from a point in the past (must be inside Time Travel retention)
CREATE STREAM raw.orders_strm_replay ON TABLE raw.orders
  AT (TIMESTAMP => DATEADD(hour, -6, CURRENT_TIMESTAMP()));

-- External tables use INSERT_ONLY instead of APPEND_ONLY
CREATE STREAM raw.ext_files_strm ON EXTERNAL TABLE raw.ext_files INSERT_ONLY = TRUE;
SHOW STREAMS IN SCHEMA raw;
DESCRIBE STREAM raw.orders_strm;
SELECT SYSTEM$STREAM_HAS_DATA('raw.orders_strm');

The SHOW STREAMS columns you care about are mode (DEFAULT, APPEND_ONLY, INSERT_ONLY), stale, stale_after, table_name and invalid_reason. For an account-wide view, query SNOWFLAKE.ACCOUNT_USAGE.STREAMS, which has latency like other ACCOUNT_USAGE views.

Tip

Creating the first stream on a table turns on change tracking, which needs OWNERSHIP of the table. If a different role creates the stream, have the owner run ALTER TABLE raw.orders SET CHANGE_TRACKING = TRUE; first. For streams on views, change tracking has to be on for every underlying table.

What a stream row looks like

Column Meaning
METADATA$ACTION INSERT or DELETE
METADATA$ISUPDATE TRUE when the row is half of an UPDATE (an update shows as a DELETE plus an INSERT)
METADATA$ROW_ID Stable ID of the row, useful to pair the two halves of an update

A standard stream returns the net change between the offset and now. A row inserted and then deleted inside that window does not appear at all. That is by design; if you need every intermediate version, use an append-only target table loaded more often, or the CHANGES clause below.

-- Quick summary of what is waiting
SELECT METADATA$ACTION, METADATA$ISUPDATE, COUNT(*)
FROM raw.orders_strm
GROUP BY 1, 2;

How the offset moves

Action Does the offset advance?
SELECT * FROM stream No
SELECT inside an explicit transaction No
DML that reads the stream (INSERT ... SELECT, MERGE, CREATE TABLE AS SELECT) and commits Yes, to the transaction start time
The same DML, then ROLLBACK or an error No
Two DML statements reading the stream in one explicit transaction Both see the same rows; offset moves once at commit

The last row is the safe pattern when one stream feeds two targets:

BEGIN;

MERGE INTO core.orders t
USING (
  SELECT * FROM raw.orders_strm
  WHERE NOT (METADATA$ACTION = 'DELETE' AND METADATA$ISUPDATE)
) s
ON t.order_id = s.order_id
WHEN MATCHED AND s.METADATA$ACTION = 'DELETE' THEN DELETE
WHEN MATCHED THEN UPDATE SET t.status = s.status, t.amount = s.amount, t.updated_at = s.updated_at
WHEN NOT MATCHED AND s.METADATA$ACTION = 'INSERT' THEN
  INSERT (order_id, status, amount, updated_at)
  VALUES (s.order_id, s.status, s.amount, s.updated_at);

INSERT INTO audit.orders_changes
SELECT *, CURRENT_TIMESTAMP() FROM raw.orders_strm;

COMMIT;

Warning

Never point two independent jobs at the same stream. Whichever commits first advances the offset and the second job silently gets nothing. Create one stream per consumer: CREATE STREAM raw.orders_strm_audit ON TABLE raw.orders;.

Run a task only when there is data

CREATE OR REPLACE TASK core.merge_orders
  WAREHOUSE = etl_wh
  SCHEDULE = '5 MINUTE'
  WHEN SYSTEM$STREAM_HAS_DATA('raw.orders_strm')
AS
  MERGE INTO core.orders t USING raw.orders_strm s ON t.order_id = s.order_id
  WHEN MATCHED THEN UPDATE SET t.status = s.status
  WHEN NOT MATCHED THEN INSERT (order_id, status) VALUES (s.order_id, s.status);

ALTER TASK core.merge_orders RESUME;

When the WHEN condition is false the run is skipped and the warehouse is not started.

Advance a stream on purpose

After a bad batch has been handled manually, or to skip a backlog you have reloaded another way, move the offset without processing anything:

CREATE OR REPLACE TEMPORARY TABLE tmp_discard AS
SELECT * FROM raw.orders_strm WHERE 1 = 0;

SELECT SYSTEM$STREAM_HAS_DATA('raw.orders_strm');  -- FALSE until new changes arrive

Caution

This throws away every pending change in the stream. Before running it, save what is there if you might need it: CREATE TABLE ops.orders_strm_backup AS SELECT * FROM raw.orders_strm; (this also advances the offset, so the backup is your only copy).

Stale streams

A stream goes stale when its offset falls outside the data retention period of the source table, so the change records are gone. stale_after is calculated from the last time the stream was consumed plus the source table's retention, where retention is the larger of DATA_RETENTION_TIME_IN_DAYS and MAX_DATA_EXTENSION_TIME_IN_DAYS. Snowflake extends retention up to MAX_DATA_EXTENSION_TIME_IN_DAYS (default 14 days) for tables that have unconsumed streams.

Find streams about to go stale

SHOW STREAMS IN ACCOUNT;

SELECT "database_name", "schema_name", "name", "table_name", "stale", "stale_after"
FROM TABLE(RESULT_SCAN(LAST_QUERY_ID()))
WHERE "stale" = 'true'
   OR "stale_after" < DATEADD(day, 2, CURRENT_TIMESTAMP())
ORDER BY "stale_after";

Put this in a Snowflake alert or your monitoring job. A stream that nobody consumes because its task is suspended is the usual cause.

Buy time before it goes stale

ALTER TABLE raw.orders SET MAX_DATA_EXTENSION_TIME_IN_DAYS = 30;

This moves stale_after forward for streams that are not stale yet. Streams that are already stale stay stale. Longer retention increases Time Travel storage, so set it back after the consumer catches up.

Recover a stale stream

A stale stream cannot be read. The only fix is to recreate it, and you must decide where the new offset starts:

Situation Action
Changes since the last good load are still in Time Travel CREATE OR REPLACE STREAM ... AT (TIMESTAMP => '<last successful load time>')
Changes are gone CREATE OR REPLACE STREAM ... at now, then reconcile the target with a full compare or reload
Target has a reliable updated_at Recreate at now and backfill with a one-off MERGE filtered on updated_at
CREATE OR REPLACE STREAM raw.orders_strm ON TABLE raw.orders
  AT (TIMESTAMP => '2026-11-20 06:00:00'::TIMESTAMP_LTZ);

CREATE OR REPLACE STREAM drops the grants on the old stream; reapply them (GRANT SELECT ON STREAM raw.orders_strm TO ROLE etl_role;).

Read changes without a stream

With change tracking on, the CHANGES clause reads a window of changes without touching any offset. Good for audits and replays.

SELECT *
FROM raw.orders
  CHANGES (INFORMATION => DEFAULT)
  AT (TIMESTAMP => DATEADD(hour, -2, CURRENT_TIMESTAMP()))
  END (TIMESTAMP => CURRENT_TIMESTAMP());

Use INFORMATION => APPEND_ONLY for inserts only.

Things that break streams

Symptom Cause Fix
Stream invalid or errors after a deploy Source table recreated with CREATE OR REPLACE TABLE Use ALTER TABLE or INSERT OVERWRITE instead; recreate the stream
Stream on a view errors View definition changed, or change tracking off on a base table Enable change tracking on all base tables, recreate the stream
Consumer role gets "does not exist or not authorized" Needs SELECT on the stream and on the source table, plus USAGE on database and schema Grant both, not only the stream
Cloned schema's stream returns nothing Unconsumed records in a cloned stream are not accessible in the clone Recreate streams in the clone with an AT clause if needed
Huge first read SHOW_INITIAL_ROWS = TRUE or an old AT timestamp Expected; size the warehouse for the first run

Prevent it next time

  • One stream per consumer, named for the consumer (orders_strm_core, orders_strm_audit).
  • Alert on stale_after inside two days and on suspended tasks that read streams.
  • Consume related DML inside one explicit transaction.
  • Ban CREATE OR REPLACE TABLE on tables with streams in your deployment tooling (dbt full_refresh, migration scripts).
  • Before discarding stream contents, back them up to a table.