2005-07-14 07:13:45 +02:00
|
|
|
/*-------------------------------------------------------------------------
|
|
|
|
*
|
|
|
|
* autovacuum.h
|
|
|
|
* header file for integrated autovacuum daemon
|
|
|
|
*
|
|
|
|
*
|
2022-01-08 01:04:57 +01:00
|
|
|
* Portions Copyright (c) 1996-2022, PostgreSQL Global Development Group
|
2005-07-14 07:13:45 +02:00
|
|
|
* Portions Copyright (c) 1994, Regents of the University of California
|
|
|
|
*
|
2010-09-20 22:08:53 +02:00
|
|
|
* src/include/postmaster/autovacuum.h
|
2005-07-14 07:13:45 +02:00
|
|
|
*
|
|
|
|
*-------------------------------------------------------------------------
|
|
|
|
*/
|
|
|
|
#ifndef AUTOVACUUM_H
|
|
|
|
#define AUTOVACUUM_H
|
|
|
|
|
2017-04-03 22:17:45 +02:00
|
|
|
#include "storage/block.h"
|
|
|
|
|
BRIN auto-summarization
Previously, only VACUUM would cause a page range to get initially
summarized by BRIN indexes, which for some use cases takes too much time
since the inserts occur. To avoid the delay, have brininsert request a
summarization run for the previous range as soon as the first tuple is
inserted into the first page of the next range. Autovacuum is in charge
of processing these requests, after doing all the regular vacuuming/
analyzing work on tables.
This doesn't impose any new tasks on autovacuum, because autovacuum was
already in charge of doing summarizations. The only actual effect is to
change the timing, i.e. that it occurs earlier. For this reason, we
don't go any great lengths to record these requests very robustly; if
they are lost because of a server crash or restart, they will happen at
a later time anyway.
Most of the new code here is in autovacuum, which can now be told about
"work items" to process. This can be used for other things such as GIN
pending list cleaning, perhaps visibility map bit setting, both of which
are currently invoked during vacuum, but do not really depend on vacuum
taking place.
The requests are at the page range level, a granularity for which we did
not have SQL-level access; we only had index-level summarization
requests via brin_summarize_new_values(). It seems reasonable to add
SQL-level access to range-level summarization too, so add a function
brin_summarize_range() to do that.
Authors: Álvaro Herrera, based on sketch from Simon Riggs.
Reviewed-by: Thomas Munro.
Discussion: https://postgr.es/m/20170301045823.vneqdqkmsd4as4ds@alvherre.pgsql
2017-04-01 19:00:53 +02:00
|
|
|
/*
|
|
|
|
* Other processes can request specific work from autovacuum, identified by
|
|
|
|
* AutoVacuumWorkItem elements.
|
|
|
|
*/
|
|
|
|
typedef enum
|
|
|
|
{
|
|
|
|
AVW_BRINSummarizeRange
|
|
|
|
} AutoVacuumWorkItemType;
|
|
|
|
|
2007-04-16 20:30:04 +02:00
|
|
|
|
2005-07-14 07:13:45 +02:00
|
|
|
/* GUC variables */
|
|
|
|
extern bool autovacuum_start_daemon;
|
2007-04-16 20:30:04 +02:00
|
|
|
extern int autovacuum_max_workers;
|
2013-12-12 12:42:39 +01:00
|
|
|
extern int autovacuum_work_mem;
|
2005-07-14 07:13:45 +02:00
|
|
|
extern int autovacuum_naptime;
|
|
|
|
extern int autovacuum_vac_thresh;
|
|
|
|
extern double autovacuum_vac_scale;
|
Trigger autovacuum based on number of INSERTs
Traditionally autovacuum has only ever invoked a worker based on the
estimated number of dead tuples in a table and for anti-wraparound
purposes. For the latter, with certain classes of tables such as
insert-only tables, anti-wraparound vacuums could be the first vacuum that
the table ever receives. This could often lead to autovacuum workers being
busy for extended periods of time due to having to potentially freeze
every page in the table. This could be particularly bad for very large
tables. New clusters, or recently pg_restored clusters could suffer even
more as many large tables may have the same relfrozenxid, which could
result in large numbers of tables requiring an anti-wraparound vacuum all
at once.
Here we aim to reduce the work required by anti-wraparound and aggressive
vacuums in general, by triggering autovacuum when the table has received
enough INSERTs. This is controlled by adding two new GUCs and reloptions;
autovacuum_vacuum_insert_threshold and
autovacuum_vacuum_insert_scale_factor. These work exactly the same as the
existing scale factor and threshold controls, only base themselves off the
number of inserts since the last vacuum, rather than the number of dead
tuples. New controls were added rather than reusing the existing
controls, to allow these new vacuums to be tuned independently and perhaps
even completely disabled altogether, which can be done by setting
autovacuum_vacuum_insert_threshold to -1.
We make no attempt to skip index cleanup operations on these vacuums as
they may trigger for an insert-mostly table which continually doesn't have
enough dead tuples to trigger an autovacuum for the purpose of removing
those dead tuples. If we were to skip cleaning the indexes in this case,
then it is possible for the index(es) to become bloated over time.
There are additional benefits to triggering autovacuums based on inserts,
as tables which never contain enough dead tuples to trigger an autovacuum
are now more likely to receive a vacuum, which can mark more of the table
as "allvisible" and encourage the query planner to make use of Index Only
Scans.
Currently, we still obey vacuum_freeze_min_age when triggering these new
autovacuums based on INSERTs. For large insert-only tables, it may be
beneficial to lower the table's autovacuum_freeze_min_age so that tuples
are eligible to be frozen sooner. Here we've opted not to zero that for
these types of vacuums, since the table may just be insert-mostly and we
may otherwise freeze tuples that are still destined to be updated or
removed in the near future.
There was some debate to what exactly the new scale factor and threshold
should default to. For now, these are set to 0.2 and 1000, respectively.
There may be some motivation to adjust these before the release.
Author: Laurenz Albe, Darafei Praliaskouski
Reviewed-by: Alvaro Herrera, Masahiko Sawada, Chris Travers, Andres Freund, Justin Pryzby
Discussion: https://postgr.es/m/CAC8Q8t%2Bj36G_bLF%3D%2B0iMo6jGNWnLnWb1tujXuJr-%2Bx8ZCCTqoQ%40mail.gmail.com
2020-03-28 07:20:12 +01:00
|
|
|
extern int autovacuum_vac_ins_thresh;
|
|
|
|
extern double autovacuum_vac_ins_scale;
|
2005-07-14 07:13:45 +02:00
|
|
|
extern int autovacuum_anl_thresh;
|
|
|
|
extern double autovacuum_anl_scale;
|
Fix recently-understood problems with handling of XID freezing, particularly
in PITR scenarios. We now WAL-log the replacement of old XIDs with
FrozenTransactionId, so that such replacement is guaranteed to propagate to
PITR slave databases. Also, rather than relying on hint-bit updates to be
preserved, pg_clog is not truncated until all instances of an XID are known to
have been replaced by FrozenTransactionId. Add new GUC variables and
pg_autovacuum columns to allow management of the freezing policy, so that
users can trade off the size of pg_clog against the amount of freezing work
done. Revise the already-existing code that forces autovacuum of tables
approaching the wraparound point to make it more bulletproof; also, revise the
autovacuum logic so that anti-wraparound vacuuming is done per-table rather
than per-database. initdb forced because of changes in pg_class, pg_database,
and pg_autovacuum catalogs. Heikki Linnakangas, Simon Riggs, and Tom Lane.
2006-11-05 23:42:10 +01:00
|
|
|
extern int autovacuum_freeze_max_age;
|
Separate multixact freezing parameters from xid's
Previously we were piggybacking on transaction ID parameters to freeze
multixacts; but since there isn't necessarily any relationship between
rates of Xid and multixact consumption, this turns out not to be a good
idea.
Therefore, we now have multixact-specific freezing parameters:
vacuum_multixact_freeze_min_age: when to remove multis as we come across
them in vacuum (default to 5 million, i.e. early in comparison to Xid's
default of 50 million)
vacuum_multixact_freeze_table_age: when to force whole-table scans
instead of scanning only the pages marked as not all visible in
visibility map (default to 150 million, same as for Xids). Whichever of
both which reaches the 150 million mark earlier will cause a whole-table
scan.
autovacuum_multixact_freeze_max_age: when for cause emergency,
uninterruptible whole-table scans (default to 400 million, double as
that for Xids). This means there shouldn't be more frequent emergency
vacuuming than previously, unless multixacts are being used very
rapidly.
Backpatch to 9.3 where multixacts were made to persist enough to require
freezing. To avoid an ABI break in 9.3, VacuumStmt has a couple of
fields in an unnatural place, and StdRdOptions is split in two so that
the newly added fields can go at the end.
Patch by me, reviewed by Robert Haas, with additional input from Andres
Freund and Tom Lane.
2014-02-13 23:30:30 +01:00
|
|
|
extern int autovacuum_multixact_freeze_max_age;
|
2019-03-10 20:01:39 +01:00
|
|
|
extern double autovacuum_vac_cost_delay;
|
2005-08-11 23:11:50 +02:00
|
|
|
extern int autovacuum_vac_cost_limit;
|
2005-07-14 07:13:45 +02:00
|
|
|
|
2007-04-16 20:30:04 +02:00
|
|
|
/* autovacuum launcher PID, only valid when worker is shutting down */
|
|
|
|
extern int AutovacuumLauncherPid;
|
|
|
|
|
2007-09-24 05:12:23 +02:00
|
|
|
extern int Log_autovacuum_min_duration;
|
2007-04-18 18:44:18 +02:00
|
|
|
|
2005-07-14 07:13:45 +02:00
|
|
|
/* Status inquiry functions */
|
|
|
|
extern bool AutoVacuumingActive(void);
|
2007-02-16 00:23:23 +01:00
|
|
|
extern bool IsAutoVacuumLauncherProcess(void);
|
|
|
|
extern bool IsAutoVacuumWorkerProcess(void);
|
2010-02-26 03:01:40 +01:00
|
|
|
|
2009-08-31 21:41:00 +02:00
|
|
|
#define IsAnyAutoVacuumProcess() \
|
|
|
|
(IsAutoVacuumLauncherProcess() || IsAutoVacuumWorkerProcess())
|
2005-07-14 07:13:45 +02:00
|
|
|
|
|
|
|
/* Functions to start autovacuum process, called from postmaster */
|
|
|
|
extern void autovac_init(void);
|
2007-02-16 00:23:23 +01:00
|
|
|
extern int StartAutoVacLauncher(void);
|
|
|
|
extern int StartAutoVacWorker(void);
|
2007-11-15 22:14:46 +01:00
|
|
|
|
2007-06-25 18:09:03 +02:00
|
|
|
/* called from postmaster when a worker could not be forked */
|
|
|
|
extern void AutoVacWorkerFailed(void);
|
2005-07-14 07:13:45 +02:00
|
|
|
|
2007-04-16 20:30:04 +02:00
|
|
|
/* autovacuum cost-delay balancer */
|
|
|
|
extern void AutoVacuumUpdateDelay(void);
|
|
|
|
|
2005-07-14 07:13:45 +02:00
|
|
|
#ifdef EXEC_BACKEND
|
2015-03-11 14:19:54 +01:00
|
|
|
extern void AutoVacLauncherMain(int argc, char *argv[]) pg_attribute_noreturn();
|
|
|
|
extern void AutoVacWorkerMain(int argc, char *argv[]) pg_attribute_noreturn();
|
2007-02-16 00:23:23 +01:00
|
|
|
extern void AutovacuumWorkerIAm(void);
|
|
|
|
extern void AutovacuumLauncherIAm(void);
|
2005-07-14 07:13:45 +02:00
|
|
|
#endif
|
|
|
|
|
2018-03-14 15:53:56 +01:00
|
|
|
extern bool AutoVacuumRequestWork(AutoVacuumWorkItemType type,
|
BRIN auto-summarization
Previously, only VACUUM would cause a page range to get initially
summarized by BRIN indexes, which for some use cases takes too much time
since the inserts occur. To avoid the delay, have brininsert request a
summarization run for the previous range as soon as the first tuple is
inserted into the first page of the next range. Autovacuum is in charge
of processing these requests, after doing all the regular vacuuming/
analyzing work on tables.
This doesn't impose any new tasks on autovacuum, because autovacuum was
already in charge of doing summarizations. The only actual effect is to
change the timing, i.e. that it occurs earlier. For this reason, we
don't go any great lengths to record these requests very robustly; if
they are lost because of a server crash or restart, they will happen at
a later time anyway.
Most of the new code here is in autovacuum, which can now be told about
"work items" to process. This can be used for other things such as GIN
pending list cleaning, perhaps visibility map bit setting, both of which
are currently invoked during vacuum, but do not really depend on vacuum
taking place.
The requests are at the page range level, a granularity for which we did
not have SQL-level access; we only had index-level summarization
requests via brin_summarize_new_values(). It seems reasonable to add
SQL-level access to range-level summarization too, so add a function
brin_summarize_range() to do that.
Authors: Álvaro Herrera, based on sketch from Simon Riggs.
Reviewed-by: Thomas Munro.
Discussion: https://postgr.es/m/20170301045823.vneqdqkmsd4as4ds@alvherre.pgsql
2017-04-01 19:00:53 +02:00
|
|
|
Oid relationId, BlockNumber blkno);
|
|
|
|
|
2007-02-16 00:23:23 +01:00
|
|
|
/* shared memory stuff */
|
|
|
|
extern Size AutoVacuumShmemSize(void);
|
|
|
|
extern void AutoVacuumShmemInit(void);
|
|
|
|
|
2005-07-14 07:13:45 +02:00
|
|
|
#endif /* AUTOVACUUM_H */
|