I have been asked to temporarily disable autovacuum in PostgreSQL 14.3. From 7 a.m. to 5 p.m., autovacuum is to be turned off, and at other times it is to be turned back on. I intend to achieve this by setting the command
psql -c "ALTER SYSTEM SET autovacuum = off;" && psql -c "SELECT PG_RELOAD_CONF();"
and
psql -c "ALTER SYSTEM SET autovacuum = on;" && psql -c "SELECT PG_RELOAD_CONF();"
in cron at appropriate times. I checked this solution on a test database, and everything works as it should.
Question for you community: do you see any risks associated with such a solution on the production database? The solution is designed to eliminate performance problems during peak hours.
Is the solution presented in the description correct?
Your solution is a good way to achieve what you intend to do.
However, I doubt the sanity of the measure. Disabling autovacuum for 10 hours may lead to a lot of bloat on busy tables that may well drive your application into the ground. If autovacuum consumes too many resources, you can either tune it to consume less or (if you need it to be fast) use stronger hardware.
If you have a table or two where autovacuum gives you trouble (and these are large tables), you could disable autovacuum only on those with
Again, I would doubt the sanity of the measure, but at least it would not affect all tables.