Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit a38dce3

Browse files
Fix assertion failure in parallel vacuum with minimal maintenance_work_mem setting.
bbf668d lowered the minimum value of maintenance_work_mem to 64kB. However, in parallel vacuum cases, since the initial underlying DSA size is 256kB, it attempts to perform a cycle of index vacuuming and table vacuuming with an empty TID store, resulting in an assertion failure. This commit ensures that at least one page is processed before index vacuuming and table vacuuming begins. Backpatch to 17, where the minimum maintenance_work_mem value was lowered. Reviewed-by: David Rowley <dgrowleyml@gmail.com> Discussion: https://postgr.es/m/CAD21AoCEAmbkkXSKbj4dB+5pJDRL4ZHxrCiLBgES_g_g8mVi1Q@mail.gmail.com Backpatch-through: 17
1 parent ee57892 commit a38dce3

File tree

3 files changed

+30
-2
lines changed

3 files changed

+30
-2
lines changed

src/backend/access/heap/vacuumlazy.c

+5-2
Original file line numberDiff line numberDiff line change
@@ -872,9 +872,12 @@ lazy_scan_heap(LVRelState *vacrel)
872872
* Consider if we definitely have enough space to process TIDs on page
873873
* already. If we are close to overrunning the available space for
874874
* dead_items TIDs, pause and do a cycle of vacuuming before we tackle
875-
* this page.
875+
* this page. However, let's force at least one page-worth of tuples
876+
* to be stored as to ensure we do at least some work when the memory
877+
* configured is so low that we run out before storing anything.
876878
*/
877-
if (TidStoreMemoryUsage(vacrel->dead_items) > vacrel->dead_items_info->max_bytes)
879+
if (vacrel->dead_items_info->num_items > 0 &&
880+
TidStoreMemoryUsage(vacrel->dead_items) > vacrel->dead_items_info->max_bytes)
878881
{
879882
/*
880883
* Before beginning index vacuuming, we release any pin we may

src/test/regress/expected/vacuum.out

+12
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,10 @@ CREATE INDEX brin_pvactst ON pvactst USING brin (i);
148148
CREATE INDEX gin_pvactst ON pvactst USING gin (a);
149149
CREATE INDEX gist_pvactst ON pvactst USING gist (p);
150150
CREATE INDEX spgist_pvactst ON pvactst USING spgist (p);
151+
CREATE TABLE pvactst2 (i INT) WITH (autovacuum_enabled = off);
152+
INSERT INTO pvactst2 SELECT generate_series(1, 1000);
153+
CREATE INDEX ON pvactst2 (i);
154+
CREATE INDEX ON pvactst2 (i);
151155
-- VACUUM invokes parallel index cleanup
152156
SET min_parallel_index_scan_size to 0;
153157
VACUUM (PARALLEL 2) pvactst;
@@ -167,6 +171,13 @@ VACUUM (PARALLEL) pvactst; -- error, cannot use PARALLEL option without parallel
167171
ERROR: parallel option requires a value between 0 and 1024
168172
LINE 1: VACUUM (PARALLEL) pvactst;
169173
^
174+
-- Test parallel vacuum using the minimum maintenance_work_mem with and without
175+
-- dead tuples.
176+
SET maintenance_work_mem TO 64;
177+
VACUUM (PARALLEL 2) pvactst2;
178+
DELETE FROM pvactst2 WHERE i < 1000;
179+
VACUUM (PARALLEL 2) pvactst2;
180+
RESET maintenance_work_mem;
170181
-- Test different combinations of parallel and full options for temporary tables
171182
CREATE TEMPORARY TABLE tmp (a int PRIMARY KEY);
172183
CREATE INDEX tmp_idx1 ON tmp (a);
@@ -175,6 +186,7 @@ WARNING: disabling parallel option of vacuum on "tmp" --- cannot vacuum tempora
175186
VACUUM (PARALLEL 0, FULL TRUE) tmp; -- can specify parallel disabled (even though that's implied by FULL)
176187
RESET min_parallel_index_scan_size;
177188
DROP TABLE pvactst;
189+
DROP TABLE pvactst2;
178190
-- INDEX_CLEANUP option
179191
CREATE TABLE no_index_cleanup (i INT PRIMARY KEY, t TEXT);
180192
-- Use uncompressed data stored in toast.

src/test/regress/sql/vacuum.sql

+13
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,10 @@ CREATE INDEX brin_pvactst ON pvactst USING brin (i);
113113
CREATE INDEX gin_pvactst ON pvactst USING gin (a);
114114
CREATE INDEX gist_pvactst ON pvactst USING gist (p);
115115
CREATE INDEX spgist_pvactst ON pvactst USING spgist (p);
116+
CREATE TABLE pvactst2 (i INT) WITH (autovacuum_enabled = off);
117+
INSERT INTO pvactst2 SELECT generate_series(1, 1000);
118+
CREATE INDEX ON pvactst2 (i);
119+
CREATE INDEX ON pvactst2 (i);
116120

117121
-- VACUUM invokes parallel index cleanup
118122
SET min_parallel_index_scan_size to 0;
@@ -130,13 +134,22 @@ VACUUM (PARALLEL 2, INDEX_CLEANUP FALSE) pvactst;
130134
VACUUM (PARALLEL 2, FULL TRUE) pvactst; -- error, cannot use both PARALLEL and FULL
131135
VACUUM (PARALLEL) pvactst; -- error, cannot use PARALLEL option without parallel degree
132136

137+
-- Test parallel vacuum using the minimum maintenance_work_mem with and without
138+
-- dead tuples.
139+
SET maintenance_work_mem TO 64;
140+
VACUUM (PARALLEL 2) pvactst2;
141+
DELETE FROM pvactst2 WHERE i < 1000;
142+
VACUUM (PARALLEL 2) pvactst2;
143+
RESET maintenance_work_mem;
144+
133145
-- Test different combinations of parallel and full options for temporary tables
134146
CREATE TEMPORARY TABLE tmp (a int PRIMARY KEY);
135147
CREATE INDEX tmp_idx1 ON tmp (a);
136148
VACUUM (PARALLEL 1, FULL FALSE) tmp; -- parallel vacuum disabled for temp tables
137149
VACUUM (PARALLEL 0, FULL TRUE) tmp; -- can specify parallel disabled (even though that's implied by FULL)
138150
RESET min_parallel_index_scan_size;
139151
DROP TABLE pvactst;
152+
DROP TABLE pvactst2;
140153

141154
-- INDEX_CLEANUP option
142155
CREATE TABLE no_index_cleanup (i INT PRIMARY KEY, t TEXT);

0 commit comments

Comments
 (0)