Postgresql – Blocking automatic vaccum

autovacuumpostgresql

I have a table message. I saw that queries for this table where long running and caused a memory leak (scheduled job in java app).

In pg_stat_activity I saw:

wait_event_type wait_event       state
IO              DataFileRead    active

So I increased available disk space, but it didn't solve this problem.

I saw that there was long running autovaccum worker for this table. I checked table size and it was about 90% of available RAM. I renamed this table and created new one with same schema.

So now I have a new table with few records, but the long running autovaccum worker for this table still occurs.

Do you have any ideas what to check, how to tune this table?

Best Answer

You have two problems:

  1. High I/O load:

    This may or may not be caused by autovacuum, but since autovacuum is an important system process, the solution is not to subdue it.

    Tune your queries so that they cause less I/O. If that doesn't suffice, get a faster I/O system or more RAM.

  2. Long running autovacuum workers:

    This can be exacerbated by I/O contention, but the problem is almost always that autovacuum is working too slow. Decrease autovacuum_vacuum_cost_delay to make it faster (but of course that will cause more I/O).

Renaming a table won't make autovacuum go away (dropping would). You will have to let it finish.

Make sure that you have no long running transactions or stale replication slots, otherwise autovacuum cannot do its job properly and keep trying again and again.