mirror of
https://github.com/postgres/postgres.git
synced 2025-11-10 17:42:29 +03:00
Integrate autovacuum functionality into the backend. There's still a
few loose ends to be dealt with, but it seems to work. Alvaro Herrera, based on the contrib code by Matthew O'Connor.
This commit is contained in:
@@ -8,7 +8,7 @@
|
||||
*
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $PostgreSQL: pgsql/src/backend/utils/init/miscinit.c,v 1.145 2005/07/04 04:51:50 tgl Exp $
|
||||
* $PostgreSQL: pgsql/src/backend/utils/init/miscinit.c,v 1.146 2005/07/14 05:13:41 tgl Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
@@ -32,6 +32,7 @@
|
||||
#include "catalog/pg_authid.h"
|
||||
#include "libpq/libpq-be.h"
|
||||
#include "miscadmin.h"
|
||||
#include "postmaster/autovacuum.h"
|
||||
#include "storage/fd.h"
|
||||
#include "storage/ipc.h"
|
||||
#include "storage/pg_shmem.h"
|
||||
@@ -394,7 +395,7 @@ void
|
||||
InitializeSessionUserIdStandalone(void)
|
||||
{
|
||||
/* This function should only be called in a single-user backend. */
|
||||
AssertState(!IsUnderPostmaster);
|
||||
AssertState(!IsUnderPostmaster || IsAutoVacuumProcess());
|
||||
|
||||
/* call only once */
|
||||
AssertState(!OidIsValid(AuthenticatedUserId));
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
*
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $PostgreSQL: pgsql/src/backend/utils/init/postinit.c,v 1.152 2005/07/04 04:51:50 tgl Exp $
|
||||
* $PostgreSQL: pgsql/src/backend/utils/init/postinit.c,v 1.153 2005/07/14 05:13:41 tgl Exp $
|
||||
*
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
@@ -29,6 +29,7 @@
|
||||
#include "libpq/hba.h"
|
||||
#include "mb/pg_wchar.h"
|
||||
#include "miscadmin.h"
|
||||
#include "postmaster/autovacuum.h"
|
||||
#include "postmaster/postmaster.h"
|
||||
#include "storage/backendid.h"
|
||||
#include "storage/fd.h"
|
||||
@@ -268,7 +269,8 @@ BaseInit(void)
|
||||
* InitPostgres
|
||||
* Initialize POSTGRES.
|
||||
*
|
||||
* In bootstrap mode neither of the parameters are used.
|
||||
* In bootstrap mode neither of the parameters are used. In autovacuum
|
||||
* mode, the username parameter is not used.
|
||||
*
|
||||
* The return value indicates whether the userID is a superuser. (That
|
||||
* can only be tested inside a transaction, so we want to do it during
|
||||
@@ -282,6 +284,7 @@ bool
|
||||
InitPostgres(const char *dbname, const char *username)
|
||||
{
|
||||
bool bootstrap = IsBootstrapProcessingMode();
|
||||
bool autovacuum = IsAutoVacuumProcess();
|
||||
bool am_superuser;
|
||||
|
||||
/*
|
||||
@@ -402,10 +405,11 @@ InitPostgres(const char *dbname, const char *username)
|
||||
RelationCacheInitializePhase2();
|
||||
|
||||
/*
|
||||
* Figure out our postgres user id. In standalone mode we use a fixed
|
||||
* id, otherwise we figure it out from the authenticated user name.
|
||||
* Figure out our postgres user id. In standalone mode and in the
|
||||
* autovacuum process, we use a fixed id, otherwise we figure it out from
|
||||
* the authenticated user name.
|
||||
*/
|
||||
if (bootstrap)
|
||||
if (bootstrap || autovacuum)
|
||||
InitializeSessionUserIdStandalone();
|
||||
else if (!IsUnderPostmaster)
|
||||
{
|
||||
@@ -441,7 +445,7 @@ InitPostgres(const char *dbname, const char *username)
|
||||
/*
|
||||
* Check if user is a superuser.
|
||||
*/
|
||||
if (bootstrap)
|
||||
if (bootstrap || autovacuum)
|
||||
am_superuser = true;
|
||||
else
|
||||
am_superuser = superuser();
|
||||
|
||||
@@ -10,7 +10,7 @@
|
||||
* Written by Peter Eisentraut <peter_e@gmx.net>.
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $PostgreSQL: pgsql/src/backend/utils/misc/guc.c,v 1.273 2005/07/05 23:18:10 momjian Exp $
|
||||
* $PostgreSQL: pgsql/src/backend/utils/misc/guc.c,v 1.274 2005/07/14 05:13:42 tgl Exp $
|
||||
*
|
||||
*--------------------------------------------------------------------
|
||||
*/
|
||||
@@ -45,6 +45,7 @@
|
||||
#include "optimizer/prep.h"
|
||||
#include "parser/parse_expr.h"
|
||||
#include "parser/parse_relation.h"
|
||||
#include "postmaster/autovacuum.h"
|
||||
#include "postmaster/bgwriter.h"
|
||||
#include "postmaster/syslogger.h"
|
||||
#include "postmaster/postmaster.h"
|
||||
@@ -286,6 +287,8 @@ const char *const config_group_names[] =
|
||||
gettext_noop("Statistics / Monitoring"),
|
||||
/* STATS_COLLECTOR */
|
||||
gettext_noop("Statistics / Query and Index Statistics Collector"),
|
||||
/* AUTOVACUUM */
|
||||
gettext_noop("Auto Vacuum"),
|
||||
/* CLIENT_CONN */
|
||||
gettext_noop("Client Connection Defaults"),
|
||||
/* CLIENT_CONN_STATEMENT */
|
||||
@@ -678,6 +681,15 @@ static struct config_bool ConfigureNamesBool[] =
|
||||
false, NULL, NULL
|
||||
},
|
||||
|
||||
{
|
||||
{"autovacuum", PGC_SIGHUP, AUTOVACUUM,
|
||||
gettext_noop("Starts the auto vacuum subprocess."),
|
||||
NULL
|
||||
},
|
||||
&autovacuum_start_daemon,
|
||||
false, NULL, NULL
|
||||
},
|
||||
|
||||
{
|
||||
{"trace_notify", PGC_USERSET, DEVELOPER_OPTIONS,
|
||||
gettext_noop("Generates debugging output for LISTEN and NOTIFY."),
|
||||
@@ -1389,6 +1401,31 @@ static struct config_int ConfigureNamesInt[] =
|
||||
BLCKSZ, BLCKSZ, BLCKSZ, NULL, NULL
|
||||
},
|
||||
|
||||
{
|
||||
{"autovacuum_naptime", PGC_SIGHUP, AUTOVACUUM,
|
||||
gettext_noop("Time to sleep between autovacuum runs, in seconds."),
|
||||
NULL
|
||||
},
|
||||
&autovacuum_naptime,
|
||||
60, 0, INT_MAX, NULL, NULL
|
||||
},
|
||||
{
|
||||
{"autovacuum_vacuum_threshold", PGC_SIGHUP, AUTOVACUUM,
|
||||
gettext_noop("Minimum number of tuple updates or deletes prior to vacuum."),
|
||||
NULL
|
||||
},
|
||||
&autovacuum_vac_thresh,
|
||||
1000, 0, INT_MAX, NULL, NULL
|
||||
},
|
||||
{
|
||||
{"autovacuum_analyze_threshold", PGC_SIGHUP, AUTOVACUUM,
|
||||
gettext_noop("Minimum number of tuple inserts, updates or deletes prior to analyze."),
|
||||
NULL
|
||||
},
|
||||
&autovacuum_anl_thresh,
|
||||
500, 0, INT_MAX, NULL, NULL
|
||||
},
|
||||
|
||||
/* End-of-list marker */
|
||||
{
|
||||
{NULL, 0, 0, NULL, NULL}, NULL, 0, 0, 0, NULL, NULL
|
||||
@@ -1487,6 +1524,23 @@ static struct config_real ConfigureNamesReal[] =
|
||||
0.5, 0.0, 1.0, assign_random_seed, show_random_seed
|
||||
},
|
||||
|
||||
{
|
||||
{"autovacuum_vacuum_scale_factor", PGC_SIGHUP, AUTOVACUUM,
|
||||
gettext_noop("Number of tuple updates or deletes prior to vacuum as a fraction of reltuples."),
|
||||
NULL
|
||||
},
|
||||
&autovacuum_vac_scale,
|
||||
0.4, 0.0, 100.0, NULL, NULL
|
||||
},
|
||||
{
|
||||
{"autovacuum_analyze_scale_factor", PGC_SIGHUP, AUTOVACUUM,
|
||||
gettext_noop("Number of tuple inserts, updates or deletes prior to analyze as a fraction of reltuples."),
|
||||
NULL
|
||||
},
|
||||
&autovacuum_anl_scale,
|
||||
0.2, 0.0, 100.0, NULL, NULL
|
||||
},
|
||||
|
||||
/* End-of-list marker */
|
||||
{
|
||||
{NULL, 0, 0, NULL, NULL}, NULL, 0.0, 0.0, 0.0, NULL, NULL
|
||||
|
||||
@@ -284,6 +284,18 @@
|
||||
#stats_reset_on_server_start = on
|
||||
|
||||
|
||||
#---------------------------------------------------------------------------
|
||||
# AUTOVACUUM PARAMETERS
|
||||
#---------------------------------------------------------------------------
|
||||
|
||||
#autovacuum = false # enable autovacuum subprocess?
|
||||
#autovacuum_naptime = 60 # time between autovacuum runs, in seconds
|
||||
#autovacuum_vacuum_threshold = 1000 # min # of tuple updates before vacuum
|
||||
#autovacuum_analyze_threshold = 500 # min # of tuple updates before analyze
|
||||
#autovacuum_vacuum_scale_factor = 0.4 # fraction of rel size before vacuum
|
||||
#autovacuum_analyze_scale_factor = 0.2 # fraction of rel size before analyze
|
||||
|
||||
|
||||
#---------------------------------------------------------------------------
|
||||
# CLIENT CONNECTION DEFAULTS
|
||||
#---------------------------------------------------------------------------
|
||||
|
||||
Reference in New Issue
Block a user