Storage lifecycle policies

A storage lifecycle policy is a schema-level object attached to one or more tables that lets you archive or delete data in compliance with your defined data expiration timeline.

When you create a storage lifecycle policy, you define an expression that identifies table rows to expire. You can optionally set an archival period, which tells Snowflake to archive the table rows for a specified time period before expiration.

Snowflake automatically runs storage lifecycle policies every 24 hours on shared compute resources.

Key benefits of using storage lifecycle policies:

  • Reduce storage costs.

  • Improve table performance.

Billing

참고

Snowflake plans to introduce charges for running storage lifecycle policies in July 2025. For data in archive storage, Snowflake plans to introduce billing in August 2025.

You can use the following views to get information about credit usage and data retrieval from archive storage for lifecycle policies:

The metering history views include the following service types related to storage lifecycle policies:

  • STORAGE_LIFECYCLE_POLICY_EXECUTION: Compute cost to apply a policy on a target table and expire or archive rows (policy execution).

  • ARCHIVE_STORAGE_WRITE: Cost for writing archived table rows into a lower-cost storage tier.

  • ARCHIVE_STORAGE_RETRIEVAL_FILE_PROCESSING: Cost for processing data retrieved from archive storage.

  • ARCHIVE_STORAGE_DATA_RETRIEVAL: Cost for retrieving data from archive storage.

For more information about billing related to storage lifecycle policy execution, file processing, and data retrieval, see tables 4(f) and 5 in the Snowflake Service Consumption Table.

Considerations

Consider the following information when you create and manage storage lifecycle policies.

  • Storage lifecycle policies use performance guidelines that are similar to guidelines for row-level access policies. For more information, see 정책 성능 지침.

  • Storage lifecycle policies are only supported for standard Snowflake tables.

  • Snowflake disables all governance policies when it evaluates a storage lifecycle policy to ensure that all data can be reviewed for expiration or archiving.

  • Storage lifecycle policies aren’t automatically applied to cloned tables.

  • User-defined functions (UDFs) with external access and external functions aren’t supported.

  • Python, Java, and Scala UDFs aren’t supported.

  • Replication for storage lifecycle policies works as follows:

    • Snowflake replicates storage lifecycle policies and their associations with tables to target accounts, but doesn’t run the policies.

    • After failover to a target account, Snowflake pauses storage lifecycle policy execution in the original primary account. Likewise, after failback to the original primary account, Snowflake resumes policy execution.

    • Snowflake never automatically runs secondary storage lifecycle policies on secondary tables, even after failover. However, you can use secondary policies in a target account by attaching them to new tables. For those new tables, Snowflake runs the policies.

  • For working with tables that have an archival storage lifecycle policy attached:

    • If you delete the table, Snowflake also deletes the archived table rows.

    • You can use Tri-Secret Secure (TSS) to secure archived data with regular TSS key rotation.

    • Snowflake doesn’t rekey archived data.

    • Changing an existing policy from the COOL tier to the COLD tier (or the other way around) isn’t supported. You must create a new and separate policy.

    • Currently, a table can only have data in one archive tier during its lifetime. Attaching a policy to a table that already has archived data in a different tier isn’t supported. For example, you can’t attach a policy that uses the COLD tier to a table that already archives data in the COOL tier.

    • Removing a policy from a table doesn’t delete the data from archive storage. You can still retrieve data from archive storage after removing the policy.

    • Dropping a table doesn’t delete data from archive storage; you can undrop the table to restore archived data. Likewise, truncating the table doesn’t remove data in archive storage.

  • For the CREATE TABLE … FROM ARCHIVE OF command:

    • Using this command requires the OWNERSHIP privilege on the source table.

    • Specifying column definitions, policies, tags, or other constraints isn’t supported. Snowflake automatically retrieves the table schema, policies, tags, and constraints from the source table.

    • The WHERE clause is required. Reading archived data is expensive, and should be performed infrequently. Filtering results using the WHERE clause helps you minimize costs by ensuring that Snowflake reads only the data that you require from archival storage.

    • To retrieve a history of data retrieval from archive storage, use the ARCHIVE_STORAGE_DATA_RETRIEVAL_USAGE_HISTORY view.

    • To retrieve data from the COLD tier of archive storage, Snowflake must first restore the files from external cloud storage. This process can take up to 48 hours.

      To support this process, set the following parameters appropriately:

Archiving data before expiration

When you create a storage lifecycle policy, you can choose an archive tier and optionally set an archival period (in days). If you set an archival period, Snowflake moves table rows that match the policy expression into a lower-cost storage tier for the specified number of days before expiring the rows. Snowflake also enables change tracking on any tables that you attach the policy to.

