=> SELECT pid, backend_start, backend_type FROM pg_stat_activity WHERE backend_type = 'autovacuum launcher';
pid | backend_start | backend_type ------+-------------------------------+--------------------- 9839 | 2019-03-31 15:24:10.132245+03 | autovacuum launcher (1 row)
=> ALTER SYSTEM SET autovacuum = off;
ALTER SYSTEM
=> SELECT pg_reload_conf();
pg_reload_conf ---------------- t (1 row)
=> SELECT pid, backend_start, backend_type FROM pg_stat_activity WHERE backend_type = 'autovacuum launcher';
pid | backend_start | backend_type -----+---------------+-------------- (0 rows)
=> CREATE DATABASE admin_maintenance;
CREATE DATABASE
=> \c admin_maintenance
You are now connected to database "admin_maintenance" as user "postgres".
=> CREATE TABLE t(n numeric);
CREATE TABLE
=> CREATE INDEX t_n on t(n);
CREATE INDEX
=> INSERT INTO t SELECT random() FROM generate_series(1,100000);
INSERT 0 100000
=> \set SIZE 'SELECT pg_size_pretty(pg_table_size(''t'')) table_size, pg_size_pretty(pg_indexes_size(''t'')) index_size;'
=> :SIZE
table_size | index_size ------------+------------ 3960 kB | 3464 kB (1 row)
=> UPDATE t SET n=n WHERE n < 0.5;
UPDATE 49901
=> :SIZE
table_size | index_size ------------+------------ 5928 kB | 5160 kB (1 row)
=> UPDATE t SET n=n WHERE n < 0.5;
UPDATE 49901
=> :SIZE
table_size | index_size ------------+------------ 7888 kB | 6904 kB (1 row)
=> UPDATE t SET n=n WHERE n < 0.5;
UPDATE 49901
=> :SIZE
table_size | index_size ------------+------------ 9848 kB | 8568 kB (1 row)
Размер таблицы и индекса постоянно растет.
=> VACUUM FULL t;
VACUUM
=> :SIZE
table_size | index_size ------------+------------ 3944 kB | 2664 kB (1 row)
Размер таблицы практически вернулся к начальному, индекс стал компактнее (построить индекс по большому объему данных эффективнее, чем добавлять эти данные к индексу построчно).
=> UPDATE t SET n=n WHERE n < 0.5;
UPDATE 49901
=> VACUUM t;
VACUUM
=> :SIZE
table_size | index_size ------------+------------ 5936 kB | 3992 kB (1 row)
=> UPDATE t SET n=n WHERE n < 0.5;
UPDATE 49901
=> VACUUM t;
VACUUM
=> :SIZE
table_size | index_size ------------+------------ 5936 kB | 3992 kB (1 row)
=> UPDATE t SET n=n WHERE n < 0.5;
UPDATE 49901
=> VACUUM t;
VACUUM
=> :SIZE
table_size | index_size ------------+------------ 5936 kB | 3992 kB (1 row)
Размер увеличился один раз и затем стабилизировался.
=> ALTER SYSTEM SET autovacuum = on;
ALTER SYSTEM
=> SELECT pg_reload_conf();
pg_reload_conf ---------------- t (1 row)