Home / Data Platform / Warehouses

Data PlatformChecklistIntermediate

Snowflake zero-copy clone to refresh dev or test: a checklist for grants, tasks, pipes, streams and stages

Refresh a dev or test database from production with a zero-copy clone without breaking it, leaking prod access or letting cloned tasks, pipes and stages touch production.

Deepak Bhardwaj7 min read

Applies toSnowflake (all editions); CREATE DATABASE/SCHEMA ... CLONE

Goal

You want dev or test to have production-shaped data, refreshed on demand, in minutes and without paying for a second copy of storage. CREATE DATABASE ... CLONE does that. It also copies grants, task definitions, pipes and stage definitions that still point at production. Some of those come back suspended, and some still point at production. Work through this checklist on every refresh.

Before you clone

  • Decide what you clone. A full database clone keeps sequences and cross-schema references consistent. A schema clone is smaller but tables using sequences in another schema keep pointing at the source sequence.
  • Confirm the role. The cloning role needs USAGE on the source database, SELECT on tables, and OWNERSHIP on pipes, streams, tasks and alerts it should clone. Without those, the clone fails or objects are missing from it. Compare object counts afterwards.
  • Check retention if you clone a point in time. Cloning AT a timestamp fails if a child table no longer has Time Travel data for that point.
SHOW TABLES IN DATABASE analytics_prod;   -- retention_time column, in days
SELECT table_schema, table_name, retention_time
FROM analytics_prod.information_schema.tables
WHERE retention_time = 0 AND table_type = 'BASE TABLE';
  • Watch for DML during the clone. Cloning doesn't lock the source and isn't instant on large databases. If a table has 0 days retention and a job purges data mid-clone, the clone fails with 000707 (02000): Data is not available. Pause heavy loads or raise retention to 1 day first.
  • Check data sensitivity. A clone contains real production data. Masking and row access policies in the same database are remapped to the clone, but anyone with unmasked access in dev sees real PII. Get sign-off before cloning regulated data into a lower environment.

Run the clone

Clone into a new database and swap it in, so a failed clone doesn't leave dev empty:

USE ROLE dev_refresh_admin;

CREATE DATABASE analytics_dev_new
  CLONE analytics_prod
  AT (TIMESTAMP => '2026-11-17 06:00:00'::TIMESTAMP_LTZ)
  IGNORE TABLES WITH INSUFFICIENT DATA RETENTION
  INCLUDE INTERNAL STAGES;

ALTER DATABASE analytics_dev SWAP WITH analytics_dev_new;

Notes:

  • Without AT/BEFORE, the clone uses the state as of the statement start.
  • Cast the timestamp explicitly. An uncast string is treated as TIMESTAMP_NTZ, so the point in time may be hours off.
  • IGNORE TABLES WITH INSUFFICIENT DATA RETENTION skips tables that can't be cloned at that point instead of failing the whole statement. Check afterwards which ones are missing.
  • INCLUDE INTERNAL STAGES copies named internal stages (and their files, if the stage has a directory table). This incurs a file copy charge. Leave it out if dev doesn't need them.

Caution

CREATE OR REPLACE DATABASE analytics_dev CLONE ... drops the current dev database, including any work developers have not committed elsewhere. Use the swap pattern, keep analytics_dev_new (now holding the old dev) for a day, then drop it.

After the clone: object by object

Object Behaviour in the clone Action
Child object grants Copied, including grants to production roles Re-own and re-grant (below)
Database/schema grants Not copied on the container itself Grant USAGE to dev roles
Tasks Suspended Resume only the ones dev needs, after checking targets
Alerts Suspended Resume deliberately; fix recipients
Pipes (external stage) Cloned; paused, or STOPPED_CLONED if auto-ingest Usually leave stopped
Pipes (internal stage) Not cloned Recreate if needed
Streams Unconsumed records are inaccessible; history starts at clone time Expect empty streams; recreate if offsets matter
External tables Not cloned Recreate from DDL
External stages Cloned, same storage URL and integration Repoint to dev storage
Table stages Cloned empty Nothing, or reload files
Views, procedures Keep their original definition text Find fully qualified references to prod
Clustered tables Clustering key kept, Automatic Clustering suspended Leave suspended in dev to save credits

Grants and ownership

Child objects keep their grants, so production reader roles may be able to read dev tables, and objects are owned by production roles. Hand ownership to the dev owner role and drop the copied grants:

