Keith Fiske: Auto-archiving and Data Retention Management in Postgres with pg_partman

原文英文,约1800词,阅读约需7分钟。发表于:

You could be saving money every month on databases costs with a smarter data retention policy. One of the primary reasons, and a huge benefit of partitioning is using it to automatically archive your data. For example, you might have a huge log table. For business purposes, you need to keep this data for 30 days. This table grows continually over time and keeping all the data makes database maintenance challenging. With time-based partitioning, you can simply archive off data older than 30 days. The nature of most relational databases means that deleting large volumes of data can be very inefficient and that space is not immediately, if ever, returned to the file system. PostgreSQL does not return the space it reserves to the file system when normal deletion operations are run except under very specific conditions: the page(s) at the end of the relation are completely emptied a VACUUM FULL/CLUSTER is run against the relation (exclusively locking it until complete) If you find yourself needing that space back more immediately, or without intrusive locking, then partitioning can provide a much simpler means of removing old data: drop the table. The removal is nearly instantaneous (barring any transactions locking the table) and immediately returns the space to the file system. pg_partman, the Postgres extension for partitioning, provides a very easy way to manage this for time and integer based partitioning. pg_partman daily partition example Recently pg_partman 5.1 was released that includes new features such as list partitioning for single value integers, controlled maintenance run ordering, and experimental support for numeric partitioning. This new version also includes several bug fixes, so please update to the latest release when possible! All examples were done using this latest version. https://github.com/pgpartman/pg_partman First lets get a simple, time-based daily partition set going CREATE TABLE public.time_stuff (col1 int , col2 text default 'stuff' [...]

通过智能的数据保留策略,每月节省数据库成本。分区可自动归档超过30天的旧数据。pg_partman是Postgres的分区扩展,提供了管理时间和整数分区的简单方法。最新版本pg_partman 5.1包括了新功能,如单值整数的列表分区、控制维护运行顺序以及对数值分区的实验性支持。此外,该版本还包括了一些错误修复。

Keith Fiske: Auto-archiving and Data Retention Management in Postgres with pg_partman
相关推荐 去reddit讨论