Run vacuum multiple times

pull/7334/head
naisila 2023-11-09 17:11:09 +03:00
parent 60e0ab5298
commit 9dc1c40580
No known key found for this signature in database
GPG Key ID: A824BA9862D73E6D
2 changed files with 22 additions and 29 deletions

View File

@ -347,24 +347,14 @@ DETAIL: on server postgres@localhost:xxxxx connectionId: xxxxxxx
-- should not propagate because no distributed table is specified -- should not propagate because no distributed table is specified
insert into local_vacuum_table select i from generate_series(1,1000000) i; insert into local_vacuum_table select i from generate_series(1,1000000) i;
delete from local_vacuum_table; delete from local_vacuum_table;
-- sometimes the vacuum doesn't clean up as expected and results in a flaky result
-- for our tests. For this reason, we re-run the vacuum command once if size of
-- the table before and after the VACUUM is not as expected
SELECT pg_total_relation_size('local_vacuum_table') AS size_before_vacuum \gset
VACUUM local_vacuum_table;
SELECT pg_total_relation_size('local_vacuum_table') AS size_after_vacuum \gset
SELECT :size_before_vacuum <= :size_after_vacuum AS re_vacuum_needed \gset
\if :re_vacuum_needed
SELECT pg_total_relation_size('local_vacuum_table') AS size_before_vacuum \gset
VACUUM local_vacuum_table; VACUUM local_vacuum_table;
VACUUM local_vacuum_table; VACUUM local_vacuum_table;
VACUUM local_vacuum_table; VACUUM local_vacuum_table;
SELECT pg_total_relation_size('local_vacuum_table') AS size_after_vacuum \gset SELECT CASE WHEN s BETWEEN 20000000 AND 49999999 THEN 35000000 ELSE s END size
\endif FROM pg_total_relation_size('local_vacuum_table') s ;
SELECT :size_before_vacuum > :size_after_vacuum AS vacuum_successful; size
vacuum_successful
--------------------------------------------------------------------- ---------------------------------------------------------------------
t 35000000
(1 row) (1 row)
-- vacuum full deallocates pages of dead tuples whereas normal vacuum only marks dead tuples on visibility map -- vacuum full deallocates pages of dead tuples whereas normal vacuum only marks dead tuples on visibility map
@ -413,6 +403,8 @@ VACUUM (DISABLE_PAGE_SKIPPING false) local_vacuum_table;
insert into local_vacuum_table select i from generate_series(1,1000000) i; insert into local_vacuum_table select i from generate_series(1,1000000) i;
delete from local_vacuum_table; delete from local_vacuum_table;
VACUUM (INDEX_CLEANUP OFF, PARALLEL 1) local_vacuum_table; VACUUM (INDEX_CLEANUP OFF, PARALLEL 1) local_vacuum_table;
VACUUM (INDEX_CLEANUP OFF, PARALLEL 1) local_vacuum_table;
VACUUM (INDEX_CLEANUP OFF, PARALLEL 1) local_vacuum_table;
SELECT CASE WHEN s BETWEEN 50000000 AND 70000000 THEN 60000000 ELSE s END size SELECT CASE WHEN s BETWEEN 50000000 AND 70000000 THEN 60000000 ELSE s END size
FROM pg_total_relation_size('local_vacuum_table') s ; FROM pg_total_relation_size('local_vacuum_table') s ;
size size
@ -423,6 +415,8 @@ FROM pg_total_relation_size('local_vacuum_table') s ;
insert into local_vacuum_table select i from generate_series(1,1000000) i; insert into local_vacuum_table select i from generate_series(1,1000000) i;
delete from local_vacuum_table; delete from local_vacuum_table;
VACUUM (INDEX_CLEANUP ON, PARALLEL 1) local_vacuum_table; VACUUM (INDEX_CLEANUP ON, PARALLEL 1) local_vacuum_table;
VACUUM (INDEX_CLEANUP ON, PARALLEL 1) local_vacuum_table;
VACUUM (INDEX_CLEANUP ON, PARALLEL 1) local_vacuum_table;
SELECT CASE WHEN s BETWEEN 20000000 AND 49999999 THEN 35000000 ELSE s END size SELECT CASE WHEN s BETWEEN 20000000 AND 49999999 THEN 35000000 ELSE s END size
FROM pg_total_relation_size('local_vacuum_table') s ; FROM pg_total_relation_size('local_vacuum_table') s ;
size size
@ -434,10 +428,14 @@ FROM pg_total_relation_size('local_vacuum_table') s ;
insert into local_vacuum_table select i from generate_series(1,1000000) i; insert into local_vacuum_table select i from generate_series(1,1000000) i;
delete from local_vacuum_table; delete from local_vacuum_table;
vacuum (TRUNCATE false) local_vacuum_table; vacuum (TRUNCATE false) local_vacuum_table;
vacuum (TRUNCATE false) local_vacuum_table;
vacuum (TRUNCATE false) local_vacuum_table;
SELECT pg_total_relation_size('local_vacuum_table') as size1 \gset SELECT pg_total_relation_size('local_vacuum_table') as size1 \gset
insert into local_vacuum_table select i from generate_series(1,1000000) i; insert into local_vacuum_table select i from generate_series(1,1000000) i;
delete from local_vacuum_table; delete from local_vacuum_table;
vacuum (TRUNCATE true) local_vacuum_table; vacuum (TRUNCATE true) local_vacuum_table;
vacuum (TRUNCATE true) local_vacuum_table;
vacuum (TRUNCATE true) local_vacuum_table;
SELECT pg_total_relation_size('local_vacuum_table') as size2 \gset SELECT pg_total_relation_size('local_vacuum_table') as size2 \gset
SELECT :size1 > :size2 as truncate_less_size; SELECT :size1 > :size2 as truncate_less_size;
truncate_less_size truncate_less_size

