Commit 834a6da4 authored by Alvaro Herrera's avatar Alvaro Herrera

Update autovacuum to use reloptions instead of a system catalog, for

per-table overrides of parameters.

This removes a whole class of problems related to misusing the catalog,
and perhaps more importantly, gives us pg_dump support for the parameters.

Based on a patch by Euler Taveira de Oliveira, heavily reworked by me.
parent 57b10ebc
<!-- $PostgreSQL: pgsql/doc/src/sgml/catalogs.sgml,v 2.196 2009/02/07 19:27:25 momjian Exp $ --> <!-- $PostgreSQL: pgsql/doc/src/sgml/catalogs.sgml,v 2.197 2009/02/09 20:57:59 alvherre Exp $ -->
<!-- <!--
Documentation of the system catalogs, directed toward PostgreSQL developers Documentation of the system catalogs, directed toward PostgreSQL developers
--> -->
...@@ -88,11 +88,6 @@ ...@@ -88,11 +88,6 @@
<entry>authorization identifier membership relationships</entry> <entry>authorization identifier membership relationships</entry>
</row> </row>
<row>
<entry><link linkend="catalog-pg-autovacuum"><structname>pg_autovacuum</structname></link></entry>
<entry>per-relation autovacuum configuration parameters</entry>
</row>
<row> <row>
<entry><link linkend="catalog-pg-cast"><structname>pg_cast</structname></link></entry> <entry><link linkend="catalog-pg-cast"><structname>pg_cast</structname></link></entry>
<entry>casts (data type conversions)</entry> <entry>casts (data type conversions)</entry>
...@@ -1256,178 +1251,6 @@ ...@@ -1256,178 +1251,6 @@
</sect1> </sect1>
<sect1 id="catalog-pg-autovacuum">
<title><structname>pg_autovacuum</structname></title>
<indexterm zone="catalog-pg-autovacuum">
<primary>pg_autovacuum</primary>
</indexterm>
<indexterm zone="catalog-pg-autovacuum">
<primary>autovacuum</primary>
<secondary>table-specific configuration</secondary>
</indexterm>
<para>
The catalog <structname>pg_autovacuum</structname> stores optional
per-relation configuration parameters for the autovacuum daemon.
If there is an entry here for a particular relation, the given
parameters will be used for autovacuuming that table. If no entry
is present, the system-wide defaults will be used. For more information
about the autovacuum daemon, see <xref linkend="autovacuum">.
</para>
<note>
<para>
It is likely that <structname>pg_autovacuum</structname> will disappear
in a future release, with the information instead being kept in
<structname>pg_class</>.<structfield>reloptions</> entries.
</para>
</note>
<table>
<title><structname>pg_autovacuum</> Columns</title>
<tgroup cols="4">
<thead>
<row>
<entry>Name</entry>
<entry>Type</entry>
<entry>References</entry>
<entry>Description</entry>
</row>
</thead>
<tbody>
<row>
<entry><structfield>vacrelid</structfield></entry>
<entry><type>oid</type></entry>
<entry><literal><link linkend="catalog-pg-class"><structname>pg_class</structname></link>.oid</literal></entry>
<entry>The table this entry is for</entry>
</row>
<row>
<entry><structfield>enabled</structfield></entry>
<entry><type>bool</type></entry>
<entry></entry>
<entry>If false, this table will not be autovacuumed, except
to prevent transaction ID wraparound</entry>
</row>
<row>
<entry><structfield>vac_base_thresh</structfield></entry>
<entry><type>integer</type></entry>
<entry></entry>
<entry>Minimum number of modified tuples before vacuum</entry>
</row>
<row>
<entry><structfield>vac_scale_factor</structfield></entry>
<entry><type>float4</type></entry>
<entry></entry>
<entry>Multiplier for <structfield>reltuples</> to add to
<structfield>vac_base_thresh</></entry>
</row>
<row>
<entry><structfield>anl_base_thresh</structfield></entry>
<entry><type>integer</type></entry>
<entry></entry>
<entry>Minimum number of modified tuples before analyze</entry>
</row>
<row>
<entry><structfield>anl_scale_factor</structfield></entry>
<entry><type>float4</type></entry>
<entry></entry>
<entry>Multiplier for <structfield>reltuples</> to add to
<structfield>anl_base_thresh</></entry>
</row>
<row>
<entry><structfield>vac_cost_delay</structfield></entry>
<entry><type>integer</type></entry>
<entry></entry>
<entry>Custom <varname>vacuum_cost_delay</> parameter</entry>
</row>
<row>
<entry><structfield>vac_cost_limit</structfield></entry>
<entry><type>integer</type></entry>
<entry></entry>
<entry>Custom <varname>vacuum_cost_limit</> parameter</entry>
</row>
<row>
<entry><structfield>freeze_min_age</structfield></entry>
<entry><type>integer</type></entry>
<entry></entry>
<entry>Custom <varname>vacuum_freeze_min_age</> parameter</entry>
</row>
<row>
<entry><structfield>freeze_max_age</structfield></entry>
<entry><type>integer</type></entry>
<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>
<para>
The autovacuum daemon will initiate a <command>VACUUM</> operation
on a particular table when the number of updated or deleted tuples
exceeds <structfield>vac_base_thresh</structfield> plus
<structfield>vac_scale_factor</structfield> times the number of
live tuples currently estimated to be in the relation.
Similarly, it will initiate an <command>ANALYZE</> operation
when the number of inserted, updated or deleted tuples
exceeds <structfield>anl_base_thresh</structfield> plus
<structfield>anl_scale_factor</structfield> times the number of
live tuples currently estimated to be in the relation.
</para>
<para>
Also, the autovacuum daemon will perform a <command>VACUUM</> operation
to prevent transaction ID wraparound if the table's
<structname>pg_class</>.<structfield>relfrozenxid</> field attains an age
of more than <structfield>freeze_max_age</> transactions, whether the table
has been changed or not, even if
<structname>pg_autovacuum</>.<structfield>enabled</> is set to
<literal>false</> for it. The system will launch autovacuum to perform
such <command>VACUUM</>s even if autovacuum is otherwise disabled.
See <xref linkend="vacuum-for-wraparound"> for more about wraparound
prevention.
</para>
<para>
Any of the numerical fields can contain <literal>-1</> (or indeed
any negative value) to indicate that the system-wide default should
be used for this particular value. Observe that the
<structfield>vac_cost_delay</> variable inherits its default value from the
<xref linkend="guc-autovacuum-vacuum-cost-delay"> configuration parameter,
or from <xref linkend="guc-vacuum-cost-delay"> if the former is set to a
negative value. The same applies to <structfield>vac_cost_limit</>.
Also, autovacuum will ignore attempts to set a per-table
<structfield>freeze_max_age</> larger than the system-wide setting (it can
only be set smaller), and the <structfield>freeze_min_age</> value will be
limited to half the system-wide <xref
linkend="guc-autovacuum-freeze-max-age"> setting. Note that while you
can set <structfield>freeze_max_age</> very small, or even zero, this
is usually unwise since it will force frequent vacuuming.
</para>
</sect1>
<sect1 id="catalog-pg-cast"> <sect1 id="catalog-pg-cast">
<title><structname>pg_cast</structname></title> <title><structname>pg_cast</structname></title>
......
<!-- $PostgreSQL: pgsql/doc/src/sgml/config.sgml,v 1.206 2009/01/16 13:27:23 heikki Exp $ --> <!-- $PostgreSQL: pgsql/doc/src/sgml/config.sgml,v 1.207 2009/02/09 20:57:59 alvherre Exp $ -->
<chapter Id="runtime-config"> <chapter Id="runtime-config">
<title>Server Configuration</title> <title>Server Configuration</title>
...@@ -3547,8 +3547,8 @@ COPY postgres_log FROM '/full/path/to/logfile.csv' WITH csv; ...@@ -3547,8 +3547,8 @@ COPY postgres_log FROM '/full/path/to/logfile.csv' WITH csv;
The default is 50 tuples. The default is 50 tuples.
This parameter can only be set in the <filename>postgresql.conf</> This parameter can only be set in the <filename>postgresql.conf</>
file or on the server command line. file or on the server command line.
This setting can be overridden for individual tables by entries in This setting can be overridden for individual tables by
<structname>pg_autovacuum</>. changing storage parameters.
</para> </para>
</listitem> </listitem>
</varlistentry> </varlistentry>
...@@ -3565,8 +3565,8 @@ COPY postgres_log FROM '/full/path/to/logfile.csv' WITH csv; ...@@ -3565,8 +3565,8 @@ COPY postgres_log FROM '/full/path/to/logfile.csv' WITH csv;
The default is 50 tuples. The default is 50 tuples.
This parameter can only be set in the <filename>postgresql.conf</> This parameter can only be set in the <filename>postgresql.conf</>
file or on the server command line. file or on the server command line.
This setting can be overridden for individual tables by entries in This setting can be overridden for individual tables by
<structname>pg_autovacuum</>. changing storage parameters.
</para> </para>
</listitem> </listitem>
</varlistentry> </varlistentry>
...@@ -3584,8 +3584,8 @@ COPY postgres_log FROM '/full/path/to/logfile.csv' WITH csv; ...@@ -3584,8 +3584,8 @@ COPY postgres_log FROM '/full/path/to/logfile.csv' WITH csv;
The default is 0.2 (20% of table size). The default is 0.2 (20% of table size).
This parameter can only be set in the <filename>postgresql.conf</> This parameter can only be set in the <filename>postgresql.conf</>
file or on the server command line. file or on the server command line.
This setting can be overridden for individual tables by entries in This setting can be overridden for individual tables by
<structname>pg_autovacuum</>. changing storage parameters.
</para> </para>
</listitem> </listitem>
</varlistentry> </varlistentry>
...@@ -3603,8 +3603,8 @@ COPY postgres_log FROM '/full/path/to/logfile.csv' WITH csv; ...@@ -3603,8 +3603,8 @@ COPY postgres_log FROM '/full/path/to/logfile.csv' WITH csv;
The default is 0.1 (10% of table size). The default is 0.1 (10% of table size).
This parameter can only be set in the <filename>postgresql.conf</> This parameter can only be set in the <filename>postgresql.conf</>
file or on the server command line. file or on the server command line.
This setting can be overridden for individual tables by entries in This setting can be overridden for individual tables by
<structname>pg_autovacuum</>. changing storage parameters.
</para> </para>
</listitem> </listitem>
</varlistentry> </varlistentry>
...@@ -3624,8 +3624,8 @@ COPY postgres_log FROM '/full/path/to/logfile.csv' WITH csv; ...@@ -3624,8 +3624,8 @@ COPY postgres_log FROM '/full/path/to/logfile.csv' WITH csv;
autovacuum is otherwise disabled. autovacuum is otherwise disabled.
The default is 200 million transactions. The default is 200 million transactions.
This parameter can only be set at server start, but the setting This parameter can only be set at server start, but the setting
can be reduced for individual tables by entries in can be reduced for individual tables by
<structname>pg_autovacuum</>. changing storage parameters.
For more information see <xref linkend="vacuum-for-wraparound">. For more information see <xref linkend="vacuum-for-wraparound">.
</para> </para>
</listitem> </listitem>
...@@ -3645,8 +3645,8 @@ COPY postgres_log FROM '/full/path/to/logfile.csv' WITH csv; ...@@ -3645,8 +3645,8 @@ COPY postgres_log FROM '/full/path/to/logfile.csv' WITH csv;
The default value is 20 milliseconds. The default value is 20 milliseconds.
This parameter can only be set in the <filename>postgresql.conf</> This parameter can only be set in the <filename>postgresql.conf</>
file or on the server command line. file or on the server command line.
This setting can be overridden for individual tables by entries in This setting can be overridden for individual tables by
<structname>pg_autovacuum</>. changing storage parameters.
</para> </para>
</listitem> </listitem>
</varlistentry> </varlistentry>
...@@ -3667,8 +3667,8 @@ COPY postgres_log FROM '/full/path/to/logfile.csv' WITH csv; ...@@ -3667,8 +3667,8 @@ COPY postgres_log FROM '/full/path/to/logfile.csv' WITH csv;
each worker never exceeds the limit on this variable. each worker never exceeds the limit on this variable.
This parameter can only be set in the <filename>postgresql.conf</> This parameter can only be set in the <filename>postgresql.conf</>
file or on the server command line. file or on the server command line.
This setting can be overridden for individual tables by entries in This setting can be overridden for individual tables by
<structname>pg_autovacuum</>. changing storage parameters.
</para> </para>
</listitem> </listitem>
</varlistentry> </varlistentry>
......
<!-- $PostgreSQL: pgsql/doc/src/sgml/maintenance.sgml,v 1.89 2009/01/16 13:27:23 heikki Exp $ --> <!-- $PostgreSQL: pgsql/doc/src/sgml/maintenance.sgml,v 1.90 2009/02/09 20:57:59 alvherre Exp $ -->
<chapter id="maintenance"> <chapter id="maintenance">
<title>Routine Database Maintenance Tasks</title> <title>Routine Database Maintenance Tasks</title>
...@@ -573,7 +573,9 @@ HINT: Stop the postmaster and use a standalone backend to VACUUM in "mydb". ...@@ -573,7 +573,9 @@ HINT: Stop the postmaster and use a standalone backend to VACUUM in "mydb".
<para> <para>
Tables whose <structfield>relfrozenxid</> value is more than Tables whose <structfield>relfrozenxid</> value is more than
<varname>autovacuum_freeze_max_age</> transactions old are always <varname>autovacuum_freeze_max_age</> transactions old are always
vacuumed. Otherwise, if the number of tuples obsoleted since the last vacuumed (this also applies to those tables whose freeze max age has
been modified via storage parameters; see below). Otherwise, if the
number of tuples obsoleted since the last
<command>VACUUM</command> exceeds the <quote>vacuum threshold</quote>, the <command>VACUUM</command> exceeds the <quote>vacuum threshold</quote>, the
table is vacuumed. The vacuum threshold is defined as: table is vacuumed. The vacuum threshold is defined as:
<programlisting> <programlisting>
...@@ -604,65 +606,39 @@ analyze threshold = analyze base threshold + analyze scale factor * number of tu ...@@ -604,65 +606,39 @@ analyze threshold = analyze base threshold + analyze scale factor * number of tu
<para> <para>
The default thresholds and scale factors are taken from The default thresholds and scale factors are taken from
<filename>postgresql.conf</filename>, but it is possible to override them <filename>postgresql.conf</filename>, but it is possible to override them
on a table-by-table basis by making entries in the system catalog on a table-by-table basis; see
<link <xref linkend="sql-createtable-storage-parameters"
linkend="catalog-pg-autovacuum"><structname>pg_autovacuum</></link>. endterm="sql-createtable-storage-parameters-title"> for more information.
If a <structname>pg_autovacuum</structname> row exists for a particular If a setting
table, the settings it specifies are applied; otherwise the global has been changed via storage parameters, that value is used; otherwise the
settings are used. See <xref linkend="runtime-config-autovacuum"> for global settings are used. See <xref linkend="runtime-config-autovacuum"> for
more details on the global settings. more details on the global settings.
</para> </para>
<para> <para>
Besides the base threshold values and scale factors, there are five Besides the base threshold values and scale factors, there are six
more parameters that can be set for each table in more autovacuum parameters that can be set for each table via
<structname>pg_autovacuum</structname>. storage parameters.
The first, <structname>pg_autovacuum</>.<structfield>enabled</>, The first parameter, <literal>autovacuum_enabled</>,
can be set to <literal>false</literal> to instruct the autovacuum daemon can be set to <literal>false</literal> to instruct the autovacuum daemon
to skip that particular table entirely. In this case to skip that particular table entirely. In this case
autovacuum will only touch the table if it must do so autovacuum will only touch the table if it must do so
to prevent transaction ID wraparound. to prevent transaction ID wraparound.
The next two parameters, the vacuum cost delay Another two parameters,
(<structname>pg_autovacuum</structname>.<structfield>vac_cost_delay</structfield>) <literal>autovacuum_vacuum_cost_delay</literal> and
and the vacuum cost limit <literal>autovacuum_vacuum_cost_limit</literal>, are used to set
(<structname>pg_autovacuum</structname>.<structfield>vac_cost_limit</structfield>), table-specific values for the
are used to set table-specific values for the <xref linkend="runtime-config-resource-vacuum-cost"
<xref linkend="runtime-config-resource-vacuum-cost" endterm="runtime-config-resource-vacuum-cost-title"> endterm="runtime-config-resource-vacuum-cost-title">
feature. feature.
The last two parameters, <literal>autovacuum_freeze_min_age</literal>,
(<structname>pg_autovacuum</structname>.<structfield>freeze_min_age</structfield>) <literal>autovacuum_freeze_max_age</literal> and
and <literal>autovacuum_freeze_table_age</literal> are used to set
(<structname>pg_autovacuum</structname>.<structfield>freeze_max_age</structfield>), values for <xref linkend="guc-vacuum-freeze-min-age">,
are used to set table-specific values for <xref linkend="guc-autovacuum-freeze-max-age"> and
<xref linkend="guc-vacuum-freeze-min-age"> and <xref linkend="guc-vacuum-freeze-table-age"> respectively.
<xref linkend="guc-autovacuum-freeze-max-age"> respectively.
</para> </para>
<para>
If any of the values in <structname>pg_autovacuum</structname>
are set to a negative number, or if a row is not present at all in
<structname>pg_autovacuum</structname> for any particular table, the
corresponding values from <filename>postgresql.conf</filename> are used.
</para>
<para>
There is not currently any support for making
<structname>pg_autovacuum</structname> entries, except by doing
manual <command>INSERT</>s into the catalog. This feature will be
improved in future releases, and it is likely that the catalog
definition will change.
</para>
<caution>
<para>
The contents of the <structname>pg_autovacuum</structname> system
catalog are currently not saved in database dumps created by the
tools <application>pg_dump</> and <application>pg_dumpall</>. If
you want to preserve them across a dump/reload cycle, make sure
you dump the catalog manually.
</para>
</caution>
<para> <para>
When multiple workers are running, the cost limit is When multiple workers are running, the cost limit is
<quote>balanced</quote> among all the running workers, so that the <quote>balanced</quote> among all the running workers, so that the
......
<!-- <!--
$PostgreSQL: pgsql/doc/src/sgml/ref/alter_table.sgml,v 1.102 2008/12/13 19:13:44 tgl Exp $ $PostgreSQL: pgsql/doc/src/sgml/ref/alter_table.sgml,v 1.103 2009/02/09 20:57:59 alvherre Exp $
PostgreSQL documentation PostgreSQL documentation
--> -->
...@@ -286,7 +286,8 @@ where <replaceable class="PARAMETER">action</replaceable> is one of: ...@@ -286,7 +286,8 @@ where <replaceable class="PARAMETER">action</replaceable> is one of:
<listitem> <listitem>
<para> <para>
This form changes one or more storage parameters for the table. See This form changes one or more storage parameters for the table. See
<xref linkend="SQL-CREATETABLE" endterm="sql-createtable-title"> <xref linkend="SQL-CREATETABLE-storage-parameters"
endterm="sql-createtable-storage-parameters-title">
for details on the available parameters. Note that the table contents for details on the available parameters. Note that the table contents
will not be modified immediately by this command; depending on the will not be modified immediately by this command; depending on the
parameter you might need to rewrite the table to get the desired effects. parameter you might need to rewrite the table to get the desired effects.
......
<!-- <!--
$PostgreSQL: pgsql/doc/src/sgml/ref/create_table.sgml,v 1.112 2009/02/02 19:31:38 alvherre Exp $ $PostgreSQL: pgsql/doc/src/sgml/ref/create_table.sgml,v 1.113 2009/02/09 20:57:59 alvherre Exp $
PostgreSQL documentation PostgreSQL documentation
--> -->
...@@ -685,19 +685,29 @@ and <replaceable class="PARAMETER">table_constraint</replaceable> is: ...@@ -685,19 +685,29 @@ and <replaceable class="PARAMETER">table_constraint</replaceable> is:
<refsect2 id="SQL-CREATETABLE-storage-parameters"> <refsect2 id="SQL-CREATETABLE-storage-parameters">
<title id="SQL-CREATETABLE-storage-parameters-title">Storage Parameters</title> <title id="SQL-CREATETABLE-storage-parameters-title">Storage Parameters</title>
<indexterm zone="sql-createtable-storage-parameters">
<primary>storage parameters</primary>
</indexterm>
<para> <para>
The <literal>WITH</> clause can specify <firstterm>storage parameters</> The <literal>WITH</> clause can specify <firstterm>storage parameters</>
for tables, and for indexes associated with a <literal>UNIQUE</literal> or for tables, and for indexes associated with a <literal>UNIQUE</literal> or
<literal>PRIMARY KEY</literal> constraint. Storage parameters for <literal>PRIMARY KEY</literal> constraint. Storage parameters for
indexes are documented in <xref linkend="SQL-CREATEINDEX" indexes are documented in <xref linkend="SQL-CREATEINDEX"
endterm="sql-createindex-title">. The storage parameters currently endterm="sql-createindex-title">. The storage parameters currently
available for tables are: available for tables are listed below. For each parameter, there is an
additional, identically named parameter, prefixed with
<literal>toast.</literal> which can be used to control the behavior of the
supplementary storage table, if any; see <xref linkend="storage-toast">.
Note that the supplementary storage table inherits the
<literal>autovacuum</literal> values from its parent table, if there are
no <literal>toast.autovacuum_*</literal> settings set.
</para> </para>
<variablelist> <variablelist>
<varlistentry> <varlistentry>
<term><literal>FILLFACTOR</></term> <term><literal>fillfactor</>, <literal>toast.fillfactor</literal> (<type>integer</>)</term>
<listitem> <listitem>
<para> <para>
The fillfactor for a table is a percentage between 10 and 100. The fillfactor for a table is a percentage between 10 and 100.
...@@ -715,11 +725,118 @@ and <replaceable class="PARAMETER">table_constraint</replaceable> is: ...@@ -715,11 +725,118 @@ and <replaceable class="PARAMETER">table_constraint</replaceable> is:
</varlistentry> </varlistentry>
<varlistentry> <varlistentry>
<term><literal>TOAST.FILLFACTOR</literal></term> <term><literal>autovacuum_enabled</>, <literal>toast.autovacuum_enabled</literal> (<type>boolean</>)</term>
<listitem>
<para>
Enables or disables the autovacuum daemon on a particular table.
If true, the autovacuum daemon will initiate a <command>VACUUM</> operation
on a particular table when the number of updated or deleted tuples exceeds
<literal>autovacuum_vacuum_threshold</> plus
<literal>autovacuum_vacuum_scale_factor</> times the number of live tuples
currently estimated to be in the relation.
Similarly, it will initiate an <command>ANALYZE</> operation when the
number of inserted, updated or deleted tuples exceeds
<literal>autovacuum_analyze_threshold</> plus
<literal>autovacuum_analyze_scale_factor</> times the number of live tuples
currently estimated to be in the relation.
If false, this table will not be autovacuumed, except to prevent
transaction Id wraparound. See <xref linkend="vacuum-for-wraparound"> for
more about wraparound prevention.
Observe that this variable inherits its value from the <xref
linkend="guc-autovacuum"> setting.
</para>
</listitem>
</varlistentry>
<varlistentry>
<term><literal>autovacuum_vacuum_threshold</>, <literal>toast.autovacuum_vacuum_threshold</literal> (<type>integer</>)</term>
<listitem>
<para>
Minimum number of updated or deleted tuples before initiate a
<command>VACUUM</> operation on a particular table.
</para>
</listitem>
</varlistentry>
<varlistentry>
<term><literal>autovacuum_vacuum_scale_factor</>, <literal>toast.autovacuum_vacuum_scale_factor</literal> (<type>float4</>)</term>
<listitem>
<para>
Multiplier for <structfield>reltuples</> to add to
<literal>autovacuum_vacuum_threshold</>.
</para>
</listitem>
</varlistentry>
<varlistentry>
<term><literal>autovacuum_analyze_threshold</>, <literal>toast.autovacuum_analyze_threshold</literal> (<type>integer</>)</term>
<listitem>
<para>
Minimum number of inserted, updated, or deleted tuples before initiate an
<command>ANALYZE</> operation on a particular table.
</para>
</listitem>
</varlistentry>
<varlistentry>
<term><literal>autovacuum_analyze_scale_factor</>, <literal>toast.autovacuum_analyze_scale_factor</literal> (<type>float4</>)</term>
<listitem>
<para>
Multiplier for <structfield>reltuples</> to add to
<literal>autovacuum_analyze_threshold</>.
</para>
</listitem>
</varlistentry>
<varlistentry>
<term><literal>autovacuum_vacuum_cost_delay</>, <literal>toast.autovacuum_vacuum_cost_delay</literal> (<type>integer</>)</term>
<listitem>
<para>
Custom <xref linkend="guc-autovacuum-vacuum-cost-delay"> parameter.
</para>
</listitem>
</varlistentry>
<varlistentry>
<term><literal>autovacuum_vacuum_cost_limit</>, <literal>toast.autovacuum_vacuum_cost_limit</literal> (<type>integer</>)</term>
<listitem>
<para>
Custom <xref linkend="guc-autovacuum-vacuum-cost-limit"> parameter.
</para>
</listitem>
</varlistentry>
<varlistentry>
<term><literal>autovacuum_freeze_min_age</>, <literal>toast.autovacuum_freeze_min_age</literal> (<type>integer</>)</term>
<listitem>
<para>
Custom <xref linkend="guc-vacuum-freeze-min-age"> parameter. Note that
autovacuum will ignore attempts to set a per-table
<literal>autovacuum_freeze_min_age</> larger than the half system-wide
<xref linkend="guc-autovacuum-freeze-max-age"> setting.
</para>
</listitem>
</varlistentry>
<varlistentry>
<term><literal>autovacuum_freeze_max_age</>, <literal>toast.autovacuum_freeze_max_age</literal> (<type>integer</>)</term>
<listitem>
<para>
Custom <xref linkend="guc-autovacuum-freeze-max-age"> parameter. Note that
autovacuum will ignore attempts to set a per-table
<literal>autovacuum_freeze_max_age</> larger than the system-wide setting
(it can only be set smaller). Note that while you can set
<literal>autovacuum_freeze_max_age</> very small, or even zero, this is
usually unwise since it will force frequent vacuuming.
</para>
</listitem>
</varlistentry>
<varlistentry>
<term><literal>autovacuum_freeze_table_age</literal> (<type>integer</type>)</term>
<listitem> <listitem>
<para> <para>
Same as above, for the supplementary storage table, if any; see Custom <xref linkend="guc-vacuum-freeze-table-age"> parameter.
<xref linkend="storage-toast">.
</para> </para>
</listitem> </listitem>
</varlistentry> </varlistentry>
......
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $PostgreSQL: pgsql/src/backend/access/common/reloptions.c,v 1.20 2009/02/02 19:31:38 alvherre Exp $ * $PostgreSQL: pgsql/src/backend/access/common/reloptions.c,v 1.21 2009/02/09 20:57:59 alvherre Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -48,6 +48,14 @@ ...@@ -48,6 +48,14 @@
static relopt_bool boolRelOpts[] = static relopt_bool boolRelOpts[] =
{ {
{
{
"autovacuum_enabled",
"Enables autovacuum in this relation",
RELOPT_KIND_HEAP
},
true
},
/* list terminator */ /* list terminator */
{ { NULL } } { { NULL } }
}; };
...@@ -86,12 +94,83 @@ static relopt_int intRelOpts[] = ...@@ -86,12 +94,83 @@ static relopt_int intRelOpts[] =
}, },
GIST_DEFAULT_FILLFACTOR, GIST_MIN_FILLFACTOR, 100 GIST_DEFAULT_FILLFACTOR, GIST_MIN_FILLFACTOR, 100
}, },
{
{
"autovacuum_vacuum_threshold",
"Minimum number of tuple updates or deletes prior to vacuum",
RELOPT_KIND_HEAP
},
50, 0, INT_MAX
},
{
{
"autovacuum_analyze_threshold",
"Minimum number of tuple inserts, updates or deletes prior to analyze",
RELOPT_KIND_HEAP
},
50, 0, INT_MAX
},
{
{
"autovacuum_vacuum_cost_delay",
"Vacuum cost delay in milliseconds, for autovacuum",
RELOPT_KIND_HEAP
},
20, 0, 1000
},
{
{
"autovacuum_vacuum_cost_limit",
"Vacuum cost amount available before napping, for autovacuum",
RELOPT_KIND_HEAP
},
200, 1, 10000
},
{
{
"autovacuum_freeze_min_age",
"Minimum age at which VACUUM should freeze a table row, for autovacuum",
RELOPT_KIND_HEAP
},
100000000, 0, 1000000000
},
{
{
"autovacuum_freeze_max_age",
"Age at which to autovacuum a table to prevent transaction ID wraparound",
RELOPT_KIND_HEAP
},
200000000, 100000000, 2000000000
},
{
{
"autovacuum_freeze_table_age",
"Age at which VACUUM should perform a full table sweep to replace old Xid values with FrozenXID",
RELOPT_KIND_HEAP
}, 150000000, 0, 2000000000
},
/* list terminator */ /* list terminator */
{ { NULL } } { { NULL } }
}; };
static relopt_real realRelOpts[] = static relopt_real realRelOpts[] =
{ {
{
{
"autovacuum_vacuum_scale_factor",
"Number of tuple updates or deletes prior to vacuum as a fraction of reltuples",
RELOPT_KIND_HEAP
},
0.2, 0.0, 100.0
},
{
{
"autovacuum_analyze_scale_factor",
"Number of tuple inserts, updates or deletes prior to analyze as a fraction of reltuples",
RELOPT_KIND_HEAP
},
0.1, 0.0, 100.0
},
/* list terminator */ /* list terminator */
{ { NULL } } { { NULL } }
}; };
...@@ -973,7 +1052,8 @@ fillRelOptions(void *rdopts, Size basesize, relopt_value *options, ...@@ -973,7 +1052,8 @@ fillRelOptions(void *rdopts, Size basesize, relopt_value *options,
/* /*
* Option parser for anything that uses StdRdOptions (i.e. fillfactor only) * Option parser for anything that uses StdRdOptions (i.e. fillfactor and
* autovacuum)
*/ */
bytea * bytea *
default_reloptions(Datum reloptions, bool validate, relopt_kind kind) default_reloptions(Datum reloptions, bool validate, relopt_kind kind)
...@@ -982,7 +1062,27 @@ default_reloptions(Datum reloptions, bool validate, relopt_kind kind) ...@@ -982,7 +1062,27 @@ default_reloptions(Datum reloptions, bool validate, relopt_kind kind)
StdRdOptions *rdopts; StdRdOptions *rdopts;
int numoptions; int numoptions;
relopt_parse_elt tab[] = { relopt_parse_elt tab[] = {
{"fillfactor", RELOPT_TYPE_INT, offsetof(StdRdOptions, fillfactor)} {"fillfactor", RELOPT_TYPE_INT, offsetof(StdRdOptions, fillfactor)},
{"autovacuum_enabled", RELOPT_TYPE_BOOL,
offsetof(StdRdOptions, autovacuum) + offsetof(AutoVacOpts, enabled)},
{"autovacuum_vacuum_threshold", RELOPT_TYPE_INT,
offsetof(StdRdOptions, autovacuum) + offsetof(AutoVacOpts, vacuum_threshold)},
{"autovacuum_analyze_threshold", RELOPT_TYPE_INT,
offsetof(StdRdOptions, autovacuum) + offsetof(AutoVacOpts, analyze_threshold)},
{"autovacuum_vacuum_cost_delay", RELOPT_TYPE_INT,
offsetof(StdRdOptions, autovacuum) + offsetof(AutoVacOpts, vacuum_cost_delay)},
{"autovacuum_vacuum_cost_limit", RELOPT_TYPE_INT,
offsetof(StdRdOptions, autovacuum) + offsetof(AutoVacOpts, vacuum_cost_limit)},
{"autovacuum_freeze_min_age", RELOPT_TYPE_INT,
offsetof(StdRdOptions, autovacuum) + offsetof(AutoVacOpts, freeze_min_age)},
{"autovacuum_freeze_max_age", RELOPT_TYPE_INT,
offsetof(StdRdOptions, autovacuum) + offsetof(AutoVacOpts, freeze_max_age)},
{"autovacuum_freeze_table_age", RELOPT_TYPE_INT,
offsetof(StdRdOptions, autovacuum) + offsetof(AutoVacOpts, freeze_table_age)},
{"autovacuum_vacuum_scale_factor", RELOPT_TYPE_REAL,
offsetof(StdRdOptions, autovacuum) + offsetof(AutoVacOpts, vacuum_scale_factor)},
{"autovacuum_analyze_scale_factor", RELOPT_TYPE_REAL,
offsetof(StdRdOptions, autovacuum) + offsetof(AutoVacOpts, analyze_scale_factor)}
}; };
options = parseRelOptions(reloptions, validate, kind, &numoptions); options = parseRelOptions(reloptions, validate, kind, &numoptions);
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
# #
# Makefile for backend/catalog # Makefile for backend/catalog
# #
# $PostgreSQL: pgsql/src/backend/catalog/Makefile,v 1.68 2008/12/19 16:25:16 petere Exp $ # $PostgreSQL: pgsql/src/backend/catalog/Makefile,v 1.69 2009/02/09 20:57:59 alvherre Exp $
# #
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
...@@ -26,7 +26,7 @@ all: $(BKIFILES) ...@@ -26,7 +26,7 @@ all: $(BKIFILES)
# indexing.h had better be last, and toasting.h just before it. # indexing.h had better be last, and toasting.h just before it.
POSTGRES_BKI_SRCS = $(addprefix $(top_srcdir)/src/include/catalog/,\ POSTGRES_BKI_SRCS = $(addprefix $(top_srcdir)/src/include/catalog/,\
pg_proc.h pg_type.h pg_attribute.h pg_class.h pg_autovacuum.h \ pg_proc.h pg_type.h pg_attribute.h pg_class.h \
pg_attrdef.h pg_constraint.h pg_inherits.h pg_index.h pg_operator.h \ pg_attrdef.h pg_constraint.h pg_inherits.h pg_index.h pg_operator.h \
pg_opfamily.h pg_opclass.h pg_am.h pg_amop.h pg_amproc.h \ pg_opfamily.h pg_opclass.h pg_am.h pg_amop.h pg_amproc.h \
pg_language.h pg_largeobject.h pg_aggregate.h pg_statistic.h \ pg_language.h pg_largeobject.h pg_aggregate.h pg_statistic.h \
......
This diff is collapsed.
...@@ -37,7 +37,7 @@ ...@@ -37,7 +37,7 @@
* Portions Copyright (c) 1996-2009, PostgreSQL Global Development Group * Portions Copyright (c) 1996-2009, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California * Portions Copyright (c) 1994, Regents of the University of California
* *
* $PostgreSQL: pgsql/src/include/catalog/catversion.h,v 1.521 2009/02/06 21:15:11 tgl Exp $ * $PostgreSQL: pgsql/src/include/catalog/catversion.h,v 1.522 2009/02/09 20:57:59 alvherre Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -53,6 +53,6 @@ ...@@ -53,6 +53,6 @@
*/ */
/* yyyymmddN */ /* yyyymmddN */
#define CATALOG_VERSION_NO 200902061 #define CATALOG_VERSION_NO 200902091
#endif #endif
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
* Portions Copyright (c) 1996-2009, PostgreSQL Global Development Group * Portions Copyright (c) 1996-2009, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California * Portions Copyright (c) 1994, Regents of the University of California
* *
* $PostgreSQL: pgsql/src/include/catalog/indexing.h,v 1.106 2009/01/22 20:16:08 tgl Exp $ * $PostgreSQL: pgsql/src/include/catalog/indexing.h,v 1.107 2009/02/09 20:57:59 alvherre Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -97,9 +97,6 @@ DECLARE_UNIQUE_INDEX(pg_auth_members_role_member_index, 2694, on pg_auth_members ...@@ -97,9 +97,6 @@ DECLARE_UNIQUE_INDEX(pg_auth_members_role_member_index, 2694, on pg_auth_members
DECLARE_UNIQUE_INDEX(pg_auth_members_member_role_index, 2695, on pg_auth_members using btree(member oid_ops, roleid oid_ops)); DECLARE_UNIQUE_INDEX(pg_auth_members_member_role_index, 2695, on pg_auth_members using btree(member oid_ops, roleid oid_ops));
#define AuthMemMemRoleIndexId 2695 #define AuthMemMemRoleIndexId 2695
DECLARE_UNIQUE_INDEX(pg_autovacuum_vacrelid_index, 1250, on pg_autovacuum using btree(vacrelid oid_ops));
#define AutovacuumRelidIndexId 1250
DECLARE_UNIQUE_INDEX(pg_cast_oid_index, 2660, on pg_cast using btree(oid oid_ops)); DECLARE_UNIQUE_INDEX(pg_cast_oid_index, 2660, on pg_cast using btree(oid oid_ops));
#define CastOidIndexId 2660 #define CastOidIndexId 2660
DECLARE_UNIQUE_INDEX(pg_cast_source_target_index, 2661, on pg_cast using btree(castsource oid_ops, casttarget oid_ops)); DECLARE_UNIQUE_INDEX(pg_cast_source_target_index, 2661, on pg_cast using btree(castsource oid_ops, casttarget oid_ops));
......
/*-------------------------------------------------------------------------
*
* pg_autovacuum.h
* definition of the system "autovacuum" relation (pg_autovacuum)
*
* 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.11 2009/01/16 13:27:24 heikki Exp $
*
*-------------------------------------------------------------------------
*/
#ifndef PG_AUTOVACUUM_H
#define PG_AUTOVACUUM_H
#include "catalog/genbki.h"
/* ----------------
* 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 */
int4 vac_cost_delay; /* vacuum cost-based delay */
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;
/* ----------------
* 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 10
#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
#define Anum_pg_autovacuum_vac_cost_delay 7
#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 */
#endif /* PG_AUTOVACUUM_H */
...@@ -7,7 +7,7 @@ ...@@ -7,7 +7,7 @@
* Portions Copyright (c) 1996-2009, PostgreSQL Global Development Group * Portions Copyright (c) 1996-2009, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California * Portions Copyright (c) 1994, Regents of the University of California
* *
* $PostgreSQL: pgsql/src/include/utils/rel.h,v 1.111 2009/01/01 17:24:02 momjian Exp $ * $PostgreSQL: pgsql/src/include/utils/rel.h,v 1.112 2009/02/09 20:57:59 alvherre Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -214,10 +214,26 @@ typedef struct RelationData ...@@ -214,10 +214,26 @@ typedef struct RelationData
* be applied to relations that use this format or a superset for * be applied to relations that use this format or a superset for
* private options data. * private options data.
*/ */
/* autovacuum-related reloptions. */
typedef struct AutoVacOpts
{
bool enabled;
int vacuum_threshold;
int analyze_threshold;
int vacuum_cost_delay;
int vacuum_cost_limit;
int freeze_min_age;
int freeze_max_age;
int freeze_table_age;
float8 vacuum_scale_factor;
float8 analyze_scale_factor;
} AutoVacOpts;
typedef struct StdRdOptions typedef struct StdRdOptions
{ {
int32 vl_len_; /* varlena header (do not touch directly!) */ int32 vl_len_; /* varlena header (do not touch directly!) */
int fillfactor; /* page fill factor in percent (0..100) */ int fillfactor; /* page fill factor in percent (0..100) */
AutoVacOpts autovacuum; /* autovacuum-related options */
} StdRdOptions; } StdRdOptions;
#define HEAP_MIN_FILLFACTOR 10 #define HEAP_MIN_FILLFACTOR 10
......
...@@ -90,7 +90,6 @@ SELECT relname, relhasindex ...@@ -90,7 +90,6 @@ SELECT relname, relhasindex
pg_attribute | t pg_attribute | t
pg_auth_members | t pg_auth_members | t
pg_authid | t pg_authid | t
pg_autovacuum | t
pg_cast | t pg_cast | t
pg_class | t pg_class | t
pg_constraint | t pg_constraint | t
...@@ -152,7 +151,7 @@ SELECT relname, relhasindex ...@@ -152,7 +151,7 @@ SELECT relname, relhasindex
timetz_tbl | f timetz_tbl | f
tinterval_tbl | f tinterval_tbl | f
varchar_tbl | f varchar_tbl | f
(141 rows) (140 rows)
-- --
-- another sanity check: every system catalog that has OIDs should have -- another sanity check: every system catalog that has OIDs should have
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment