Postgresql cannot drop a table when autovacuum holds lock on it

lockingpostgresqlpostgresql-9.1vacuum

Autovacuuming process holds RowExclusiveLock and ShareUpdateExclusiveLock on the table, which I want to drop. I read that autovacuum should be canceled automatically, when submitting DROP TABLE command, but it doesn't happen. Maybe I have wrong configuration of postgresql? Furthermore I don't have any delete or update operations of those tables — only inserts and drops. Can I disable autovacuum on those particular tables?

Best Answer

If no delete or update happened, autovacuum shouldn't process the table, per autovacuum_analyze_threshold. See Automatic Vacuuming for the relevant configuration parameters.

You may set log_autovacuum_min_duration to zero to help figure out what's being autovacuumed.

In any case, it is possible to completely disable autovacuum for a particular table, with:

ALTER TABLE tablename SET (autovacuum_enabled = false,  toast.autovacuum_enabled = false);

This is documented in Storage parameters.