We run multiple Postgres clusters in our infrastructure with 10-30 DB per cluster, ranging from 10 GB size to 1TB in size. I have recently noticed that on all our clusters the wraparound id is always close to the 10% threshold for aggressive auto vacuums. This has caused some instances where heavy active tables got locked to reduce the transaction id's which has some impact on user experience.
Example outputs of age query
datname | age | current_setting
-------------+-----------+-----------------
db1 | 199952474 | 200000000
db2 | 199808560 | 200000000
db3 | 199432374 | 200000000
db4 | 199409271 | 200000000
db5 | 198777642 | 200000000
db6 | 198333349 | 200000000
db7 | 198113424 | 200000000
Query used
SELECT datname
, age(datfrozenxid)
, current_setting('autovacuum_freeze_max_age')
FROM pg_database
ORDER BY 2 DESC;
We are running Postgres 12.9 clusters. Servers are running at about 25% CPU load. Our vacuum settings
#------------------------------------------------------------------------------
# AUTOVACUUM
#------------------------------------------------------------------------------
autovacuum = on
autovacuum_work_mem = 1GB
#log_autovacuum_min_duration = -1
autovacuum_max_workers = 20
autovacuum_naptime = 1min
autovacuum_vacuum_threshold = 50
autovacuum_analyze_threshold = 50
autovacuum_vacuum_scale_factor = 0.02
autovacuum_analyze_scale_factor = 0.01
autovacuum_freeze_max_age = 200000000
#autovacuum_multixact_freeze_max_age = 400000000
#autovacuum_vacuum_cost_delay = 2ms
#autovacuum_vacuum_cost_limit = -1
So our schemas remain the same, but the size of our tables may vary significantly depending on the client. I am aware that I can tune auto vacuum per table, but this is not practical in our environment.
So my question is as follow.
- Is it expected behaviour for auto vacuum to remain close to my 10% threshold?
- Is there some tunning I am missing which would say to Postgres vacuum tables after X amount of time even if nothing has changed.
Appreciate any help you can offer.