You can’t query rows after Snowflake archives them to a lower-cost storage tier. However, you can retrieve archived rows during the archival period by using the CREATE TABLE … FROM ARCHIVE OF command. Running the command doesn’t remove the data from archive storage. Instead, Snowflake makes a temporary copy of the archived data in standard storage, and creates a new table.

Snowflake supports archiving data for the following cloud providers and storage tiers:

Archive tier

Description

COOL

Offers fast retrieval time, so data is readily available. The minimum archival period is 90 days.

COLD

Offers greater cost savings than the COOL tier (four times less expensive). The minimum archival period is 180 days. Compared to the COOL tier, COLD has a longer data retrieval time (up to 48 hours).

Storage lifecycle policy workflow

Use the following workflow to get started with storage lifecycle policies.

  1. Set up the required privileges to use and manage storage lifecycle policies.

  2. Create a storage lifecycle policy using CREATE STORAGE LIFECYCLE POLICY.

  3. Add a lifecycle policy to a table. Snowflake runs the storage lifecycle policy daily to archive or expire rows as defined by the policy.

Required privileges

Schema privileges

CREATE STORAGE LIFECYCLE POLICY

Allows the grantee to create a new storage lifecycle policy in a schema.

Schema object privileges

OWNERSHIP

Grants full control of the storage lifecycle policy. This privilege is required to alter the policy. Only one role can have this privilege per lifecycle policy object.

APPLY

Allows the grantee to add or drop the storage lifecycle policy on a table. To add the policy to a table, you must also have the OWNERSHIP privilege for the table or the global APPLY STORAGE LIFECYCLE POLICY privilege on the account.

To make changes to or create a storage lifecycle policy you must also have the USAGE privilege on the parent database and schema. For more information about privileges and grant behavior, see GRANT <privileges> … TO ROLE.

Global privileges

With global privileges the grantee can add or drop the storage lifecycle policy on a table. Granting this privilege also allows the grantee to use the DESCRIBE command on all tables. You can only grant this at the account level.

Global privileges aren’t required to use storage lifecycle policies. For security best practice, use the minimum required privileges described above.

APPLY STORAGE LIFECYCLE POLICY

Storage lifecycle policies DDL commands

You can use the following data definition language (DDL) commands to manage your storage lifecycle policies. These DDLs are similar to other Snowflake row access policies. For more information about row access policies, see 행 액세스 정책 이해하기.

Create a storage lifecycle policy

To create a storage lifecycle policy, use the CREATE STORAGE LIFECYCLE POLICY command.

For example:

CREATE STORAGE LIFECYCLE POLICY example_policy
  AS (event_ts TIMESTAMP, account_id NUMBER)
  RETURNS BOOLEAN ->
    event_ts < DATEADD(DAY, -60, CURRENT_TIMESTAMP())
    AND EXISTS (
      SELECT 1 FROM closed_accounts
      WHERE id = account_id
    )
  ARCHIVE_TIER = COOL
  ARCHIVE_FOR_DAYS = 90;
Copy

Get the data definition to recreate a storage lifecycle policy

This feature extends the GET_DDL command to recreate a specified storage lifecycle policy.

Return the DDL to recreate a storage lifecycle policy named slp.

SELECT GET_DDL('policy','slp');
Copy

Output:

---------------------------------------------------------------------+
                      GET_DDL('POLICY','SLP')                        |
---------------------------------------------------------------------+
create or replace storage lifecycle policy SLP as                    |
  (event_ts timestamp, account_id number)
    returns boolean ->
    event_ts < dateadd(day, -60, current_timestamp())
    and exists (
      select 1 from closed_accounts
      where id = account_id
  )
  ARCHIVE_FOR_DAYS = 365                                                                  |
;                                                                    |
---------------------------------------------------------------------+

Manage storage lifecycle policies on tables

You can use the following commands to manage storage lifecycle policy attachments.

Add a lifecycle policy to a table

You can manage multiple tables with one storage lifecycle policy. Attach the policy when you create or alter the table.

Use CREATE TABLE to create a table and attach the policy to a new table using the specified columns.

CREATE TABLE <table_name>
  ...
  WITH STORAGE LIFECYCLE POLICY <policy_name> ON (<col1>, [<col2>, ...]);
Copy

Use ALTER TABLE to attach the policy to an existing table using the specified columns.

ALTER TABLE <table_name> ADD STORAGE LIFECYCLE POLICY <policy_name>
  ON (<col1>, [<col2, ...]);