View File

@ -228,24 +228,11 @@ VACUUM;
-- should not propagate because no distributed table is specified -- should not propagate because no distributed table is specified
insert into local_vacuum_table select i from generate_series(1,1000000) i; insert into local_vacuum_table select i from generate_series(1,1000000) i;
delete from local_vacuum_table; delete from local_vacuum_table;
-- sometimes the vacuum doesn't clean up as expected and results in a flaky result
-- for our tests. For this reason, we re-run the vacuum command once if size of
-- the table before and after the VACUUM is not as expected
SELECT pg_total_relation_size('local_vacuum_table') AS size_before_vacuum \gset
VACUUM local_vacuum_table;
SELECT pg_total_relation_size('local_vacuum_table') AS size_after_vacuum \gset
SELECT :size_before_vacuum <= :size_after_vacuum AS re_vacuum_needed \gset
\if :re_vacuum_needed
SELECT pg_total_relation_size('local_vacuum_table') AS size_before_vacuum \gset
VACUUM local_vacuum_table; VACUUM local_vacuum_table;
VACUUM local_vacuum_table; VACUUM local_vacuum_table;
VACUUM local_vacuum_table; VACUUM local_vacuum_table;
SELECT pg_total_relation_size('local_vacuum_table') AS size_after_vacuum \gset SELECT CASE WHEN s BETWEEN 20000000 AND 49999999 THEN 35000000 ELSE s END size
\endif FROM pg_total_relation_size('local_vacuum_table') s ;
SELECT :size_before_vacuum > :size_after_vacuum AS vacuum_successful;
-- vacuum full deallocates pages of dead tuples whereas normal vacuum only marks dead tuples on visibility map -- vacuum full deallocates pages of dead tuples whereas normal vacuum only marks dead tuples on visibility map
VACUUM FULL local_vacuum_table; VACUUM FULL local_vacuum_table;
@ -272,12 +259,16 @@ VACUUM (DISABLE_PAGE_SKIPPING false) local_vacuum_table;
insert into local_vacuum_table select i from generate_series(1,1000000) i; insert into local_vacuum_table select i from generate_series(1,1000000) i;
delete from local_vacuum_table; delete from local_vacuum_table;
VACUUM (INDEX_CLEANUP OFF, PARALLEL 1) local_vacuum_table; VACUUM (INDEX_CLEANUP OFF, PARALLEL 1) local_vacuum_table;
VACUUM (INDEX_CLEANUP OFF, PARALLEL 1) local_vacuum_table;
VACUUM (INDEX_CLEANUP OFF, PARALLEL 1) local_vacuum_table;
SELECT CASE WHEN s BETWEEN 50000000 AND 70000000 THEN 60000000 ELSE s END size SELECT CASE WHEN s BETWEEN 50000000 AND 70000000 THEN 60000000 ELSE s END size
FROM pg_total_relation_size('local_vacuum_table') s ; FROM pg_total_relation_size('local_vacuum_table') s ;
insert into local_vacuum_table select i from generate_series(1,1000000) i; insert into local_vacuum_table select i from generate_series(1,1000000) i;
delete from local_vacuum_table; delete from local_vacuum_table;
VACUUM (INDEX_CLEANUP ON, PARALLEL 1) local_vacuum_table; VACUUM (INDEX_CLEANUP ON, PARALLEL 1) local_vacuum_table;
VACUUM (INDEX_CLEANUP ON, PARALLEL 1) local_vacuum_table;
VACUUM (INDEX_CLEANUP ON, PARALLEL 1) local_vacuum_table;
SELECT CASE WHEN s BETWEEN 20000000 AND 49999999 THEN 35000000 ELSE s END size SELECT CASE WHEN s BETWEEN 20000000 AND 49999999 THEN 35000000 ELSE s END size
FROM pg_total_relation_size('local_vacuum_table') s ; FROM pg_total_relation_size('local_vacuum_table') s ;
@ -285,11 +276,15 @@ FROM pg_total_relation_size('local_vacuum_table') s ;
insert into local_vacuum_table select i from generate_series(1,1000000) i; insert into local_vacuum_table select i from generate_series(1,1000000) i;
delete from local_vacuum_table; delete from local_vacuum_table;
vacuum (TRUNCATE false) local_vacuum_table; vacuum (TRUNCATE false) local_vacuum_table;
vacuum (TRUNCATE false) local_vacuum_table;
vacuum (TRUNCATE false) local_vacuum_table;
SELECT pg_total_relation_size('local_vacuum_table') as size1 \gset SELECT pg_total_relation_size('local_vacuum_table') as size1 \gset
insert into local_vacuum_table select i from generate_series(1,1000000) i; insert into local_vacuum_table select i from generate_series(1,1000000) i;
delete from local_vacuum_table; delete from local_vacuum_table;
vacuum (TRUNCATE true) local_vacuum_table; vacuum (TRUNCATE true) local_vacuum_table;
vacuum (TRUNCATE true) local_vacuum_table;
vacuum (TRUNCATE true) local_vacuum_table;
SELECT pg_total_relation_size('local_vacuum_table') as size2 \gset SELECT pg_total_relation_size('local_vacuum_table') as size2 \gset
SELECT :size1 > :size2 as truncate_less_size; SELECT :size1 > :size2 as truncate_less_size;