Hi hackers, I recently ran into this issue as well and reproduced it on master. The table had 30,000 live rows, but after six autovacuum runs, pg_class.reltuples had fallen to 1,831.
I've attached a small patch that changes only vacuumlazy.c. When a partial vacuum finds more recently dead tuples than live ones, removes no tuples, and sees no change in the number of heap pages, it uses the previous reltuples estimate as a lower bound. With the patch, the estimate stayed at 30,000 across all six runs. This version includes no test case or other file changes. I can continue updating this patch if needed. The check uses counters VACUUM already collects, so it requires no additional page reads. The trade-off is that if the previous estimate was already too high after a real deletion, a partial vacuum meeting these conditions can retain that overestimate. I'd appreciate a review, particularly of whether these conditions are a reasonable basis for keeping the previous estimate. I'm happy to revise the patch based on feedback. Thanks, Jiao Shuntian
v1-0001-vacuum-reltuples.patch
Description: Binary data
