diff options
| author | Tom Lane | 2005-07-14 05:13:45 +0000 |
|---|---|---|
| committer | Tom Lane | 2005-07-14 05:13:45 +0000 |
| commit | 29094193f526bf90671d71b59a2e007aad1fcae5 (patch) | |
| tree | 51e632c843ab9c7eedbd0b01f4de5b27c202443e /src/include | |
| parent | f2bf2d2dc5cef3f5b9cf50493490fa9931f982b2 (diff) | |
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.
Diffstat (limited to 'src/include')
| -rw-r--r-- | src/include/catalog/catversion.h | 4 | ||||
| -rw-r--r-- | src/include/catalog/indexing.h | 4 | ||||
| -rw-r--r-- | src/include/catalog/pg_autovacuum.h | 60 | ||||
| -rw-r--r-- | src/include/commands/vacuum.h | 4 | ||||
| -rw-r--r-- | src/include/pgstat.h | 85 | ||||
| -rw-r--r-- | src/include/postmaster/autovacuum.h | 38 | ||||
| -rw-r--r-- | src/include/tcop/tcopprot.h | 3 | ||||
| -rw-r--r-- | src/include/utils/guc_tables.h | 3 |
8 files changed, 184 insertions, 17 deletions
diff --git a/src/include/catalog/catversion.h b/src/include/catalog/catversion.h index 5ce6b4724e1..d87e9f9ce69 100644 --- a/src/include/catalog/catversion.h +++ b/src/include/catalog/catversion.h @@ -37,7 +37,7 @@ * Portions Copyright (c) 1996-2005, PostgreSQL Global Development Group * Portions Copyright (c) 1994, Regents of the University of California * - * $PostgreSQL: pgsql/src/include/catalog/catversion.h,v 1.288 2005/07/10 21:13:59 tgl Exp $ + * $PostgreSQL: pgsql/src/include/catalog/catversion.h,v 1.289 2005/07/14 05:13:42 tgl Exp $ * *------------------------------------------------------------------------- */ @@ -53,6 +53,6 @@ */ /* yyyymmddN */ -#define CATALOG_VERSION_NO 200507102 +#define CATALOG_VERSION_NO 200507131 #endif diff --git a/src/include/catalog/indexing.h b/src/include/catalog/indexing.h index 1ab33708f0c..0c4c095e40a 100644 --- a/src/include/catalog/indexing.h +++ b/src/include/catalog/indexing.h @@ -8,7 +8,7 @@ * Portions Copyright (c) 1996-2005, PostgreSQL Global Development Group * Portions Copyright (c) 1994, Regents of the University of California * - * $PostgreSQL: pgsql/src/include/catalog/indexing.h,v 1.89 2005/07/07 20:39:59 tgl Exp $ + * $PostgreSQL: pgsql/src/include/catalog/indexing.h,v 1.90 2005/07/14 05:13:42 tgl Exp $ * *------------------------------------------------------------------------- */ @@ -210,6 +210,8 @@ DECLARE_UNIQUE_INDEX(pg_type_oid_index,2703, on pg_type using btree(oid oid_ops) DECLARE_UNIQUE_INDEX(pg_type_typname_nsp_index,2704, on pg_type using btree(typname name_ops, typnamespace oid_ops)); #define TypeNameNspIndexId 2704 +DECLARE_UNIQUE_INDEX(pg_autovacuum_vacrelid_index,1250, on pg_autovacuum using btree(vacrelid oid_ops)); +#define AutovacuumRelidIndexId 1250 /* last step of initialization script: build the indexes declared above */ BUILD_INDICES diff --git a/src/include/catalog/pg_autovacuum.h b/src/include/catalog/pg_autovacuum.h new file mode 100644 index 00000000000..b0bfc204922 --- /dev/null +++ b/src/include/catalog/pg_autovacuum.h @@ -0,0 +1,60 @@ +/*------------------------------------------------------------------------- + * + * pg_autovacuum.h + * definition of the system "autovacuum" relation (pg_autovacuum) + * + * Portions Copyright (c) 1996-2005, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * $PostgreSQL: pgsql/src/include/catalog/pg_autovacuum.h,v 1.1 2005/07/14 05:13:42 tgl Exp $ + * + *------------------------------------------------------------------------- + */ +#ifndef PG_AUTOVACUUM_H +#define PG_AUTOVACUUM_H + +/* ---------------- + * postgres.h contains the system type definitions and the + * CATALOG(), BOOTSTRAP and DATA() sugar words so this file + * can be read by both genbki.sh and the C compiler. + * ---------------- + */ + +/* ---------------- + * pg_autovacuum definition. cpp turns this into + * typedef struct FormData_pg_autovacuum + * ---------------- + */ +#define AutovacuumRelationId 1248 +CATALOG(pg_autovacuum,1248) BKI_WITHOUT_OIDS +{ + Oid vacrelid; /* OID of table */ + bool enabled; /* enabled for this table? */ + int4 vac_base_thresh; /* base threshold value */ + float4 vac_scale_factor; /* reltuples scaling factor */ + int4 anl_base_thresh; /* base threshold value */ + float4 anl_scale_factor; /* reltuples scaling factor */ +} FormData_pg_autovacuum; + +/* ---------------- + * Form_pg_autovacuum corresponds to a pointer to a tuple with + * the format of pg_autovacuum relation. + * ---------------- + */ +typedef FormData_pg_autovacuum *Form_pg_autovacuum; + +/* ---------------- + * compiler constants for pg_autovacuum + * ---------------- + */ +#define Natts_pg_autovacuum 6 +#define Anum_pg_autovacuum_vacrelid 1 +#define Anum_pg_autovacuum_enabled 2 +#define Anum_pg_autovacuum_vac_base_thresh 3 +#define Anum_pg_autovacuum_vac_scale_factor 4 +#define Anum_pg_autovacuum_anl_base_thresh 5 +#define Anum_pg_autovacuum_anl_scale_factor 6 + +/* There are no preloaded tuples in pg_autovacuum.h */ + +#endif /* PG_AUTOVACUUM_H */ diff --git a/src/include/commands/vacuum.h b/src/include/commands/vacuum.h index 0434b6f5ec4..71ec0580229 100644 --- a/src/include/commands/vacuum.h +++ b/src/include/commands/vacuum.h @@ -7,7 +7,7 @@ * Portions Copyright (c) 1996-2005, PostgreSQL Global Development Group * Portions Copyright (c) 1994, Regents of the University of California * - * $PostgreSQL: pgsql/src/include/commands/vacuum.h,v 1.59 2004/12/31 22:03:28 pgsql Exp $ + * $PostgreSQL: pgsql/src/include/commands/vacuum.h,v 1.60 2005/07/14 05:13:43 tgl Exp $ * *------------------------------------------------------------------------- */ @@ -125,7 +125,7 @@ extern DLLIMPORT int default_statistics_target; /* DLLIMPORT for PostGIS */ /* in commands/vacuum.c */ -extern void vacuum(VacuumStmt *vacstmt); +extern void vacuum(VacuumStmt *vacstmt, List *relids); extern void vac_open_indexes(Relation relation, LOCKMODE lockmode, int *nindexes, Relation **Irel); extern void vac_close_indexes(int nindexes, Relation *Irel, LOCKMODE lockmode); diff --git a/src/include/pgstat.h b/src/include/pgstat.h index 5612d912909..4df12d77d38 100644 --- a/src/include/pgstat.h +++ b/src/include/pgstat.h @@ -5,7 +5,7 @@ * * Copyright (c) 2001-2005, PostgreSQL Global Development Group * - * $PostgreSQL: pgsql/src/include/pgstat.h,v 1.32 2005/06/29 22:51:57 tgl Exp $ + * $PostgreSQL: pgsql/src/include/pgstat.h,v 1.33 2005/07/14 05:13:43 tgl Exp $ * ---------- */ #ifndef PGSTAT_H @@ -20,14 +20,20 @@ * The types of backend/postmaster -> collector messages * ---------- */ -#define PGSTAT_MTYPE_DUMMY 0 -#define PGSTAT_MTYPE_BESTART 1 -#define PGSTAT_MTYPE_BETERM 2 -#define PGSTAT_MTYPE_ACTIVITY 3 -#define PGSTAT_MTYPE_TABSTAT 4 -#define PGSTAT_MTYPE_TABPURGE 5 -#define PGSTAT_MTYPE_DROPDB 6 -#define PGSTAT_MTYPE_RESETCOUNTER 7 +typedef enum StatMsgType +{ + PGSTAT_MTYPE_DUMMY, + PGSTAT_MTYPE_BESTART, + PGSTAT_MTYPE_BETERM, + PGSTAT_MTYPE_ACTIVITY, + PGSTAT_MTYPE_TABSTAT, + PGSTAT_MTYPE_TABPURGE, + PGSTAT_MTYPE_DROPDB, + PGSTAT_MTYPE_RESETCOUNTER, + PGSTAT_MTYPE_AUTOVAC_START, + PGSTAT_MTYPE_VACUUM, + PGSTAT_MTYPE_ANALYZE +} StatMsgType; /* ---------- * The data type used for counters. @@ -48,7 +54,7 @@ typedef int64 PgStat_Counter; */ typedef struct PgStat_MsgHdr { - int m_type; + StatMsgType m_type; int m_size; int m_backendid; int m_procpid; @@ -115,6 +121,47 @@ typedef struct PgStat_MsgBeterm } PgStat_MsgBeterm; /* ---------- + * PgStat_MsgAutovacStart Sent by the autovacuum daemon to signal + * that a database is going to be processed + * ---------- + */ +typedef struct PgStat_MsgAutovacStart +{ + PgStat_MsgHdr m_hdr; + Oid m_databaseid; + TimestampTz m_start_time; +} PgStat_MsgAutovacStart; + +/* ---------- + * PgStat_MsgVacuum Sent by the backend or autovacuum daemon + * after VACUUM or VACUUM ANALYZE + * ---------- + */ +typedef struct PgStat_MsgVacuum +{ + PgStat_MsgHdr m_hdr; + Oid m_databaseid; + Oid m_tableoid; + bool m_analyze; + PgStat_Counter m_tuples; +} PgStat_MsgVacuum; + +/* ---------- + * PgStat_MsgAnalyze Sent by the backend or autovacuum daemon + * after ANALYZE + * ---------- + */ +typedef struct PgStat_MsgAnalyze +{ + PgStat_MsgHdr m_hdr; + Oid m_databaseid; + Oid m_tableoid; + PgStat_Counter m_live_tuples; + PgStat_Counter m_dead_tuples; +} PgStat_MsgAnalyze; + + +/* ---------- * PgStat_MsgActivity Sent by the backends when they start * to parse a query. * ---------- @@ -200,14 +247,22 @@ typedef union PgStat_Msg PgStat_MsgTabpurge msg_tabpurge; PgStat_MsgDropdb msg_dropdb; PgStat_MsgResetcounter msg_resetcounter; + PgStat_MsgAutovacStart msg_autovacuum; + PgStat_MsgVacuum msg_vacuum; + PgStat_MsgAnalyze msg_analyze; } PgStat_Msg; /* ------------------------------------------------------------ * Statistic collector data structures follow + * + * PGSTAT_FILE_FORMAT_ID should be changed whenever any of these + * data structures change. * ------------------------------------------------------------ */ +#define PGSTAT_FILE_FORMAT_ID 0x01A5BC93 + /* ---------- * PgStat_StatDBEntry The collectors data per database * ---------- @@ -222,6 +277,7 @@ typedef struct PgStat_StatDBEntry PgStat_Counter n_blocks_fetched; PgStat_Counter n_blocks_hit; int destroy; + TimestampTz last_autovac_time; } PgStat_StatDBEntry; @@ -282,6 +338,10 @@ typedef struct PgStat_StatTabEntry PgStat_Counter tuples_updated; PgStat_Counter tuples_deleted; + PgStat_Counter n_live_tuples; + PgStat_Counter n_dead_tuples; + PgStat_Counter last_anl_tuples; + PgStat_Counter blocks_fetched; PgStat_Counter blocks_hit; @@ -323,6 +383,11 @@ extern void pgstat_bestart(void); extern void pgstat_ping(void); extern void pgstat_report_activity(const char *what); extern void pgstat_report_tabstat(void); +extern void pgstat_report_autovac(void); +extern void pgstat_report_vacuum(Oid tableoid, bool analyze, + PgStat_Counter tuples); +extern void pgstat_report_analyze(Oid tableoid, PgStat_Counter livetuples, + PgStat_Counter deadtuples); extern int pgstat_vacuum_tabstat(void); extern void pgstat_reset_counters(void); diff --git a/src/include/postmaster/autovacuum.h b/src/include/postmaster/autovacuum.h new file mode 100644 index 00000000000..85667af1cc6 --- /dev/null +++ b/src/include/postmaster/autovacuum.h @@ -0,0 +1,38 @@ +/*------------------------------------------------------------------------- + * + * autovacuum.h + * header file for integrated autovacuum daemon + * + * + * Portions Copyright (c) 1996-2005, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * $PostgreSQL: pgsql/src/include/postmaster/autovacuum.h,v 1.1 2005/07/14 05:13:43 tgl Exp $ + * + *------------------------------------------------------------------------- + */ +#ifndef AUTOVACUUM_H +#define AUTOVACUUM_H + +/* GUC variables */ +extern bool autovacuum_start_daemon; +extern int autovacuum_naptime; +extern int autovacuum_vac_thresh; +extern double autovacuum_vac_scale; +extern int autovacuum_anl_thresh; +extern double autovacuum_anl_scale; + +/* Status inquiry functions */ +extern bool AutoVacuumingActive(void); +extern bool IsAutoVacuumProcess(void); + +/* Functions to start autovacuum process, called from postmaster */ +extern void autovac_init(void); +extern int autovac_start(void); +extern void autovac_stopped(void); + +#ifdef EXEC_BACKEND +extern void AutoVacMain(int argc, char *argv[]); +#endif + +#endif /* AUTOVACUUM_H */ diff --git a/src/include/tcop/tcopprot.h b/src/include/tcop/tcopprot.h index d694146d59a..7886d66d7c9 100644 --- a/src/include/tcop/tcopprot.h +++ b/src/include/tcop/tcopprot.h @@ -7,7 +7,7 @@ * Portions Copyright (c) 1996-2005, PostgreSQL Global Development Group * Portions Copyright (c) 1994, Regents of the University of California * - * $PostgreSQL: pgsql/src/include/tcop/tcopprot.h,v 1.75 2005/06/03 23:05:30 tgl Exp $ + * $PostgreSQL: pgsql/src/include/tcop/tcopprot.h,v 1.76 2005/07/14 05:13:44 tgl Exp $ * * OLD COMMENTS * This file was created so that other c files could get the two @@ -58,6 +58,7 @@ extern bool assign_max_stack_depth(int newval, bool doit, GucSource source); extern void die(SIGNAL_ARGS); extern void quickdie(SIGNAL_ARGS); extern void authdie(SIGNAL_ARGS); +extern void StatementCancelHandler(SIGNAL_ARGS); extern void prepare_for_client_read(void); extern void client_read_ended(void); extern int PostgresMain(int argc, char *argv[], const char *username); diff --git a/src/include/utils/guc_tables.h b/src/include/utils/guc_tables.h index 39d2af3bab9..beddf5dd5f0 100644 --- a/src/include/utils/guc_tables.h +++ b/src/include/utils/guc_tables.h @@ -7,7 +7,7 @@ * * Portions Copyright (c) 1996-2005, PostgreSQL Global Development Group * - * $PostgreSQL: pgsql/src/include/utils/guc_tables.h,v 1.19 2004/12/31 22:03:46 pgsql Exp $ + * $PostgreSQL: pgsql/src/include/utils/guc_tables.h,v 1.20 2005/07/14 05:13:44 tgl Exp $ * *------------------------------------------------------------------------- */ @@ -62,6 +62,7 @@ enum config_group STATS, STATS_MONITORING, STATS_COLLECTOR, + AUTOVACUUM, CLIENT_CONN, CLIENT_CONN_STATEMENT, CLIENT_CONN_LOCALE, |
