-<!-- $PostgreSQL: pgsql/doc/src/sgml/catalogs.sgml,v 2.188 2009/01/09 15:02:22 momjian Exp $ -->
+<!-- $PostgreSQL: pgsql/doc/src/sgml/catalogs.sgml,v 2.189 2009/01/16 13:27:23 heikki Exp $ -->
<!--
Documentation of the system catalogs, directed toward PostgreSQL developers
-->
<entry></entry>
<entry>Custom <varname>autovacuum_freeze_max_age</> parameter</entry>
</row>
+
+ <row>
+ <entry><structfield>freeze_table_age</structfield></entry>
+ <entry><type>integer</type></entry>
+ <entry></entry>
+ <entry>Custom <varname>vacuum_freeze_table_age</> parameter</entry>
+ </row>
</tbody>
</tgroup>
</table>
-<!-- $PostgreSQL: pgsql/doc/src/sgml/config.sgml,v 1.205 2009/01/12 05:10:44 tgl Exp $ -->
+<!-- $PostgreSQL: pgsql/doc/src/sgml/config.sgml,v 1.206 2009/01/16 13:27:23 heikki Exp $ -->
<chapter Id="runtime-config">
<title>Server Configuration</title>
</listitem>
</varlistentry>
+ <varlistentry id="guc-vacuum-freeze-table-age" xreflabel="vacuum_freeze_table_age">
+ <term><varname>vacuum_freeze_table_age</varname> (<type>integer</type>)</term>
+ <indexterm>
+ <primary><varname>vacuum_freeze_table_age</> configuration parameter</primary>
+ </indexterm>
+ <listitem>
+ <para>
+ <command>VACUUM</> performs a whole-table scan if the table's
+ <structname>pg_class</>.<structfield>relfrozenxid</> field has reached
+ the age specified by this setting. The default is 150 million
+ transactions. Although users can set this value anywhere from zero to
+ one billion, <command>VACUUM</> will silently limit the effective value
+ to 95% of <xref linkend="guc-autovacuum-freeze-max-age">, so that a
+ periodical manual <command>VACUUM</> has a chance to run before an
+ anti-wraparound autovacuum is launched for the table. For more
+ information see
+ <xref linkend="vacuum-for-wraparound">.
+ </para>
+ </listitem>
+ </varlistentry>
+
<varlistentry id="guc-vacuum-freeze-min-age" xreflabel="vacuum_freeze_min_age">
<term><varname>vacuum_freeze_min_age</varname> (<type>integer</type>)</term>
<indexterm>
Specifies the cutoff age (in transactions) that <command>VACUUM</>
should use to decide whether to replace transaction IDs with
<literal>FrozenXID</> while scanning a table.
- The default is 100 million transactions. Although
+ The default is 50 million transactions. Although
users can set this value anywhere from zero to one billion,
<command>VACUUM</> will silently limit the effective value to half
the value of <xref linkend="guc-autovacuum-freeze-max-age">, so
-<!-- $PostgreSQL: pgsql/doc/src/sgml/maintenance.sgml,v 1.88 2008/12/11 18:16:18 tgl Exp $ -->
+<!-- $PostgreSQL: pgsql/doc/src/sgml/maintenance.sgml,v 1.89 2009/01/16 13:27:23 heikki Exp $ -->
<chapter id="maintenance">
<title>Routine Database Maintenance Tasks</title>
</para>
<para>
- <command>VACUUM</>'s behavior is controlled by the configuration parameter
- <xref linkend="guc-vacuum-freeze-min-age">: any XID older than
- <varname>vacuum_freeze_min_age</> transactions is replaced by
- <literal>FrozenXID</>. Larger values of <varname>vacuum_freeze_min_age</>
+ <command>VACUUM</>'s behavior is controlled by the two configuration
+ parameters: <xref linkend="guc-vacuum-freeze-min-age"> and
+ <xref linkend="guc-vacuum-freeze-table-age">.
+ <varname>vacuum_freeze_table_age</> controls when <command>VACUUM</>
+ performs a full sweep of the table, in order to replace old XID values
+ with <literal>FrozenXID</>. <varname>vacuum_freeze_min_age</>
+ controls how old an XID value has to be before it's replaced with
+ <literal>FrozenXID</>. Larger values of these settings
preserve transactional information longer, while smaller values increase
the number of transactions that can elapse before the table must be
vacuumed again.
<para>
The maximum time that a table can go unvacuumed is two billion
transactions minus the <varname>vacuum_freeze_min_age</> that was used
- when it was last vacuumed. If it were to go unvacuumed for longer than
+ when <command>VACUUM</> last scanned the whole table. If it were to go
+ unvacuumed for longer than
that, data loss could result. To ensure that this does not happen,
autovacuum is invoked on any table that might contain XIDs older than the
age specified by the configuration parameter <xref
</para>
<para>
- The sole disadvantage of increasing <varname>autovacuum_freeze_max_age</>
+ The sole disadvantage of increasing <varname>vacuum_freeze_table_age</>
+ and <varname>autovacuum_freeze_max_age</>
is that the <filename>pg_clog</> subdirectory of the database cluster
will take more space, because it must store the commit status for all
transactions back to the <varname>autovacuum_freeze_max_age</> horizon.
<varname>autovacuum_freeze_max_age</> has its maximum allowed value of
a little less than two billion, <filename>pg_clog</> can be expected to
grow to about half a gigabyte. If this is trivial compared to your
- total database size, setting <varname>autovacuum_freeze_max_age</> to
- its maximum allowed value is recommended. Otherwise, set it depending
+ total database size, setting <varname>autovacuum_freeze_max_age</> and
+ <varname>vacuum_freeze_table_age</varname> to their maximum allowed values
+ is recommended. Otherwise, set them depending
on what you are willing to allow for <filename>pg_clog</> storage.
(The default, 200 million transactions, translates to about 50MB of
<filename>pg_clog</> storage.)
</programlisting>
The <literal>age</> column measures the number of transactions from the
- cutoff XID to the current transaction's XID. Immediately after a
- <command>VACUUM</>, <literal>age(relfrozenxid)</> should be a little
- more than the <varname>vacuum_freeze_min_age</> setting that was used
- (more by the number of transactions started since the <command>VACUUM</>
- started). If <literal>age(relfrozenxid)</> exceeds
- <varname>autovacuum_freeze_max_age</>, an autovacuum will soon be forced
- for the table.
+ cutoff XID to the current transaction's XID. When <command>VACUUM</>
+ scans the whole table, after it's finished <literal>age(relfrozenxid)</>
+ should be a little more than the <varname>vacuum_freeze_min_age</> setting
+ that was used (more by the number of transactions started since the
+ <command>VACUUM</> started).
+ </para>
+
+ <para>
+ <command>VACUUM</> normally only scans pages that have been modified
+ since last vacuum, but <structfield>relfrozenxid</> can only be advanced
+ when the whole table is scanned. The whole table is scanned when
+ <structfield>relfrozenxid</> is more than
+ <varname>vacuum_freeze_table_age</> transactions old, if
+ <command>VACUUM FREEZE</> command is used, or if all pages happen to
+ require vacuuming to remove dead row versions. If no whole-table-scanning
+ <command>VACUUM</> is issued on the table until
+ <varname>autovacuum_freeze_max_age</> is reached, an autovacuum will soon
+ be forced for the table.
</para>
<para>
*
*
* IDENTIFICATION
- * $PostgreSQL: pgsql/src/backend/commands/cluster.c,v 1.180 2009/01/01 17:23:37 momjian Exp $
+ * $PostgreSQL: pgsql/src/backend/commands/cluster.c,v 1.181 2009/01/16 13:27:23 heikki Exp $
*
*-------------------------------------------------------------------------
*/
* freeze_min_age to avoid having CLUSTER freeze tuples earlier than a
* plain VACUUM would.
*/
- vacuum_set_xid_limits(-1, OldHeap->rd_rel->relisshared,
- &OldestXmin, &FreezeXid);
+ vacuum_set_xid_limits(-1, -1, OldHeap->rd_rel->relisshared,
+ &OldestXmin, &FreezeXid, NULL);
/*
* FreezeXid will become the table's new relfrozenxid, and that mustn't
*
*
* IDENTIFICATION
- * $PostgreSQL: pgsql/src/backend/commands/vacuum.c,v 1.384 2009/01/01 17:23:40 momjian Exp $
+ * $PostgreSQL: pgsql/src/backend/commands/vacuum.c,v 1.385 2009/01/16 13:27:23 heikki Exp $
*
*-------------------------------------------------------------------------
*/
* GUC parameters
*/
int vacuum_freeze_min_age;
+int vacuum_freeze_table_age;
/*
* VacPage structures keep track of each page on which we find useful
* vacuum_set_xid_limits() -- compute oldest-Xmin and freeze cutoff points
*/
void
-vacuum_set_xid_limits(int freeze_min_age, bool sharedRel,
+vacuum_set_xid_limits(int freeze_min_age,
+ int freeze_table_age,
+ bool sharedRel,
TransactionId *oldestXmin,
- TransactionId *freezeLimit)
+ TransactionId *freezeLimit,
+ TransactionId *freezeTableLimit)
{
int freezemin;
TransactionId limit;
}
*freezeLimit = limit;
+
+ if (freezeTableLimit != NULL)
+ {
+ int freezetable;
+
+ /*
+ * Determine the table freeze age to use: as specified by the caller,
+ * or vacuum_freeze_table_age, but in any case not more than
+ * autovacuum_freeze_max_age * 0.95, so that if you have e.g nightly
+ * VACUUM schedule, the nightly VACUUM gets a chance to freeze tuples
+ * before anti-wraparound autovacuum is launched.
+ */
+ freezetable = freeze_min_age;
+ if (freezetable < 0)
+ freezetable = vacuum_freeze_table_age;
+ freezetable = Min(freezetable, autovacuum_freeze_max_age * 0.95);
+ Assert(freezetable >= 0);
+
+ /*
+ * Compute the cutoff XID, being careful not to generate a
+ * "permanent" XID.
+ */
+ limit = ReadNewTransactionId() - freezetable;
+ if (!TransactionIdIsNormal(limit))
+ limit = FirstNormalTransactionId;
+
+ *freezeTableLimit = limit;
+ }
}
i;
VRelStats *vacrelstats;
- vacuum_set_xid_limits(vacstmt->freeze_min_age, onerel->rd_rel->relisshared,
- &OldestXmin, &FreezeLimit);
+ vacuum_set_xid_limits(vacstmt->freeze_min_age, vacstmt->freeze_table_age,
+ onerel->rd_rel->relisshared,
+ &OldestXmin, &FreezeLimit, NULL);
/*
* Flush any previous async-commit transactions. This does not guarantee
*
*
* IDENTIFICATION
- * $PostgreSQL: pgsql/src/backend/commands/vacuumlazy.c,v 1.116 2009/01/06 14:55:37 heikki Exp $
+ * $PostgreSQL: pgsql/src/backend/commands/vacuumlazy.c,v 1.117 2009/01/16 13:27:23 heikki Exp $
*
*-------------------------------------------------------------------------
*/
BlockNumber possibly_freeable;
PGRUsage ru0;
TimestampTz starttime = 0;
+ bool scan_all;
+ TransactionId freezeTableLimit;
pg_rusage_init(&ru0);
vac_strategy = bstrategy;
- vacuum_set_xid_limits(vacstmt->freeze_min_age, onerel->rd_rel->relisshared,
- &OldestXmin, &FreezeLimit);
+ vacuum_set_xid_limits(vacstmt->freeze_min_age, vacstmt->freeze_table_age,
+ onerel->rd_rel->relisshared,
+ &OldestXmin, &FreezeLimit, &freezeTableLimit);
+ scan_all = TransactionIdPrecedesOrEquals(onerel->rd_rel->relfrozenxid,
+ freezeTableLimit);
vacrelstats = (LVRelStats *) palloc0(sizeof(LVRelStats));
vacrelstats->hasindex = (nindexes > 0);
/* Do the vacuuming */
- lazy_scan_heap(onerel, vacrelstats, Irel, nindexes, vacstmt->scan_all);
+ lazy_scan_heap(onerel, vacrelstats, Irel, nindexes, scan_all);
/* Done with indexes */
vac_close_indexes(nindexes, Irel, NoLock);
* Portions Copyright (c) 1994, Regents of the University of California
*
* IDENTIFICATION
- * $PostgreSQL: pgsql/src/backend/nodes/copyfuncs.c,v 1.419 2009/01/01 17:23:43 momjian Exp $
+ * $PostgreSQL: pgsql/src/backend/nodes/copyfuncs.c,v 1.420 2009/01/16 13:27:23 heikki Exp $
*
*-------------------------------------------------------------------------
*/
COPY_SCALAR_FIELD(analyze);
COPY_SCALAR_FIELD(verbose);
COPY_SCALAR_FIELD(freeze_min_age);
- COPY_SCALAR_FIELD(scan_all);
+ COPY_SCALAR_FIELD(freeze_table_age);
COPY_NODE_FIELD(relation);
COPY_NODE_FIELD(va_cols);
* Portions Copyright (c) 1994, Regents of the University of California
*
* IDENTIFICATION
- * $PostgreSQL: pgsql/src/backend/nodes/equalfuncs.c,v 1.344 2009/01/01 17:23:43 momjian Exp $
+ * $PostgreSQL: pgsql/src/backend/nodes/equalfuncs.c,v 1.345 2009/01/16 13:27:23 heikki Exp $
*
*-------------------------------------------------------------------------
*/
COMPARE_SCALAR_FIELD(analyze);
COMPARE_SCALAR_FIELD(verbose);
COMPARE_SCALAR_FIELD(freeze_min_age);
- COMPARE_SCALAR_FIELD(scan_all);
+ COMPARE_SCALAR_FIELD(freeze_table_age);
COMPARE_NODE_FIELD(relation);
COMPARE_NODE_FIELD(va_cols);
*
*
* IDENTIFICATION
- * $PostgreSQL: pgsql/src/backend/parser/gram.y,v 2.654 2009/01/12 09:38:30 petere Exp $
+ * $PostgreSQL: pgsql/src/backend/parser/gram.y,v 2.655 2009/01/16 13:27:23 heikki Exp $
*
* HISTORY
* AUTHOR DATE MAJOR EVENT
n->analyze = false;
n->full = $2;
n->freeze_min_age = $3 ? 0 : -1;
- n->scan_all = $2 || $3;
+ n->freeze_table_age = $3 ? 0 : -1;
n->verbose = $4;
n->relation = NULL;
n->va_cols = NIL;
n->analyze = false;
n->full = $2;
n->freeze_min_age = $3 ? 0 : -1;
- n->scan_all = $2 || $3;
+ n->freeze_table_age = $3 ? 0 : -1;
n->verbose = $4;
n->relation = $5;
n->va_cols = NIL;
n->vacuum = true;
n->full = $2;
n->freeze_min_age = $3 ? 0 : -1;
- n->scan_all = $2 || $3;
+ n->freeze_table_age = $3 ? 0 : -1;
n->verbose |= $4;
$$ = (Node *)n;
}
n->analyze = true;
n->full = false;
n->freeze_min_age = -1;
+ n->freeze_table_age = -1;
n->verbose = $2;
n->relation = NULL;
n->va_cols = NIL;
n->analyze = true;
n->full = false;
n->freeze_min_age = -1;
+ n->freeze_table_age = -1;
n->verbose = $2;
n->relation = $3;
n->va_cols = $4;
*
*
* IDENTIFICATION
- * $PostgreSQL: pgsql/src/backend/postmaster/autovacuum.c,v 1.91 2009/01/01 17:23:46 momjian Exp $
+ * $PostgreSQL: pgsql/src/backend/postmaster/autovacuum.c,v 1.92 2009/01/16 13:27:24 heikki Exp $
*
*-------------------------------------------------------------------------
*/
/* Comparison point for determining whether freeze_max_age is exceeded */
static TransactionId recentXid;
-/* Default freeze_min_age to use for autovacuum (varies by database) */
+/* Default freeze ages to use for autovacuum (varies by database) */
static int default_freeze_min_age;
+static int default_freeze_table_age;
/* Memory context for long-lived data */
static MemoryContext AutovacMemCxt;
bool at_dovacuum;
bool at_doanalyze;
int at_freeze_min_age;
+ int at_freeze_table_age;
int at_vacuum_cost_delay;
int at_vacuum_cost_limit;
bool at_wraparound;
pgstat_vacuum_stat();
/*
- * Find the pg_database entry and select the default freeze_min_age. We
+ * Find the pg_database entry and select the default freeze ages. We
* use zero in template and nonconnectable databases, else the system-wide
* default.
*/
dbForm = (Form_pg_database) GETSTRUCT(tuple);
if (dbForm->datistemplate || !dbForm->datallowconn)
+ {
default_freeze_min_age = 0;
+ default_freeze_table_age = 0;
+ }
else
+ {
default_freeze_min_age = vacuum_freeze_min_age;
+ default_freeze_table_age = vacuum_freeze_table_age;
+ }
ReleaseSysCache(tuple);
if (doanalyze || dovacuum)
{
int freeze_min_age;
+ int freeze_table_age;
int vac_cost_limit;
int vac_cost_delay;
freeze_min_age = (avForm->freeze_min_age >= 0) ?
avForm->freeze_min_age : default_freeze_min_age;
+
+ freeze_table_age = (avForm->freeze_table_age >= 0) ?
+ avForm->freeze_table_age : default_freeze_table_age;
}
else
{
autovacuum_vac_cost_delay : VacuumCostDelay;
freeze_min_age = default_freeze_min_age;
+
+ freeze_table_age = default_freeze_table_age;
}
tab = palloc(sizeof(autovac_table));
tab->at_dovacuum = dovacuum;
tab->at_doanalyze = doanalyze;
tab->at_freeze_min_age = freeze_min_age;
+ tab->at_freeze_table_age = freeze_table_age;
tab->at_vacuum_cost_limit = vac_cost_limit;
tab->at_vacuum_cost_delay = vac_cost_delay;
tab->at_wraparound = wraparound;
vacstmt.full = false;
vacstmt.analyze = tab->at_doanalyze;
vacstmt.freeze_min_age = tab->at_freeze_min_age;
- vacstmt.scan_all = tab->at_wraparound;
+ vacstmt.freeze_table_age = tab->at_freeze_table_age;
vacstmt.verbose = false;
vacstmt.relation = NULL; /* not used since we pass a relid */
vacstmt.va_cols = NIL;
* Written by Peter Eisentraut <peter_e@gmx.net>.
*
* IDENTIFICATION
- * $PostgreSQL: pgsql/src/backend/utils/misc/guc.c,v 1.493 2009/01/12 05:10:44 tgl Exp $
+ * $PostgreSQL: pgsql/src/backend/utils/misc/guc.c,v 1.494 2009/01/16 13:27:24 heikki Exp $
*
*--------------------------------------------------------------------
*/
NULL
},
&vacuum_freeze_min_age,
- 100000000, 0, 1000000000, NULL, NULL
+ 50000000, 0, 1000000000, NULL, NULL
+ },
+
+ {
+ {"vacuum_freeze_table_age", PGC_USERSET, CLIENT_CONN_STATEMENT,
+ gettext_noop("Age at which VACUUM should scan whole table to freeze tuples."),
+ NULL
+ },
+ &vacuum_freeze_table_age,
+ 150000000, 0, 2000000000, NULL, NULL
},
{
#default_transaction_read_only = off
#session_replication_role = 'origin'
#statement_timeout = 0 # 0 is disabled
-#vacuum_freeze_min_age = 100000000
+#vacuum_freeze_min_age = 50000000
+#vacuum_freeze_table_age = 150000000
#xmlbinary = 'base64'
#xmloption = 'content'
* Portions Copyright (c) 1996-2009, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California
*
- * $PostgreSQL: pgsql/src/include/catalog/catversion.h,v 1.517 2009/01/05 17:14:28 alvherre Exp $
+ * $PostgreSQL: pgsql/src/include/catalog/catversion.h,v 1.518 2009/01/16 13:27:24 heikki Exp $
*
*-------------------------------------------------------------------------
*/
*/
/* yyyymmddN */
-#define CATALOG_VERSION_NO 200901051
+#define CATALOG_VERSION_NO 200901161
#endif
* Portions Copyright (c) 1996-2009, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California
*
- * $PostgreSQL: pgsql/src/include/catalog/pg_autovacuum.h,v 1.10 2009/01/01 17:23:56 momjian Exp $
+ * $PostgreSQL: pgsql/src/include/catalog/pg_autovacuum.h,v 1.11 2009/01/16 13:27:24 heikki Exp $
*
*-------------------------------------------------------------------------
*/
int4 vac_cost_limit; /* vacuum cost limit */
int4 freeze_min_age; /* vacuum min freeze age */
int4 freeze_max_age; /* max age before forcing vacuum */
+ int4 freeze_table_age; /* age at which vacuum scans whole table */
} FormData_pg_autovacuum;
/* ----------------
#define Anum_pg_autovacuum_vac_cost_limit 8
#define Anum_pg_autovacuum_freeze_min_age 9
#define Anum_pg_autovacuum_freeze_max_age 10
+#define Anum_pg_autovacuum_freeze_table_age 11
/* There are no preloaded tuples in pg_autovacuum.h */
* Portions Copyright (c) 1996-2009, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California
*
- * $PostgreSQL: pgsql/src/include/commands/vacuum.h,v 1.83 2009/01/01 17:23:58 momjian Exp $
+ * $PostgreSQL: pgsql/src/include/commands/vacuum.h,v 1.84 2009/01/16 13:27:24 heikki Exp $
*
*-------------------------------------------------------------------------
*/
extern PGDLLIMPORT int default_statistics_target; /* PGDLLIMPORT for
* PostGIS */
extern int vacuum_freeze_min_age;
+extern int vacuum_freeze_table_age;
/* in commands/vacuum.c */
double num_tuples,
bool hasindex,
TransactionId frozenxid);
-extern void vacuum_set_xid_limits(int freeze_min_age, bool sharedRel,
+extern void vacuum_set_xid_limits(int freeze_min_age, int freeze_table_age,
+ bool sharedRel,
TransactionId *oldestXmin,
- TransactionId *freezeLimit);
+ TransactionId *freezeLimit,
+ TransactionId *freezeTableLimit);
extern void vac_update_datfrozenxid(void);
extern bool vac_is_partial_index(Relation indrel);
extern void vacuum_delay_point(void);
* Portions Copyright (c) 1996-2009, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California
*
- * $PostgreSQL: pgsql/src/include/nodes/parsenodes.h,v 1.387 2009/01/01 17:24:00 momjian Exp $
+ * $PostgreSQL: pgsql/src/include/nodes/parsenodes.h,v 1.388 2009/01/16 13:27:24 heikki Exp $
*
*-------------------------------------------------------------------------
*/
bool full; /* do FULL (non-concurrent) vacuum */
bool analyze; /* do ANALYZE step */
bool verbose; /* print progress info */
- bool scan_all; /* force scan of all pages */
int freeze_min_age; /* min freeze age, or -1 to use default */
+ int freeze_table_age; /* age at which to scan whole table */
RangeVar *relation; /* single table to process, or NULL */
List *va_cols; /* list of column names, or NIL for all */
} VacuumStmt;