@phnt @kirby @snacks @VD15 @graf I keep forgetting to mention that I think we really need to change our vacuum settings on our Activites and Objects tables because they're terribly inefficient for our schema.
e.g., I use this:
ALTER TABLE objects SET ( autovacuum_vacuum_scale_factor=0, autovacuum_vacuum_threshold=100 );
the default values are:
autovacuum_vacuum_scale_factor=0.2 (20%)
autovacuum_vacuum_threshold=50
My settings might not be perfect, but they seem to be working very well.
So to explain what we're seeing here: if you have a small table, autovacuum kicks in when 20% of the table + 50 rows has changed -- INSERT, UPDATE, or DELETE. e.g., 1000 rows? When 250 rows change, autovacuum kicks in. Stats get updated. Query plans are better, dead tuples are swept. (NOT the same as a VACUUM FULL / repack, but still good)
Now what happens when you have 50 million activities in your database? With the default scale factor of 0.2, PostgreSQL would wait until ~10 million rows changed before vacuuming. So... it never autovacuums again. Your stats are way stale. Query plans suck ass. And because it does wait so long to autovacuum, when it has to do it there's so much work to do that it's slow. And it can fail to complete because it keeps getting paused for other work.
But by setting it to scale factor of 0 and threshold 100, Postgres now does a very quick and efficient sweep of the table after every 100 rows that change, so my stats stay correct and my query plans are better.
After making this change do a VACUUM FULL, and then never worry about it again. If you don't do a VACUUM FULL after this it might get stuck trying to autovacuum and never complete because there's too much work to do.
More help experimenting to figure out what sane settings we should use on these tables would be appreciated, but mine is running great on my tiny server with 4GB of RAM:
cheese_prod=# select COUNT(1) from activities;
count
----------
10259407
(1 row)
cheese_prod=# select COUNT(1) from objects;
count
---------
6783698
(1 row)
I should really cc
@lain on this :)
edit: this doesn't fix BLOAT, so it won't reduce disk usage, but should keep performance good