mirror of
https://github.com/postgres/postgres.git
synced 2025-12-10 14:22:35 +03:00
Add TRUNCATE parameter to VACUUM.
This commit adds new parameter to VACUUM command, TRUNCATE, which specifies that VACUUM should attempt to truncate off any empty pages at the end of the table and allow the disk space for the truncated pages to be returned to the operating system. This parameter, if specified, overrides the vacuum_truncate reloption. If neither the reloption nor the VACUUM option is used, the default is true, as before. Author: Fujii Masao Reviewed-by: Julien Rouhaud, Masahiko Sawada Discussion: https://postgr.es/m/CAD21AoD+qtrSDL=GSma4Wd3kLYLeRC0hPna-YAdkDeV4z156vg@mail.gmail.com
This commit is contained in:
@@ -88,6 +88,28 @@ VACUUM (INDEX_CLEANUP FALSE, FREEZE TRUE) vaccluster;
|
||||
-- index cleanup option is ignored if VACUUM FULL
|
||||
VACUUM (INDEX_CLEANUP TRUE, FULL TRUE) no_index_cleanup;
|
||||
VACUUM (FULL TRUE) no_index_cleanup;
|
||||
-- TRUNCATE option
|
||||
CREATE TABLE vac_truncate_test(i INT NOT NULL, j text)
|
||||
WITH (vacuum_truncate=true, autovacuum_enabled=false);
|
||||
INSERT INTO vac_truncate_test VALUES (1, NULL), (NULL, NULL);
|
||||
ERROR: null value in column "i" violates not-null constraint
|
||||
DETAIL: Failing row contains (null, null).
|
||||
VACUUM (TRUNCATE FALSE) vac_truncate_test;
|
||||
SELECT pg_relation_size('vac_truncate_test') > 0;
|
||||
?column?
|
||||
----------
|
||||
t
|
||||
(1 row)
|
||||
|
||||
VACUUM vac_truncate_test;
|
||||
SELECT pg_relation_size('vac_truncate_test') = 0;
|
||||
?column?
|
||||
----------
|
||||
t
|
||||
(1 row)
|
||||
|
||||
VACUUM (TRUNCATE FALSE, FULL TRUE) vac_truncate_test;
|
||||
DROP TABLE vac_truncate_test;
|
||||
-- partitioned table
|
||||
CREATE TABLE vacparted (a int, b char) PARTITION BY LIST (a);
|
||||
CREATE TABLE vacparted1 PARTITION OF vacparted FOR VALUES IN (1);
|
||||
|
||||
@@ -71,6 +71,17 @@ VACUUM (INDEX_CLEANUP FALSE, FREEZE TRUE) vaccluster;
|
||||
VACUUM (INDEX_CLEANUP TRUE, FULL TRUE) no_index_cleanup;
|
||||
VACUUM (FULL TRUE) no_index_cleanup;
|
||||
|
||||
-- TRUNCATE option
|
||||
CREATE TABLE vac_truncate_test(i INT NOT NULL, j text)
|
||||
WITH (vacuum_truncate=true, autovacuum_enabled=false);
|
||||
INSERT INTO vac_truncate_test VALUES (1, NULL), (NULL, NULL);
|
||||
VACUUM (TRUNCATE FALSE) vac_truncate_test;
|
||||
SELECT pg_relation_size('vac_truncate_test') > 0;
|
||||
VACUUM vac_truncate_test;
|
||||
SELECT pg_relation_size('vac_truncate_test') = 0;
|
||||
VACUUM (TRUNCATE FALSE, FULL TRUE) vac_truncate_test;
|
||||
DROP TABLE vac_truncate_test;
|
||||
|
||||
-- partitioned table
|
||||
CREATE TABLE vacparted (a int, b char) PARTITION BY LIST (a);
|
||||
CREATE TABLE vacparted1 PARTITION OF vacparted FOR VALUES IN (1);
|
||||
|
||||
Reference in New Issue
Block a user