Skip to content

Commit 6c6b497

Browse files
Revert "Add eager and lazy freezing strategies to VACUUM."
This reverts commit 4d41799. Broad concerns about regressions caused by eager freezing strategy have been raised. Whether or not these concerns can be worked through in any time frame is far from certain. Discussion: https://postgr.es/m/20230126004347.gepcmyenk2csxrri@awork3.anarazel.de
1 parent 8b5f36b commit 6c6b497

File tree

12 files changed

+14
-197
lines changed

12 files changed

+14
-197
lines changed

doc/src/sgml/config.sgml

Lines changed: 0 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -9272,36 +9272,6 @@ COPY postgres_log FROM '/full/path/to/logfile.csv' WITH csv;
92729272
</listitem>
92739273
</varlistentry>
92749274

9275-
<varlistentry id="guc-vacuum-freeze-strategy-threshold" xreflabel="vacuum_freeze_strategy_threshold">
9276-
<term><varname>vacuum_freeze_strategy_threshold</varname> (<type>integer</type>)
9277-
<indexterm>
9278-
<primary><varname>vacuum_freeze_strategy_threshold</varname> configuration parameter</primary>
9279-
</indexterm>
9280-
</term>
9281-
<listitem>
9282-
<para>
9283-
Specifies the cutoff storage size that
9284-
<command>VACUUM</command> should use to determine its freezing
9285-
strategy. This is applied by comparing it to the size of the
9286-
target table's <glossterm linkend="glossary-fork">main
9287-
fork</glossterm> at the beginning of each <command>VACUUM</command>.
9288-
Eager freezing strategy is used by <command>VACUUM</command>
9289-
when the table's main fork size exceeds this value.
9290-
<command>VACUUM</command> <emphasis>always</emphasis> uses
9291-
eager freezing strategy when processing <glossterm
9292-
linkend="glossary-unlogged">unlogged</glossterm> tables,
9293-
regardless of this setting. Otherwise <command>VACUUM</command>
9294-
uses lazy freezing strategy. For more information see <xref
9295-
linkend="vacuum-for-wraparound"/>.
9296-
</para>
9297-
<para>
9298-
If this value is specified without units, it is taken as
9299-
megabytes. The default is four gigabytes
9300-
(<literal>4GB</literal>).
9301-
</para>
9302-
</listitem>
9303-
</varlistentry>
9304-
93059275
<varlistentry id="guc-vacuum-failsafe-age" xreflabel="vacuum_failsafe_age">
93069276
<term><varname>vacuum_failsafe_age</varname> (<type>integer</type>)
93079277
<indexterm>

doc/src/sgml/maintenance.sgml

Lines changed: 12 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -478,30 +478,13 @@
478478
</note>
479479

480480
<para>
481-
<xref linkend="guc-vacuum-freeze-strategy-threshold"/> controls
482-
<command>VACUUM</command>'s freezing strategy. The
483-
<firstterm>eager freezing strategy</firstterm> makes
484-
<command>VACUUM</command> freeze all rows on a page whenever each
485-
and every row on the page is considered visible to all current
486-
transactions (immediately after dead row versions are removed).
487-
Freezing pages early and in batch often spreads out the overhead
488-
of freezing over time. <command>VACUUM</command> consistently
489-
avoids allowing unfrozen all-visible pages to build up, improving
490-
system level performance stability. The <firstterm>lazy freezing
491-
strategy</firstterm> makes <command>VACUUM</command> determine
492-
whether pages should be frozen on the basis of the age of the
493-
oldest XID on the page. Freezing pages lazily sometimes avoids
494-
the overhead of freezing that turns out to have been unnecessary
495-
because the rows were modified soon after freezing took place.
496-
</para>
497-
498-
<para>
499-
<xref linkend="guc-vacuum-freeze-min-age"/> controls how old an
500-
XID value has to be before pages with rows bearing that XID are
501-
frozen. This setting is an additional trigger criteria for
502-
freezing a page's tuples. It is used by both freezing strategies,
503-
though it typically has little impact when <command>VACUUM</command>
504-
uses the eager freezing strategy.
481+
<xref linkend="guc-vacuum-freeze-min-age"/>
482+
controls how old an XID value has to be before rows bearing that XID will be
483+
frozen. Increasing this setting may avoid unnecessary work if the
484+
rows that would otherwise be frozen will soon be modified again,
485+
but decreasing this setting increases
486+
the number of transactions that can elapse before the table must be
487+
vacuumed again.
505488
</para>
506489

