Skip to content

In development. Expect rough edges and changes. The source code is not public yet.

Supabase 6 min read How-to mediumAdept

Postgres Bloat Minimization

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.

Related posts

  • 6 tips to optimize storage costs for your Postgres databases

    Neon mediumAdept

    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. Shorter retention saves storage but narrows the point-in-time recovery window. For bloat, look in pg_stat_activity for long-running transactions that block autovacuum.

  • Postgres Support Recap: Investigating Postgres Query Performance

    Neon mediumAdept

    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. A hit ratio below 99% suggests the working set doesn't fit in memory, which calls for more shared_buffers or a larger Neon compute. Bloat is reduced with VACUUM, VACUUM FULL or REINDEX, all of which take locks. PgHero, run via Docker, gives a free dashboard alternative.

  • Performance tips for Neon Postgres

    Neon mediumAdept

    Neon's serverless Postgres follows mostly standard Postgres tuning, plus a few Neon-specific checks. Size compute at roughly 100 connections per GB of RAM, use pooling and autoscaling, then find slow queries with pg_stat_statements and EXPLAIN (ANALYZE, BUFFERS). Fix them with indexes, REINDEX and autovacuum tuning against bloat, and by keeping the local file cache hit ratio (shown in neon_stat_file_cache) above 99%. For faster ingests, batch inserts, drop unused indexes, offload reads to ephemeral read replicas, and test changes safely on a database branch.

  • 1 Year of Autoscaling Postgres: How it’s going, and what’s next

    Neon hardMaster

    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. Over the past year the team replaced cgroup memory.high event triggers with 100ms polling of memory usage for stability, and traced a 0-TPS stall to a kernel bug in ACPI memory hotplug that was fixed by upgrading the kernel. Next steps include sizing compute with a HyperLogLog estimate of working set from LFC page accesses, since a slightly larger cache can yield 10x gains. They are also adding swap, set up via mkswap/swapon on pre-created VMs, and disabling overcommit so up-front allocations like pgvector 0.6's parallel HNSW builds don't OOM.

  • How we scale an open source, multi-tenant storage engine for Postgres written in Rust

    Neon mediumAdept

    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. Large tenants then get I/O that scales with dataset size, and they stop competing with small tenants for resources. All shards subscribe to the Paxos-based Safekeepers and filter WAL down to their own pages, while Postgres routes GetPage@LSN reads directly to the right shard by hashing, with no proxy in between. Tables need to exceed stripe size × shard count (e.g. 2GiB with 8 shards) to use full throughput. Planned work includes shard-aware Safekeepers to cut WAL fan-out cost and shard splitting, since shard count is currently fixed at tenant creation.

The quest for software engineering knowledge.

Look:
Layout: