Tech stories

Efficiently RePartitioning Large Tables in PostgreSQL

By Cagri Biroglu, Database Engineer

November 27, 2024
 ·  10 minutes
Illustration of a person interacting with a stylized data server infrastructure.

Partitioning a massive table that already holds data can be challenging, especially when the initial table, or “Mammoth” partition, has all or most of the data. For instance, partitioning an existing 10TB orders table into smaller, monthly partitions requires a strategy that minimizes downtime and efficiently loads data into the new partitions. In this blog post, I’ll explain how we managed such a partitioning scenario in PostgreSQL, leveraging a three-step process to create, load, and switch partitions to have maximum control.This workaround helped us clean data across different database shards, totaling approximately 100TB — all coming from a single table. It became a valuable part of our data archival strategy, particularly for append-only tables where the data does not change after being written.

Fresh insights, straight to your inbox