507490
<para>
@@ -523,21 +506,12 @@
523506
always use its aggressive strategy.
524507
</para>
525508

526-
<para>
527-
Controlling the overhead of freezing existing all-visible pages
528-
during aggressive vacuuming is the goal of the eager freezing
529-
strategy. Increasing <varname>vacuum_freeze_strategy_threshold</varname>
530-
may avoid unnecessary work, but it increases the risk of an
531-
eventual aggressive vacuum that performs an excessive amount of
532-
<quote>catch up</quote> freezing all at once.
533-
</para>
534-
535509
<para>
536510
The maximum time that a table can go unvacuumed is two billion
537511
transactions minus the <varname>vacuum_freeze_min_age</varname> value at
538512
the time of the last aggressive vacuum. If it were to go
539-
unvacuumed for longer than that, the system could temporarily refuse to
540-
allocate new transaction IDs. To ensure that this never happens,
513+
unvacuumed for longer than
514+
that, data loss could result. To ensure that this does not happen,
541515
autovacuum is invoked on any table that might contain unfrozen rows with
542516
XIDs older than the age specified by the configuration parameter <xref
543517
linkend="guc-autovacuum-freeze-max-age"/>. (This will happen even if
@@ -577,7 +551,7 @@
577551
</para>
578552

579553
<para>
580-
One disadvantage of increasing <varname>autovacuum_freeze_max_age</varname>
554+
The sole disadvantage of increasing <varname>autovacuum_freeze_max_age</varname>
581555
(and <varname>vacuum_freeze_table_age</varname> along with it) is that
582556
the <filename>pg_xact</filename> and <filename>pg_commit_ts</filename>
583557
subdirectories of the database cluster will take more space, because it
@@ -864,8 +838,8 @@ vacuum insert threshold = vacuum base insert threshold + vacuum insert scale fac
864838
For tables which receive <command>INSERT</command> operations but no or
865839
almost no <command>UPDATE</command>/<command>DELETE</command> operations,
866840
it may be beneficial to lower the table's
867-
<xref linkend="reloption-autovacuum-freeze-strategy-threshold"/>
868-
to allow freezing to take place proactively. The number of obsolete tuples and
841+
<xref linkend="reloption-autovacuum-freeze-min-age"/> as this may allow
842+
tuples to be frozen by earlier vacuums. The number of obsolete tuples and
869843
the number of inserted tuples are obtained from the cumulative statistics system;
870844
it is a semi-accurate count updated by each <command>UPDATE</command>,
871845
<command>DELETE</command> and <command>INSERT</command> operation. (It is

doc/src/sgml/ref/create_table.sgml

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1781,20 +1781,6 @@ WITH ( MODULUS <replaceable class="parameter">numeric_literal</replaceable>, REM
17811781
</listitem>
17821782
</varlistentry>
17831783

1784-
<varlistentry id="reloption-autovacuum-freeze-strategy-threshold" xreflabel="autovacuum_freeze_strategy_threshold">
1785-
<term><literal>autovacuum_freeze_strategy_threshold</literal>, <literal>toast.autovacuum_freeze_strategy_threshold</literal> (<type>integer</type>)
1786-
<indexterm>
1787-
<primary><varname>autovacuum_freeze_strategy_threshold</varname> storage parameter</primary>
1788-
</indexterm>
1789-
</term>
1790-
<listitem>
1791-
<para>
1792-
Per-table value for <xref linkend="guc-vacuum-freeze-strategy-threshold"/>
1793-
parameter.
1794-
</para>
1795-
</listitem>
1796-
</varlistentry>
1797-
17981784
<varlistentry id="reloption-log-autovacuum-min-duration" xreflabel="log_autovacuum_min_duration">
17991785
<term><literal>log_autovacuum_min_duration</literal>, <literal>toast.log_autovacuum_min_duration</literal> (<type>integer</type>)
18001786
<indexterm>

src/backend/access/common/reloptions.c

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -312,14 +312,6 @@ static relopt_int intRelOpts[] =
312312
ShareUpdateExclusiveLock
313313
}, -1, 0, 2000000000
314314
},
315-
{
316-
{
317-
"autovacuum_freeze_strategy_threshold",
318-
"Table size at which VACUUM freezes using eager strategy, in megabytes.",
319-
RELOPT_KIND_HEAP | RELOPT_KIND_TOAST,
320-
ShareUpdateExclusiveLock
321-
}, -1, 0, MAX_KILOBYTES
322-
},
323315
{
324316
{
325317
"log_autovacuum_min_duration",
@@ -1871,8 +1863,6 @@ default_reloptions(Datum reloptions, bool validate, relopt_kind kind)
18711863
offsetof(StdRdOptions, autovacuum) + offsetof(AutoVacOpts, multixact_freeze_max_age)},
18721864
{"autovacuum_multixact_freeze_table_age", RELOPT_TYPE_INT,
18731865
offsetof(StdRdOptions, autovacuum) + offsetof(AutoVacOpts, multixact_freeze_table_age)},
1874-
{"autovacuum_freeze_strategy_threshold", RELOPT_TYPE_INT,
1875-
offsetof(StdRdOptions, autovacuum) + offsetof(AutoVacOpts, freeze_strategy_threshold)},
18761866
{"log_autovacuum_min_duration", RELOPT_TYPE_INT,
18771867
offsetof(StdRdOptions, autovacuum) + offsetof(AutoVacOpts, log_min_duration)},
18781868
{"toast_tuple_target", RELOPT_TYPE_INT,

src/backend/access/heap/heapam.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7057,7 +7057,6 @@ heap_freeze_tuple(HeapTupleHeader tuple,
70577057
cutoffs.OldestMxact = MultiXactCutoff;
70587058
cutoffs.FreezeLimit = FreezeLimit;
70597059
cutoffs.MultiXactCutoff = MultiXactCutoff;
7060-
cutoffs.freeze_strategy_threshold_pages = 0;
70617060

70627061
pagefrz.freeze_required = true;
70637062
pagefrz.FreezePageRelfrozenXid = FreezeLimit;

src/backend/access/heap/vacuumlazy.c

Lines changed: 1 addition & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -153,8 +153,6 @@ typedef struct LVRelState
153153
bool aggressive;
154154
/* Use visibility map to skip? (disabled by DISABLE_PAGE_SKIPPING) */
155155
bool skipwithvm;
156-
/* Eagerly freeze pages that are eligible to become all-frozen? */
157-
bool eager_freeze_strategy;
158156
/* Wraparound failsafe has been triggered? */
159157
bool failsafe_active;
160158
/* Consider index vacuuming bypass optimization? */
@@ -245,7 +243,6 @@ typedef struct LVSavedErrInfo
245243

246244
/* non-export function prototypes */
247245
static void lazy_scan_heap(LVRelState *vacrel);
248-
static void lazy_scan_strategy(LVRelState *vacrel);
249246
static BlockNumber lazy_scan_skip(LVRelState *vacrel, Buffer *vmbuffer,
250247
BlockNumber next_block,
251248
bool *next_unskippable_allvis,
@@ -475,10 +472,6 @@ heap_vacuum_rel(Relation rel, VacuumParams *params,
475472

476473
vacrel->skipwithvm = skipwithvm;
477474

478-
/*
479-
* Now determine VACUUM's freezing strategy
480-
*/
481-
lazy_scan_strategy(vacrel);
482475
if (verbose)
483476
{
484477
if (vacrel->aggressive)
@@ -1274,38 +1267,6 @@ lazy_scan_heap(LVRelState *vacrel)
12741267
lazy_cleanup_all_indexes(vacrel);
12751268
}
12761269

1277-
/*
1278-
* lazy_scan_strategy() -- Determine freezing strategy.
1279-
*
1280-
* Our lazy freezing strategy is useful when putting off the work of freezing
1281-
* totally avoids freezing that turns out to have been wasted effort later on.
1282-
* Our eager freezing strategy is useful with larger tables that experience
1283-
* continual growth, where freezing pages proactively is needed just to avoid
1284-
* falling behind on freezing (eagerness is also likely to be cheaper in the
1285-
* short/medium term for such tables, but the long term picture matters most).
1286-
*/
1287-
static void
1288-
lazy_scan_strategy(LVRelState *vacrel)
1289-
{
1290-
BlockNumber rel_pages = vacrel->rel_pages;
1291-
1292-
/*
1293-
* Decide freezing strategy.
1294-
*
1295-
* The eager freezing strategy is used whenever rel_pages exceeds a
1296-
* threshold controlled by the freeze_strategy_threshold GUC/reloption.
1297-
*
1298-
* Also freeze eagerly with an unlogged or temp table, where the total
1299-
* cost of freezing pages is mostly just the cycles needed to prepare a
1300-
* set of freeze plans. Executing the freeze plans adds very little cost.
1301-
* Dirtying extra pages isn't a concern, either; VACUUM will definitely
1302-
* set PD_ALL_VISIBLE on affected pages, regardless of freezing strategy.
1303-
*/
1304-
vacrel->eager_freeze_strategy =
1305-
(rel_pages > vacrel->cutoffs.freeze_strategy_threshold_pages ||
1306-
!RelationIsPermanent(vacrel->rel));
1307-
}
1308-
13091270
/*
13101271
* lazy_scan_skip() -- set up range of skippable blocks using visibility map.
13111272
*
@@ -1834,12 +1795,10 @@ lazy_scan_prune(LVRelState *vacrel,
18341795
* one XID/MXID from before FreezeLimit/MultiXactCutoff is present. Also
18351796
* freeze when pruning generated an FPI, if doing so means that we set the
18361797
* page all-frozen afterwards (might not happen until final heap pass).
1837-
* When ongoing VACUUM opted to use the eager freezing strategy we freeze
1838-
* any page that will thereby become all-frozen in the visibility map.
18391798
*/
18401799
if (pagefrz.freeze_required || tuples_frozen == 0 ||
18411800
(prunestate->all_visible && prunestate->all_frozen &&
1842-
(fpi_before != pgWalUsage.wal_fpi || vacrel->eager_freeze_strategy)))
1801+
fpi_before != pgWalUsage.wal_fpi))
18431802
{
18441803
/*
18451804
* We're freezing the page. Our final NewRelfrozenXid doesn't need to

src/backend/commands/vacuum.c

Lines changed: 1 addition & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,6 @@ int vacuum_freeze_min_age;
6868
int vacuum_freeze_table_age;
6969
int vacuum_multixact_freeze_min_age;
7070
int vacuum_multixact_freeze_table_age;
71-
int vacuum_freeze_strategy_threshold;
7271
int vacuum_failsafe_age;
7372
int vacuum_multixact_failsafe_age;
7473

@@ -265,15 +264,13 @@ ExecVacuum(ParseState *pstate, VacuumStmt *vacstmt, bool isTopLevel)
265264
params.freeze_table_age = 0;
266265
params.multixact_freeze_min_age = 0;
267266
params.multixact_freeze_table_age = 0;
268-
params.freeze_strategy_threshold = 0;
269267
}
270268
else
271269
{
272270
params.freeze_min_age = -1;
273271
params.freeze_table_age = -1;
274272
params.multixact_freeze_min_age = -1;
275273
params.multixact_freeze_table_age = -1;
276-
params.freeze_strategy_threshold = -1;
277274
}
278275

279276
/* user-invoked vacuum is never "for wraparound" */
@@ -965,9 +962,7 @@ vacuum_get_cutoffs(Relation rel, const VacuumParams *params,
965962
multixact_freeze_min_age,
966963
freeze_table_age,
967964
multixact_freeze_table_age,
968-
effective_multixact_freeze_max_age,
969-
freeze_strategy_threshold;
970-
uint64 threshold_strategy_pages;
965+
effective_multixact_freeze_max_age;
971966
TransactionId nextXID,
972967
safeOldestXmin,
973968
aggressiveXIDCutoff;
@@ -980,7 +975,6 @@ vacuum_get_cutoffs(Relation rel, const VacuumParams *params,
980975
multixact_freeze_min_age = params->multixact_freeze_min_age;
981976
freeze_table_age = params->freeze_table_age;
982977
multixact_freeze_table_age = params->multixact_freeze_table_age;
983-
freeze_strategy_threshold = params->freeze_strategy_threshold;
984978

985979
/* Set pg_class fields in cutoffs */
986980
cutoffs->relfrozenxid = rel->rd_rel->relfrozenxid;
@@ -1095,23 +1089,6 @@ vacuum_get_cutoffs(Relation rel, const VacuumParams *params,
10951089
if (MultiXactIdPrecedes(cutoffs->OldestMxact, cutoffs->MultiXactCutoff))
10961090
cutoffs->MultiXactCutoff = cutoffs->OldestMxact;
10971091

1098-
/*
1099-
* Determine the freeze_strategy_threshold to use: as specified by the
1100-
* caller, or vacuum_freeze_strategy_threshold
1101-
*/
1102-
if (freeze_strategy_threshold < 0)
1103-
freeze_strategy_threshold = vacuum_freeze_strategy_threshold;
1104-
Assert(freeze_strategy_threshold >= 0);
1105-
1106-
/*
1107-
* Convert MB-based freeze_strategy_threshold to page-based value used by
1108-
* our vacuumlazy.c caller, while being careful to avoid overflow
1109-
*/
1110-
threshold_strategy_pages =
1111-
((uint64) freeze_strategy_threshold * 1024 * 1024) / BLCKSZ;
1112-
threshold_strategy_pages = Min(threshold_strategy_pages, MaxBlockNumber);
1113-
cutoffs->freeze_strategy_threshold_pages = threshold_strategy_pages;
1114-
11151092
/*
11161093
* Finally, figure out if caller needs to do an aggressive VACUUM or not.
11171094
*

src/backend/postmaster/autovacuum.c

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,6 @@ static int default_freeze_min_age;
151151
static int default_freeze_table_age;
152152
static int default_multixact_freeze_min_age;
153153
static int default_multixact_freeze_table_age;
154-
static int default_freeze_strategy_threshold;
155154

156155
/* Memory context for long-lived data */
157156
static MemoryContext AutovacMemCxt;
@@ -2011,15 +2010,13 @@ do_autovacuum(void)
20112010
default_freeze_table_age = 0;
20122011
default_multixact_freeze_min_age = 0;
20132012
default_multixact_freeze_table_age = 0;
2014-
default_freeze_strategy_threshold = 0;
20152013
}
20162014
else
20172015
{
20182016
default_freeze_min_age = vacuum_freeze_min_age;
20192017
default_freeze_table_age = vacuum_freeze_table_age;
20202018
default_multixact_freeze_min_age = vacuum_multixact_freeze_min_age;
20212019
default_multixact_freeze_table_age = vacuum_multixact_freeze_table_age;
2022-
default_freeze_strategy_threshold = vacuum_freeze_strategy_threshold;
20232020
}
20242021

20252022
ReleaseSysCache(tuple);
@@ -2804,7 +2801,6 @@ table_recheck_autovac(Oid relid, HTAB *table_toast_map,
28042801
int freeze_table_age;
28052802
int multixact_freeze_min_age;
28062803
int multixact_freeze_table_age;
2807-
int freeze_strategy_threshold;
28082804
int vac_cost_limit;
28092805
double vac_cost_delay;
28102806
int log_min_duration;
@@ -2854,11 +2850,6 @@ table_recheck_autovac(Oid relid, HTAB *table_toast_map,
28542850
? avopts->multixact_freeze_table_age
28552851
: default_multixact_freeze_table_age;
28562852

2857-
freeze_strategy_threshold = (avopts &&
2858-
avopts->freeze_strategy_threshold >= 0)
2859-
? avopts->freeze_strategy_threshold
2860-
: default_freeze_strategy_threshold;
2861-
28622853
tab = palloc(sizeof(autovac_table));
28632854
tab->at_relid = relid;
28642855
tab->at_sharedrel = classForm->relisshared;
@@ -2886,7 +2877,6 @@ table_recheck_autovac(Oid relid, HTAB *table_toast_map,
28862877
tab->at_params.freeze_table_age = freeze_table_age;
28872878
tab->at_params.multixact_freeze_min_age = multixact_freeze_min_age;
28882879
tab->at_params.multixact_freeze_table_age = multixact_freeze_table_age;
2889-
tab->at_params.freeze_strategy_threshold = freeze_strategy_threshold;
28902880
tab->at_params.is_wraparound = wraparound;
28912881
tab->at_params.log_min_duration = log_min_duration;
28922882
tab->at_vacuum_cost_limit = vac_cost_limit;

src/backend/utils/misc/guc_tables.c

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2535,20 +2535,6 @@ struct config_int ConfigureNamesInt[] =
25352535
NULL, NULL, NULL
25362536
},
25372537

2538-
{
2539-
{"vacuum_freeze_strategy_threshold", PGC_USERSET, CLIENT_CONN_STATEMENT,
2540-
gettext_noop("Table size at which VACUUM freezes using eager strategy, in megabytes."),
2541-
gettext_noop("This is applied by comparing it to the size of a table's main fork at "
2542-
"the beginning of each VACUUM. Eager freezing strategy is used when size "
2543-
"exceeds the threshold, or when table is a temporary or unlogged table. "
2544-
"Otherwise lazy freezing strategy is used."),
2545-
GUC_UNIT_MB
2546-
},
2547-
&vacuum_freeze_strategy_threshold,
2548-
4096, 0, MAX_KILOBYTES,
2549-
NULL, NULL, NULL
2550-
},
2551-
25522538
{
25532539
{"vacuum_defer_cleanup_age", PGC_SIGHUP, REPLICATION_PRIMARY,
25542540
gettext_noop("Number of transactions by which VACUUM and HOT cleanup should be deferred, if any."),

0 commit comments

Comments
 (0)