USE ROLE securityadmin;
GRANT OWNERSHIP ON ALL TABLES  IN DATABASE analytics_dev TO ROLE dev_owner REVOKE CURRENT GRANTS;
GRANT OWNERSHIP ON ALL VIEWS   IN DATABASE analytics_dev TO ROLE dev_owner REVOKE CURRENT GRANTS;
GRANT OWNERSHIP ON ALL SCHEMAS IN DATABASE analytics_dev TO ROLE dev_owner REVOKE CURRENT GRANTS;

GRANT USAGE ON DATABASE analytics_dev TO ROLE dev_reader;
GRANT USAGE ON ALL SCHEMAS IN DATABASE analytics_dev TO ROLE dev_reader;
GRANT SELECT ON ALL TABLES IN DATABASE analytics_dev TO ROLE dev_reader;

Check what's left:

SHOW GRANTS ON SCHEMA analytics_dev.marts;
SHOW GRANTS ON TABLE  analytics_dev.marts.fct_orders;

Repeat the ownership step for tasks, streams, sequences, stages and procedures your environment uses. Cloned tasks start suspended; keep them that way until ownership and targets are sorted.

References that still point at production

The clone keeps the original definition text. A view written as analytics_prod.raw.orders still reads production from dev, and a task that writes to analytics_prod.marts.x would write to production if resumed.

SELECT table_schema, table_name
FROM analytics_dev.information_schema.views
WHERE view_definition ILIKE '%ANALYTICS_PROD.%';

SHOW TASKS IN DATABASE analytics_dev;
SELECT "name", "state", "definition"
FROM TABLE(RESULT_SCAN(LAST_QUERY_ID()))
WHERE "definition" ILIKE '%ANALYTICS_PROD%';

SELECT procedure_schema, procedure_name
FROM analytics_dev.information_schema.procedures
WHERE procedure_definition ILIKE '%ANALYTICS_PROD%';

Rewrite those objects with CREATE OR REPLACE against the dev names. Better long term: write code without the database name, or template it (dbt targets do this).

Tasks, pipes and stages

Warning

Cloned external stages and pipes point at the same bucket or container as production. Resuming a cloned auto-ingest pipe makes dev load production files. An unload (COPY INTO @stage) from dev writes into production storage. Repoint stages before anyone uses them.

SHOW STAGES IN DATABASE analytics_dev;   -- check url and storage_integration
ALTER STAGE analytics_dev.raw.landing SET URL = 's3://company-dev-landing/orders/';

SHOW PIPES IN DATABASE analytics_dev;
SELECT SYSTEM$PIPE_STATUS('analytics_dev.raw.orders_pipe');

The storage integration must allow the dev location (STORAGE_ALLOWED_LOCATIONS). Only resume tasks once their targets and stages are confirmed dev-only:

ALTER TASK analytics_dev.marts.refresh_orders RESUME;

For a task graph, SELECT SYSTEM$TASK_DEPENDENTS_ENABLE('analytics_dev.marts.root_task'); resumes the root and its children together.

Cost check

A clone is free until data changes. After that, each side pays for its own changed micro-partitions, and a long-lived dev clone keeps production's old partitions alive after production deletes them.

SELECT table_catalog, table_schema, table_name,
       active_bytes / POWER(1024, 3)              AS active_gb,
       retained_for_clone_bytes / POWER(1024, 3)  AS retained_for_clone_gb
FROM snowflake.account_usage.table_storage_metrics
WHERE table_catalog IN ('ANALYTICS_PROD', 'ANALYTICS_DEV')
  AND deleted = FALSE
ORDER BY retained_for_clone_bytes DESC
LIMIT 20;

High retained_for_clone_bytes on production tables means old clones are holding storage. Drop clones you no longer need, including the swapped-out analytics_dev_new.

Prevent it next time

  • Put the whole refresh (clone, swap, re-own, re-grant, repoint stages, rewrite prod references) in one script run by a dedicated role, and set ALTER SESSION SET QUERY_TAG = 'dev-refresh'; so it's easy to audit.
  • Keep dev-only stage URLs and grants in that script, so a refresh never leaves dev pointing at prod storage.
  • Never resume tasks or pipes as part of the automated refresh; make it a separate, reviewed step.
  • Remove database names from views, tasks and procedures so clones work without rewrites.
  • Schedule refreshes outside heavy load windows and keep retention at 1 day or more on tables you clone.
  • Review retained_for_clone_bytes monthly and drop stale clones.