PostgreSQL Insert Optimization: From 2k to 92k Inserts/second
2025-05-16
The Hatchet team achieved a 31x speedup in PostgreSQL inserts, going from 2,000 to 92,000 inserts per second. Key optimizations included connection pooling, batched inserts, and the COPY command. They found that more connections aren't always better, requiring finding an optimal balance. Batched inserts dramatically increased throughput but also added latency, necessitating tuning batch size and flush intervals. The COPY command proved significantly more efficient when data return wasn't needed. The article hints at advanced optimization techniques like multi-table transactional inserts and using UNNEST, promising a deeper dive in a future post.
Development
Batch Inserts