Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to prevent autovacuum for table in Postgres

I have big tables in which I have only inserts and selects, so when autovacuum for this tables is running - system is very slow. I have switch off autovacuum for specific tables:

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

After this (some time after) I see:

select pid, waiting, xact_start, query_start,query from pg_stat_activity order by query_start;

 18092 | f       | 2014-11-04 22:21:05.95512+03  | 2014-11-04 22:21:05.95512+03  | autovacuum: VACUUM public.ag_event_20141004_20141009 (to prevent wraparound)
 19877 | f       | 2014-11-04 22:22:05.889182+03 | 2014-11-04 22:22:05.889182+03 | autovacuum: VACUUM public.ag_event_20141014_20141019 (to prevent wraparound)

What shell I do to switch autovacuuming for this tables at all ??

like image 681
clarent Avatar asked Nov 04 '14 19:11

clarent


People also ask

Does Autovacuum lock the table?

Autovacuum does take a lock on the table, but it is a weak lock which does not interfere with normal operations (SELECT, UPDATE, DELETE) but will interfere with things like adding indexes, or truncating the table.

How do you check if Autovacuum is enabled in Postgres?

Autovacuum may be disabled on certain tables We can re-enable it by running: ALTER TABLE my_table SET (autovacuum_enabled = true);

What is Autovacuum in Postgres?

PostgreSQL has an optional but highly recommended feature called autovacuum, whose purpose is to automate the execution of VACUUM and ANALYZE commands. When enabled, autovacuum checks for tables that have had a large number of inserted, updated or deleted tuples.

Does Postgres vacuum lock table?

Since VACUUM does not take any exclusive lock on tables, it does not (or minimal) impact other database work. The configuration of Auto-VACUUM should be done based on the usage pattern of the database.


1 Answers

The key here is:

(to prevent wraparound)

This means Postgres must autovacuum in order to free up transaction identifiers.

You can not entirely disable this type of autovacuum, but you can reduce its frequency by tuning the autovacuum_freeze_max_age and vacuum_freeze_min_age parameters.

like image 98
Andomar Avatar answered Sep 21 '22 13:09

Andomar