存储生命周期策略¶
备注
存储生命周期策略 目前在政府区域不可用。
A storage lifecycle policy is a schema-level object that automatically manages the data lifecycle for standard Snowflake tables. Use these policies to archive or expire specific table rows that are based on conditions that you define, such as data age or other criteria. Snowflake automatically executes these policies daily by using shared compute resources.
存储生命周期策略的工作原理¶
To get started with storage lifecycle policies, complete the following steps:
创建一个策略,其中包含用于识别需归档或过期行的表达式。
After you attach a storage lifecycle policy to a table, Snowflake waits approximately 24 hours before running the policy for the first time. Following this initial delay, Snowflake automatically runs the policy daily by using shared compute resources to identify and process rows that meet your defined conditions.
When the policy runs, it checks each row against your expression, and then either archives the data to COOL or COLD storage or expires the data, which deletes it permanently. You can retrieve archived data by using the CREATE TABLE ... FROM ARCHIVE OF command before expiration occurs. Snowflake waits until the specified archive period elapses before expiring the data from archive storage.
主要功能¶
存储生命周期策略为管理 Snowflake 数据提供以下优势。
- 降低存储成本
Storage lifecycle policies help optimize costs by automatically moving older data to more cost-effective archival tiers. For data that must be retained long-term but accessed infrequently, archival storage can significantly reduce storage costs compared to standard storage tiers.
- 法规合规性
通过配置策略以根据监管标准归档或使数据过期,自动满足合规性要求。您可以在数据过期前将其归档特定时长,也可以不经过归档直接使其过期。这可确保您的数据管理遵循组织的治理标准。
- 简单的数据管理
存储生命周期策略通过自动执行归档和过期规则,消除了手动数据管理任务。有关更多信息,请参阅 Monitor storage lifecycle policies。
- 灵活的数据检索
通过创建一个仅包含所需数据行的新表,精确 检索已归档的数据。使用带有 WHERE 子句的简单命令,精确指定要恢复的归档数据。
归档存储层¶
Snowflake 支持将数据归档到以下存储层级:
归档层 |
描述 |
|---|---|
COOL |
提供快速检索时间,确保数据立即可用。最短归档期为 90 天。 |
COLD |
Offers greater cost savings than the COOL tier; it is four times less expensive. The minimum archival period is 180 days. Compared to the COOL tier, COLD has a longer data retrieval time, which is up to 48 hours. Data retrieval operations from the COLD storage tier support a maximum of 1 million files per restore operation. |
选择归档层¶
When you select an archive tier, consider the following factors:
归档成本:两个层的归档数据一次性成本相同。
存储成本:COLD 层的存储费用低于 COOL 层。
检索成本:COLD 层的数据检索费用低于 COOL 层。
检索时间:COOL 存储层提供即时数据检索,而 COLD 层的检索可能需要长达 48 小时。
有关详细定价信息,请参阅 Snowflake 服务消耗表 中的表 3(e) 和 4(f)。
For more information about archiving data, see Create a storage lifecycle policy and Archive storage considerations.
注意事项¶
Consider the following information when you work with storage lifecycle policies.
云提供商支持¶
Expiration policies: Supported for accounts hosted on all cloud providers (Amazon Web Services (AWS), Microsoft Azure, and Google Cloud).
归档策略:目前仅适用于托管在 AWS 上的账户。
支持的表和功能¶
Supported tables: Storage lifecycle policies are supported for standard Snowflake tables. To evaluate and apply storage lifecycle policy expressions, Snowflake internally and temporarily bypasses any governance policies on a table.
复制:
Snowflake 会将存储生命周期策略及其与表的关联复制到目标账户,但不会运行这些策略。
故障转移到目标账户后,Snowflake 会暂停原始主账户中的存储生命周期策略执行。故障恢复至原始主账户后,Snowflake 会恢复策略执行。
即使在故障转移后,Snowflake 也永远不会在辅助表上自动运行辅助存储生命周期策略。但是,您可以通过将辅助策略附加到 新 表的方式,在目标账户中使用它们。对于这些新表,Snowflake 会运行策略。
**克隆*:Snowflake 不会自动将存储生命周期策略应用于克隆表。如果您对克隆组中的某个表应用存储生命周期策略,Snowflake 仅会归档该特定表中的行。该策略不会影响克隆。这会在标准存储层和归档存储层中创建数据副本,您需要为每个层的存储付费。有关成本信息,请参阅 存储生命周期策略计费。
不支持的功能
Storage lifecycle policies aren't supported for the following features:
除常规 Snowflake 表和动态表之外的所有对象类型。
Write once read many (WORM) snapshots, which are immutable snapshots that can't be modified after creation.
Both provider and consumer tables shared through Snowflake data sharing.
原生应用。
具有外部访问权限的用户定义函数 (UDFs) 和外部函数。
Python、Java 或 Scala UDFs。
策略行为和执行¶
存储生命周期策略使用的性能指南与 行级访问策略指南 相似,并具有以下自动运行特征:
当您将存储生命周期策略附加到表时,Snowflake 大约会等待 24 小时才首次运行该策略。
Snowflake 每日使用共享计算资源运行存储生命周期策略。有关存储生命周期策略成本的信息,请参阅 存储生命周期策略计费。
To prevent excessively long archive or expiration runs, Snowflake processes large data operations incrementally in smaller chunks. A large operation might not complete in one daily run and might instead complete across multiple daily runs.
当存储生命周期策略在表上运行时,Snowflake 会锁定 UPDATE、DELETE 和 MERGE 操作。您仍然可以在此期间执行 INSERT 和 COPY 操作。有关更多信息,请参阅 资源锁定。
归档存储策略¶
Consider the following information when you work with tables that have an archival storage lifecycle policy attached:
访问归档数据:Snowflake 归档行后,您无法直接查询它们。要访问这些数据,请使用 CREATE TABLE ... FROM ARCHIVE OF 命令创建一个包含已归档数据副本的新表。有关更多信息,请参阅 检索归档数据。
安全:您可以使用 Tri-Secret Secure (TSS),通过定期密钥轮换来保护归档数据。
Rekeying: Snowflake doesn't rekey archived data. If you suspect a key compromise, perform the following steps:
使用 CREATE TABLE... FROM ARCHIVE OF 命令将归档数据检索到新表中。
Archive data in the new table when needed.
Each table has its own encryption key, so the new table effectively uses a new key.
删除原始表(其密钥已泄露)的归档数据。
归档层限制:
You can't change the archive tier for a policy from COOL to COLD or from COLD to COOL. Create a new policy instead. For instructions, see 重新创建存储生命周期策略.
一个表只能使用一个归档层。您无法将 COLD 策略附加到已使用 COOL 归档的表中。
移除策略:当您从表中移除策略时,已归档的数据仍保留在归档存储中,并且仍可被检索。
移除或截断表:
截断表不会影响该表的已归档数据。截断表后,您仍可从归档存储中检索数据。
当您在适用的 Time Travel 数据保留期 内使用 UNDROP TABLE 恢复表时,Snowflake 也会恢复归档存储中的任何数据。
当表处于 故障安全 期内时,归档存储中的数据或许可以通过联系 Snowflake 支持团队执行故障安全数据恢复步骤来恢复。
在 ARCHIVE_FOR_DAYS 期限届满前删除的归档存储中的表数据仍会产生存储费用。有关更多信息,请参阅 最短存储期限费用。