Partitioning very large tables with Django and PostgreSQL
summary
A real production case has a 3 TB table with 9 billion rows receiving 20–30 million updates per day, where autovacuuming takes 16–20 hours and blocks schema work. The chosen solution is range partitioning on the primary key using an mammoth-first partition technique: rename the table, create a partitioned table, attach the old table as the first partition, add an empty new partition, and perform fast metadata-only constraints and an atomic switch via a custom Django migration to avoid copying all data.
AI-written summary · about
chapters (22)
- 0:00Introduction and speaker welcome
- 1:05Speaker introduction and background
- 3:12What is table partitioning?
- 6:22Partitioning as a leaky abstraction
- 7:27Why partition tables?
- 8:30When to consider partitioning
- 8:51Key partitioning decisions
- 10:14Partitioning design principles
- 10:56Partition pruning explained
- 12:22Partitioning limitations
- 13:03Django and partitioning
- 14:47Tools for partitioning in Django
- 15:30Case study workflows step table
- 16:56Choosing partition key
- 19:05Online partitioning method
- 21:31Partitioning process details
- 25:04SQL for partitioning workflow
- 26:09Query performance after partitioning
- 27:37Current status and next steps
- 28:00Caveats and schema changes
- 28:41Conclusions and takeaways
- 29:02Q&A session
