PostgreSQL Autovacuum Tuning Calculator
Enter your table's row count, average row size and write rate, plus your current autovacuum settings, and this calculator works out exactly when autovacuum will fire, how many dead tuples and how much bloat the table carries at that moment, how fast a vacuum pass can actually run under cost-based throttling, and whether cleanup keeps up with your writes at all. Pick a table profile and it generates the per-table ALTER TABLE ... SET storage parameters to fix it, along with the pg_stat_user_tables and pg_stat_progress_vacuum queries to verify the result on a live server. Every intermediate number is shown so you can check the arithmetic. Everything runs entirely in your browser — no connection details and no data are sent anywhere.
Do more than postgresql autovacuum tuning calculator — meet Chat2DB
Chat2DB is an AI-powered SQL client for Windows, macOS and Linux. Write SQL in natural language, format and optimize queries automatically, and manage MySQL, PostgreSQL, Oracle and 20+ other databases in one workspace.
How to use
- Fill in the table facts: name, live row count, average row size, and the UPDATE, DELETE and INSERT rates per second that the table sees at peak.
- Enter the autovacuum settings currently in effect (SHOW autovacuum_vacuum_scale_factor, and the reloptions on the table) plus the cost limit, cost delay and worker count.
- Choose a table profile to get suggested overrides, copy the generated ALTER TABLE statement, then run the monitoring queries to confirm dead tuples actually stop piling up.
Frequently asked questions
When does autovacuum trigger on a PostgreSQL table?
Autovacuum vacuums a table once n_dead_tup exceeds autovacuum_vacuum_threshold + autovacuum_vacuum_scale_factor × reltuples, and analyzes it once n_mod_since_analyze exceeds autovacuum_analyze_threshold + autovacuum_analyze_scale_factor × reltuples. With the defaults (threshold 50, scale factor 0.2) a table needs roughly 20% of its rows dead before cleanup starts. Since PostgreSQL 13 there is also an insert-driven trigger, autovacuum_vacuum_insert_threshold + autovacuum_vacuum_insert_scale_factor × reltuples, so append-only tables still get frozen and marked all-visible. The launcher only wakes up every autovacuum_naptime seconds, so that is the finest granularity you get.
What autovacuum settings should I use for a very large table?
Set autovacuum_vacuum_scale_factor to 0 and use a flat autovacuum_vacuum_threshold instead, so the trigger point stops scaling with table size. A common target is about 1% of the table: on 50 million rows that is a threshold of roughly 500,000 dead tuples rather than the 10 million the default 0.2 scale factor implies. Then raise autovacuum_vacuum_cost_limit (1000–3000 is typical on SSD) and keep autovacuum_vacuum_cost_delay at 2 ms so a pass can actually finish before the next one is due. Apply all of it per table with ALTER TABLE ... SET rather than globally.
Why is autovacuum running constantly but the table is still bloated?
The usual cause is that vacuum cannot remove the dead tuples: a long-running transaction, an idle-in-transaction session, an abandoned replication slot or a stale prepared transaction holds back the xmin horizon, so the dead rows are still visible to somebody. Check pg_stat_activity for old xact_start values, pg_replication_slots for inactive slots and pg_prepared_xacts. The other cause is throttling — the cost limit is too low for the write rate, so each pass is slower than the rate at which new dead tuples appear. Chat2DB makes this easy to watch: track dead tuples, vacuum progress and blocking sessions with AI-assisted SQL at https://app.chat2db.ai or download it from https://chat2db.ai/download.
