---
title: "Postgres Bloat Minimization"
description: "Postgres stores table rows in 8KB heap pages and writes a new row version on every update, so dead versions accumulate until vacuum reclaims them and updates the free-space and visibility maps."
url: "https://swe.quest/articles/postgres-bloat-minimization-4680de201e2c3adb"
canonical: "https://supabase.com/blog/postgres-bloat"
source: "Supabase"
published: "2024-04-26"
difficulty: "medium"
kind: "How-to"
reading_minutes: 6
tags: ["postgres","storage-engines","performance"]
---

# Postgres Bloat Minimization

A post on [Supabase](https://swe.quest/sources/supabase.md), published 2024-04-26, 6 min read, How-to. Original: [https://supabase.com/blog/postgres-bloat](https://supabase.com/blog/postgres-bloat)

## Summary

Postgres stores table rows in 8KB heap pages and writes a new row version on every update, so dead versions accumulate until vacuum reclaims them and updates the free-space and visibility maps. Bloat usually means autovacuum never started, because the default 20% scale factor is too high for large tables, or it started but couldn't finish because of long-running idle transactions or SHARE UPDATE EXCLUSIVE locks. The fixes include lowering per-table scale factors, setting idle\_in\_transaction\_session\_timeout, cancelling stuck backends, and raising autovacuum\_max\_workers or autovacuum\_work\_mem. VACUUM FULL or pg\_repack returns space to the filesystem after mass deletes; VACUUM FULL takes an exclusive lock and pg\_repack does not.

Written by swe.quest, not by the author.

**Difficulty:** Medium: assumes a working developer; shows how it is built or done

## Topics

- [PostgreSQL](https://swe.quest/tags/postgres.md) (Data & databases)
- [Storage engines](https://swe.quest/tags/storage-engines.md) (Data & databases)
- [Performance engineering](https://swe.quest/tags/performance.md) (Reliability & operations)

## Prerequisites

- PostgreSQL basics ([easy posts on PostgreSQL](https://swe.quest/tags/postgres.md?difficulty=easy))
- MVCC and transactions ([easy posts on Consistency models](https://swe.quest/tags/consistency.md?difficulty=easy))

## Keywords

PostgreSQL, autovacuum, VACUUM FULL, pg\_repack, Supabase CLI, MVCC

## Related posts

- [6 tips to optimize storage costs for your Postgres databases](https://swe.quest/articles/6-tips-to-optimize-storage-costs-for-your-postgres-databases-11da5e875c34786c.md): Neon · 2024-03-15 · Medium · 4 min read · PostgreSQL, Cost optimization, Storage engines
  Six ways to shrink Postgres storage spend: drop unused indexes (found via pg\_stat\_user\_indexes and pg\_index), avoid full database copies for dev and staging by using Neon's copy-on-write branching, choose smaller data types like SMALLINT, order columns largest to smallest to cut alignment padding, shorten Neon's history retention window, and tune autovacuum to limit bloat.
- [Postgres Support Recap: Investigating Postgres Query Performance](https://swe.quest/articles/postgres-support-recap-investigating-postgres-query-performance-82d2d3f876d71410.md): Neon · 2024-02-29 · Medium · 9 min read · PostgreSQL, Performance engineering, SQL, Observability
  Three starting points for diagnosing slow Postgres queries: use pg\_stat\_statements to find long-running queries by mean execution time and then EXPLAIN ANALYZE them, check the cache hit ratio (in Neon via the neon\_stat\_file\_cache view, since Neon extends shared buffers with a local file cache), and look for table and index bloat caused by MVCC dead tuples.
- [Performance tips for Neon Postgres](https://swe.quest/articles/performance-tips-for-neon-postgres-9739985c47432424.md): Neon · 2024-04-04 · Medium · 8 min read · PostgreSQL, Performance engineering, Serverless, SQL
  Neon's serverless Postgres follows mostly standard Postgres tuning, plus a few Neon-specific checks.
- [1 Year of Autoscaling Postgres: How it’s going, and what’s next](https://swe.quest/articles/1-year-of-autoscaling-postgres-how-it-s-going-and-what-s-next-a75ce75d92118903.md): Neon · 2024-04-15 · Hard · 8 min read · PostgreSQL, Virtualization, Capacity planning, Memory management, Kubernetes
  Neon autoscales Postgres by running each instance as a VM in Kubernetes (NeonVM), with a per-node autoscaler-agent, a modified scheduler, and an in-VM vm-monitor that resizes the Local File Cache.
- [How we scale an open source, multi-tenant storage engine for Postgres written in Rust](https://swe.quest/articles/how-we-scale-an-open-source-multi-tenant-storage-engine-for-postgres-written-in-e5615307ced50afc.md): Neon · 2024-04-15 · Medium · 5 min read · Storage engines, PostgreSQL, Distributed databases, Multi-tenancy, Scaling
  Neon shards its Rust-based Pageserver storage layer by dividing each Postgres relation's 8KiB block numbers into stripes (default 256MiB) and hashing each stripe to a Pageserver.

Browse: [Latest posts](https://swe.quest/index.md) · [Topics](https://swe.quest/tags.md) · [Sources](https://swe.quest/sources.md) · [Topic map](https://swe.quest/map.md) · [Site guide (llms.txt)](https://swe.quest/llms.txt)
