1
0
mirror of https://github.com/postgres/postgres.git synced 2025-07-28 23:42:10 +03:00

Add vacuum_truncate reloption.

vacuum_truncate controls whether vacuum tries to truncate off
any empty pages at the end of the table. Previously vacuum always
tried to do the truncation. However, the truncation could cause
some problems; for example, ACCESS EXCLUSIVE lock needs to
be taken on the table during the truncation and can cause
the query cancellation on the standby even if hot_standby_feedback
is true. Setting this reloption to false can be helpful to avoid
such problems.

Author: Tsunakawa Takayuki
Reviewed-By: Julien Rouhaud, Masahiko Sawada, Michael Paquier, Kirk Jamison and Fujii Masao
Discussion: https://postgr.es/m/CAHGQGwE5UqFqSq1=kV3QtTUtXphTdyHA-8rAj4A=Y+e4kyp3BQ@mail.gmail.com
This commit is contained in:
Fujii Masao
2019-04-08 16:43:57 +09:00
parent e3865c3754
commit 119dcfad98
7 changed files with 112 additions and 5 deletions

View File

@ -87,6 +87,53 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass AND
-- RESET fails if a value is specified
ALTER TABLE reloptions_test RESET (fillfactor=12);
ERROR: RESET must not include values for parameters
-- Test vacuum_truncate option
DROP TABLE reloptions_test;
CREATE TABLE reloptions_test(i INT NOT NULL, j text)
WITH (vacuum_truncate=false,
toast.vacuum_truncate=false,
autovacuum_enabled=false);
SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass;
reloptions
--------------------------------------------------
{vacuum_truncate=false,autovacuum_enabled=false}
(1 row)
INSERT INTO reloptions_test VALUES (1, NULL), (NULL, NULL);
ERROR: null value in column "i" violates not-null constraint
DETAIL: Failing row contains (null, null).
VACUUM reloptions_test;
SELECT pg_relation_size('reloptions_test') > 0;
?column?
----------
t
(1 row)
SELECT reloptions FROM pg_class WHERE oid =
(SELECT reltoastrelid FROM pg_class
WHERE oid = 'reloptions_test'::regclass);
reloptions
-------------------------
{vacuum_truncate=false}
(1 row)
ALTER TABLE reloptions_test RESET (vacuum_truncate);
SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass;
reloptions
----------------------------
{autovacuum_enabled=false}
(1 row)
INSERT INTO reloptions_test VALUES (1, NULL), (NULL, NULL);
ERROR: null value in column "i" violates not-null constraint
DETAIL: Failing row contains (null, null).
VACUUM reloptions_test;
SELECT pg_relation_size('reloptions_test') = 0;
?column?
----------
t
(1 row)
-- Test toast.* options
DROP TABLE reloptions_test;
CREATE TABLE reloptions_test (s VARCHAR)

View File

@ -52,6 +52,28 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass AND
-- RESET fails if a value is specified
ALTER TABLE reloptions_test RESET (fillfactor=12);
-- Test vacuum_truncate option
DROP TABLE reloptions_test;
CREATE TABLE reloptions_test(i INT NOT NULL, j text)
WITH (vacuum_truncate=false,
toast.vacuum_truncate=false,
autovacuum_enabled=false);
SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass;
INSERT INTO reloptions_test VALUES (1, NULL), (NULL, NULL);
VACUUM reloptions_test;
SELECT pg_relation_size('reloptions_test') > 0;
SELECT reloptions FROM pg_class WHERE oid =
(SELECT reltoastrelid FROM pg_class
WHERE oid = 'reloptions_test'::regclass);
ALTER TABLE reloptions_test RESET (vacuum_truncate);
SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass;
INSERT INTO reloptions_test VALUES (1, NULL), (NULL, NULL);
VACUUM reloptions_test;
SELECT pg_relation_size('reloptions_test') = 0;
-- Test toast.* options
DROP TABLE reloptions_test;