Copy
Considerations:
  • The number of columns must match the argument count in the policy function signature, and the column data must be compatible with the argument types.

  • Associated policies aren’t affected if you rename table columns. Snowflake associates policies to tables using the column IDs.

  • A table can have only one attached storage lifecycle policy.

Remove a lifecycle policy from a table

Use ALTER TABLE to remove a storage lifecycle policy from a table.

ALTER TABLE <table_name> DROP STORAGE LIFECYCLE POLICY
Copy
Considerations:
  • This removes all future policy executions for this table.

  • Running policy executions might complete before they are dropped from the table.

  • To drop a storage lifecycle policy, you must have the OWNERSHIP privilege on the table the policy is attached to.

List lifecycle policy attachments

To see which tables a particular lifecycle policy is attached to, you can call the POLICY_REFERENCES table function in the Snowflake Information Schema. The function displays only the tables that you have the OWNERSHIP privilege on.

The function returns a row for each table in a database that has the specified policy attached to it.

For example:

SELECT *
  FROM TABLE(
    my_db.INFORMATION_SCHEMA.POLICY_REFERENCES(
    POLICY_NAME => 'my_storage_lifecycle_policy'
  )
);
Copy

Alternatively, retrieve the policy assigned to a specified table:

SELECT *
  FROM TABLE(
    my_db.INFORMATION_SCHEMA.POLICY_REFERENCES(
      REF_ENTITY_NAME => 'my_db.my_schema.my_table',
      REF_ENTITY_DOMAIN => 'table'))
  WHERE POLICY_KIND = 'STORAGE_LIFECYCLE_POLICY';
Copy

Monitor storage lifecycle policy runs

You can monitor storage lifecycle policy executions over the last 14 days by using the STORAGE_LIFECYCLE_POLICY_HISTORY table function.

The following example retrieves the 100 most recent executions for a policy attached to a specified table, scheduled within the last day:

SELECT * FROM
  TABLE(
    INFORMATION_SCHEMA.STORAGE_LIFECYCLE_POLICY_HISTORY(
      REF_ENTITY_NAME => 'my_db.my_schema.my_source_table',
      REF_ENTITY_DOMAIN => 'table',
      TIME_RANGE_START => DATEADD('DAY', -1, CURRENT_TIMESTAMP()),
      RESULT_LIMIT => 100
    )
  );
Copy

For information about the function output, see the STORAGE_LIFECYCLE_POLICY_HISTORY page.

Retrieve archived data

Read archived data by using the CREATE TABLE … FROM ARCHIVE OF command.

For example, the following statement creates a new table from archived rows where the value in the event_timestamp column is between January 15 and January 20 of 2023.

CREATE TABLE my_table
  FROM ARCHIVE OF my_source_table AS st
  WHERE st.event_timestamp BETWEEN '01/15/2023' AND '01/20/2023';
Copy

참고

  • Using this command requires the OWNERSHIP privilege on the source table.

  • Specifying column definitions, policies, tags, or other constraints isn’t supported. Snowflake automatically retrieves the table schema, policies, tags, and constraints from the source table.

  • The WHERE clause is required. Reading archived data is expensive, and should be performed infrequently. Filtering results using the WHERE clause helps you minimize costs by ensuring that Snowflake reads only the data that you require from archival storage.

  • To retrieve a history of data retrieval from archive storage, use the ARCHIVE_STORAGE_DATA_RETRIEVAL_USAGE_HISTORY view.

  • To retrieve data from the COLD tier of archive storage, Snowflake must first restore the files from external cloud storage. This process can take up to 48 hours.

    To support this process, set the following parameters appropriately:

Syntax

CREATE [ TRANSIENT ] TABLE [ IF NOT EXISTS ] <new_table_name>
  FROM ARCHIVE OF <source_table> [ [ AS ] <alias_name> ]
  WHERE <expression>
Copy

Where:

new_table_name

String that specifies the identifier for the table. This must be unique for the schema.

In addition, the identifier must start with an alphabetic character and cannot contain spaces or special characters unless the entire identifier string is enclosed in double quotes (for example, "My object"). Identifiers enclosed in double quotes are also case-sensitive.

For more information, see 식별자 요구 사항.

source_table

String that specifies the identifier for the source table. The source table is the table whose rows have been archived by a storage lifecycle policy.

[ AS ] alias_name

Specifies an alias name for the source table reference.

Alias names must follow the rules for 오브젝트 식별자.

WHERE expressions

Specifies a condition that acts as a filter on the archived table rows. For more information, see WHERE.