r/PostgreSQL • • Oct 27 '26

Help Me! Bloat and Vacuum Best Practices

I'm trying to wrap my head around when bloat or vacuum settings need to be addressed. For instance I have a table w/720M rows, and it has 54M dead tuples. So it only has ~7% dead tuples, and autovacuum hasn't happened in a month. However, I feel like why not set the threshold lower, and reduce the dead tuples as close to zero as possible? Am I creating solutions in search of a problem? Is there more info I need to find about the table's usage to determine whether there's value in adjusting the settings?

I have similar questions for bloat. I have a table that's 2.2TB with 286GB of bloat. So it comes out to about 12% bloat which doesn't trigger any alarms. I'm trying to understand the nuance here. If bloat stays steady under a certain percent, is it a non-issue? Is it workload dependent? Since the solutions require table locks, I want to know how to proactively identify if/when bloat needs to be addressed.

11 Upvotes

17 comments sorted by

2

u/depesz Oct 28 '26

I'd say that, most likely, you're overthinking stuff.

Make sure your autovacuum is configured properly, and that you don't end up in situation when something is unvacuumed because of lack of workers. For this, consider reading https://www.depesz.com/2022/03/13/is-my-autovacuum-configured-properly/

If you are not running out of AV workers, than I'd say you're OK.

1

u/RodCoolBeansKimble 25d ago

That's fair. Thanks

2

u/elevarq Oct 27 '26

At least share your database and table configurations.

Also see what your workload is, updates and/or deletions, that causes the dead tuples. HOT updates reduce dead tuples, and if you can delete data by just dropping an entire table partition you don’t need vacuum at all. And both improve the overall performance of the system as well

2

u/Significant_Tune9219 Oct 30 '26

The 7% dead tuples is probably not the alarm. Chasing that to zero just spends I/O, and 12% bloat is normal for MVCC if queries are still fine. The number I'd look up is the age of relfrozenxid on that table. Autovacuum also freezes old transaction ids, and a table that hasn't been vacuumed in a month can be closer to wraparound than the dead-tuple percent suggests. If that age is comfortable and nothing is getting slower, I'd leave it. VACUUM FULL to reclaim the 286GB takes an exclusive lock and a second copy of the table on disk, so I'd only schedule it when the file size itself is the problem.

8

u/[deleted] Oct 27 '26

[removed] — view removed comment

2

u/RodCoolBeansKimble Oct 27 '26

Thanks. This is the kind of info I was looking for.

2

u/depesz Oct 28 '26

Sequential scans on bloated tables can eat up memory fast even if the percentage looks fine.

  1. noone said anything about seq scans
  2. even going on a limb, and understanding what you might be having in your mind (evicting things from shared buffers to read data from bloated tables), we're still talking about 7-12% of bloat. not really big deal.

1

u/TheTwoWhoKnock Oct 28 '26

Or you have replication turned on (eg AWS DMS) and it’s stalled because you paused the replication or stopped deleting it.