mirror of
https://github.com/postgres/postgres.git
synced 2025-12-21 05:21:08 +03:00
Add vacuum_truncate configuration parameter.
This new parameter works just like the storage parameter of the same name: if set to true (which is the default), autovacuum and VACUUM attempt to truncate any empty pages at the end of the table. It is primarily intended to help users avoid locking issues on hot standbys. The setting can be overridden with the storage parameter or VACUUM's TRUNCATE option. Since there's presently no way to determine whether a Boolean storage parameter is explicitly set or has just picked up the default value, this commit also introduces an isset_offset member to relopt_parse_elt. Suggested-by: Will Storey <will@summercat.com> Author: Nathan Bossart <nathandbossart@gmail.com> Co-authored-by: Gurjeet Singh <gurjeet@singh.im> Reviewed-by: Laurenz Albe <laurenz.albe@cybertec.at> Reviewed-by: Fujii Masao <masao.fujii@oss.nttdata.com> Reviewed-by: Robert Treat <rob@xzilla.net> Discussion: https://postgr.es/m/Z2DE4lDX4tHqNGZt%40dev.null
This commit is contained in:
@@ -236,6 +236,7 @@ SELECT pg_relation_size('vac_truncate_test') > 0;
|
||||
t
|
||||
(1 row)
|
||||
|
||||
SET vacuum_truncate = false;
|
||||
VACUUM (DISABLE_PAGE_SKIPPING) vac_truncate_test;
|
||||
SELECT pg_relation_size('vac_truncate_test') = 0;
|
||||
?column?
|
||||
@@ -244,6 +245,32 @@ SELECT pg_relation_size('vac_truncate_test') = 0;
|
||||
(1 row)
|
||||
|
||||
VACUUM (TRUNCATE FALSE, FULL TRUE) vac_truncate_test;
|
||||
ALTER TABLE vac_truncate_test RESET (vacuum_truncate);
|
||||
INSERT INTO vac_truncate_test VALUES (1, NULL), (NULL, NULL);
|
||||
ERROR: null value in column "i" of relation "vac_truncate_test" violates not-null constraint
|
||||
DETAIL: Failing row contains (null, null).
|
||||
VACUUM (DISABLE_PAGE_SKIPPING) vac_truncate_test;
|
||||
SELECT pg_relation_size('vac_truncate_test') > 0;
|
||||
?column?
|
||||
----------
|
||||
t
|
||||
(1 row)
|
||||
|
||||
RESET vacuum_truncate;
|
||||
VACUUM (TRUNCATE FALSE, DISABLE_PAGE_SKIPPING) vac_truncate_test;
|
||||
SELECT pg_relation_size('vac_truncate_test') > 0;
|
||||
?column?
|
||||
----------
|
||||
t
|
||||
(1 row)
|
||||
|
||||
VACUUM (DISABLE_PAGE_SKIPPING) vac_truncate_test;
|
||||
SELECT pg_relation_size('vac_truncate_test') = 0;
|
||||
?column?
|
||||
----------
|
||||
t
|
||||
(1 row)
|
||||
|
||||
DROP TABLE vac_truncate_test;
|
||||
-- partitioned table
|
||||
CREATE TABLE vacparted (a int, b char) PARTITION BY LIST (a);
|
||||
|
||||
@@ -194,9 +194,19 @@ CREATE TEMP TABLE vac_truncate_test(i INT NOT NULL, j text)
|
||||
INSERT INTO vac_truncate_test VALUES (1, NULL), (NULL, NULL);
|
||||
VACUUM (TRUNCATE FALSE, DISABLE_PAGE_SKIPPING) vac_truncate_test;
|
||||
SELECT pg_relation_size('vac_truncate_test') > 0;
|
||||
SET vacuum_truncate = false;
|
||||
VACUUM (DISABLE_PAGE_SKIPPING) vac_truncate_test;
|
||||
SELECT pg_relation_size('vac_truncate_test') = 0;
|
||||
VACUUM (TRUNCATE FALSE, FULL TRUE) vac_truncate_test;
|
||||
ALTER TABLE vac_truncate_test RESET (vacuum_truncate);
|
||||
INSERT INTO vac_truncate_test VALUES (1, NULL), (NULL, NULL);
|
||||
VACUUM (DISABLE_PAGE_SKIPPING) vac_truncate_test;
|
||||
SELECT pg_relation_size('vac_truncate_test') > 0;
|
||||
RESET vacuum_truncate;
|
||||
VACUUM (TRUNCATE FALSE, DISABLE_PAGE_SKIPPING) vac_truncate_test;
|
||||
SELECT pg_relation_size('vac_truncate_test') > 0;
|
||||
VACUUM (DISABLE_PAGE_SKIPPING) vac_truncate_test;
|
||||
SELECT pg_relation_size('vac_truncate_test') = 0;
|
||||
DROP TABLE vac_truncate_test;
|
||||
|
||||
-- partitioned table
|
||||
|
||||
Reference in New Issue
Block a user