Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 4830f10

Browse filesBrowse files
committed
Disable vacuum's use of a buffer access strategy during failsafe
Traditionally, vacuum always makes use of a buffer access strategy 32 buffers in size. This means that running vacuums tend not to cause too many shared buffers to become dirty, however, this can cause vacuums to run much more slowly than they otherwise could as WAL flushes will occur more frequently due to having to flush WAL out to the LSN of the dirty page before that page can be written to disk. When we are performing failsafe VACUUMs (as added in 1e55e7d), we really want to make the vacuum work go as quickly as possible, so here we disable the buffer access strategy when entering failsafe mode while vacuuming a relation. Per idea and analyis from Andres Freund. In passing, also include some changes I had intended for 32fbe02. Author: Melanie Plageman Reviewed-by: Justin Pryzby, David Rowley Discussion: https://postgr.es/m/20230111182720.ejifsclfwymw2reb%40awork3.anarazel.de
1 parent 525fb0a commit 4830f10
Copy full SHA for 4830f10

File tree

3 files changed

+18
-5
lines changed
Filter options

3 files changed

+18
-5
lines changed

‎doc/src/sgml/config.sgml

Copy file name to clipboardExpand all lines: doc/src/sgml/config.sgml
+6-2
Original file line numberDiff line numberDiff line change
@@ -9320,8 +9320,12 @@ COPY postgres_log FROM '/full/path/to/logfile.csv' WITH csv;
93209320
</para>
93219321
<para>
93229322
When the failsafe is triggered, any cost-based delay that is
9323-
in effect will no longer be applied, and further non-essential
9324-
maintenance tasks (such as index vacuuming) are bypassed.
9323+
in effect will no longer be applied, further non-essential
9324+
maintenance tasks (such as index vacuuming) are bypassed, and any
9325+
<glossterm linkend="glossary-buffer-access-strategy">Buffer Access Strategy</glossterm>
9326+
in use will be disabled resulting in <command>VACUUM</command> being
9327+
free to make use of all of
9328+
<glossterm linkend="glossary-shared-memory">shared buffers</glossterm>.
93259329
</para>
93269330
<para>
93279331
The default is 1.6 billion transactions. Although users can

‎src/backend/access/heap/vacuumlazy.c

Copy file name to clipboardExpand all lines: src/backend/access/heap/vacuumlazy.c
+7
Original file line numberDiff line numberDiff line change
@@ -2623,6 +2623,13 @@ lazy_check_wraparound_failsafe(LVRelState *vacrel)
26232623
{
26242624
vacrel->failsafe_active = true;
26252625

2626+
/*
2627+
* Abandon use of a buffer access strategy to allow use of all of
2628+
* shared buffers. We assume the caller who allocated the memory for
2629+
* the BufferAccessStrategy will free it.
2630+
*/
2631+
vacrel->bstrategy = NULL;
2632+
26262633
/* Disable index vacuuming, index cleanup, and heap rel truncation */
26272634
vacrel->do_index_vacuuming = false;
26282635
vacrel->do_index_cleanup = false;

‎src/backend/commands/vacuum.c

Copy file name to clipboardExpand all lines: src/backend/commands/vacuum.c
+5-3
Original file line numberDiff line numberDiff line change
@@ -391,11 +391,13 @@ vacuum(List *relations, VacuumParams *params,
391391

392392
/*
393393
* If caller didn't give us a buffer strategy object, make one in the
394-
* cross-transaction memory context.
394+
* cross-transaction memory context. We needn't bother making this for
395+
* VACUUM (FULL) or VACUUM (ONLY_DATABASE_STATS) as they'll not make use
396+
* of it.
395397
*/
396398
if (bstrategy == NULL &&
397-
!(params->options & VACOPT_ONLY_DATABASE_STATS ||
398-
params->options & VACOPT_FULL))
399+
(params->options & (VACOPT_ONLY_DATABASE_STATS |
400+
VACOPT_FULL)) == 0)
399401
{
400402
MemoryContext old_context = MemoryContextSwitchTo(vac_context);
401403

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.