Skip to content

Commit 834a6da

Browse files
committed
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.
1 parent 57b10eb commit 834a6da

File tree

13 files changed

+421
-483
lines changed

13 files changed

+421
-483
lines changed

doc/src/sgml/catalogs.sgml

+1-178
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<!-- $PostgreSQL: pgsql/doc/src/sgml/catalogs.sgml,v 2.196 2009/02/07 19:27:25 momjian Exp $ -->
1+
<!-- $PostgreSQL: pgsql/doc/src/sgml/catalogs.sgml,v 2.197 2009/02/09 20:57:59 alvherre Exp $ -->
22
<!--
33
Documentation of the system catalogs, directed toward PostgreSQL developers
44
-->
@@ -88,11 +88,6 @@
8888
<entry>authorization identifier membership relationships</entry>
8989
</row>
9090

91-
<row>
92-
<entry><link linkend="catalog-pg-autovacuum"><structname>pg_autovacuum</structname></link></entry>
93-
<entry>per-relation autovacuum configuration parameters</entry>
94-
</row>
95-
9691
<row>
9792
<entry><link linkend="catalog-pg-cast"><structname>pg_cast</structname></link></entry>
9893
<entry>casts (data type conversions)</entry>
@@ -1256,178 +1251,6 @@
12561251
</sect1>
12571252

12581253

1259-
<sect1 id="catalog-pg-autovacuum">
1260-
<title><structname>pg_autovacuum</structname></title>
1261-
1262-
<indexterm zone="catalog-pg-autovacuum">
1263-
<primary>pg_autovacuum</primary>
1264-
</indexterm>
1265-
1266-
<indexterm zone="catalog-pg-autovacuum">
1267-
<primary>autovacuum</primary>
1268-
<secondary>table-specific configuration</secondary>
1269-
</indexterm>
1270-
1271-
<para>
1272-
The catalog <structname>pg_autovacuum</structname> stores optional
1273-
per-relation configuration parameters for the autovacuum daemon.
1274-
If there is an entry here for a particular relation, the given
1275-
parameters will be used for autovacuuming that table. If no entry
1276-
is present, the system-wide defaults will be used. For more information
1277-
about the autovacuum daemon, see <xref linkend="autovacuum">.
1278-
</para>
1279-
1280-
<note>
1281-
<para>
1282-
It is likely that <structname>pg_autovacuum</structname> will disappear
1283-
in a future release, with the information instead being kept in
1284-
<structname>pg_class</>.<structfield>reloptions</> entries.
1285-
</para>
1286-
</note>
1287-
1288-
<table>
1289-
<title><structname>pg_autovacuum</> Columns</title>
1290-
1291-
<tgroup cols="4">
1292-
<thead>
1293-
<row>
1294-
<entry>Name</entry>
1295-
<entry>Type</entry>
1296-
<entry>References</entry>
1297-
<entry>Description</entry>
1298-
</row>
1299-
</thead>
1300-
1301-
<tbody>
1302-
<row>
1303-
<entry><structfield>vacrelid</structfield></entry>
1304-
<entry><type>oid</type></entry>
1305-
<entry><literal><link linkend="catalog-pg-class"><structname>pg_class</structname></link>.oid</literal></entry>
1306-
<entry>The table this entry is for</entry>
1307-
</row>
1308-
1309-
<row>
1310-
<entry><structfield>enabled</structfield></entry>
1311-
<entry><type>bool</type></entry>
1312-
<entry></entry>
1313-
<entry>If false, this table will not be autovacuumed, except
1314-
to prevent transaction ID wraparound</entry>
1315-
</row>
1316-
1317-
<row>
1318-
<entry><structfield>vac_base_thresh</structfield></entry>
1319-
<entry><type>integer</type></entry>
1320-
<entry></entry>
1321-
<entry>Minimum number of modified tuples before vacuum</entry>
1322-
</row>
1323-
1324-
<row>
1325-
<entry><structfield>vac_scale_factor</structfield></entry>
1326-
<entry><type>float4</type></entry>
1327-
<entry></entry>
1328-
<entry>Multiplier for <structfield>reltuples</> to add to
1329-
<structfield>vac_base_thresh</></entry>
1330-
</row>
1331-
1332-
<row>
1333-
<entry><structfield>anl_base_thresh</structfield></entry>
1334-
<entry><type>integer</type></entry>
1335-
<entry></entry>
1336-
<entry>Minimum number of modified tuples before analyze</entry>
1337-
</row>
1338-
1339-
<row>
1340-
<entry><structfield>anl_scale_factor</structfield></entry>
1341-
<entry><type>float4</type></entry>
1342-
<entry></entry>
1343-
<entry>Multiplier for <structfield>reltuples</> to add to
1344-
<structfield>anl_base_thresh</></entry>
1345-
</row>
1346-
1347-
<row>
1348-
<entry><structfield>vac_cost_delay</structfield></entry>
1349-
<entry><type>integer</type></entry>
1350-
<entry></entry>
1351-
<entry>Custom <varname>vacuum_cost_delay</> parameter</entry>
1352-
</row>
1353-
1354-
<row>
1355-
<entry><structfield>vac_cost_limit</structfield></entry>
1356-
<entry><type>integer</type></entry>
1357-
<entry></entry>
1358-
<entry>Custom <varname>vacuum_cost_limit</> parameter</entry>
1359-
</row>
1360-
1361-
<row>
1362-
<entry><structfield>freeze_min_age</structfield></entry>
1363-
<entry><type>integer</type></entry>
1364-
<entry></entry>
1365-
<entry>Custom <varname>vacuum_freeze_min_age</> parameter</entry>
1366-
</row>
1367-
1368-
<row>
1369-
<entry><structfield>freeze_max_age</structfield></entry>
1370-
<entry><type>integer</type></entry>
1371-
<entry></entry>
1372-
<entry>Custom <varname>autovacuum_freeze_max_age</> parameter</entry>
1373-
</row>
1374-
1375-
<row>
1376-
<entry><structfield>freeze_table_age</structfield></entry>
1377-
<entry><type>integer</type></entry>
1378-
<entry></entry>
1379-
<entry>Custom <varname>vacuum_freeze_table_age</> parameter</entry>
1380-
</row>
1381-
</tbody>
1382-
</tgroup>
1383-
</table>
1384-
1385-
<para>
1386-
The autovacuum daemon will initiate a <command>VACUUM</> operation
1387-
on a particular table when the number of updated or deleted tuples
1388-
exceeds <structfield>vac_base_thresh</structfield> plus
1389-
<structfield>vac_scale_factor</structfield> times the number of
1390-
live tuples currently estimated to be in the relation.
1391-
Similarly, it will initiate an <command>ANALYZE</> operation
1392-
when the number of inserted, updated or deleted tuples
1393-
exceeds <structfield>anl_base_thresh</structfield> plus
1394-
<structfield>anl_scale_factor</structfield> times the number of
1395-
live tuples currently estimated to be in the relation.
1396-
</para>
1397-
1398-
<para>
1399-
Also, the autovacuum daemon will perform a <command>VACUUM</> operation
1400-
to prevent transaction ID wraparound if the table's
1401-
<structname>pg_class</>.<structfield>relfrozenxid</> field attains an age
1402-
of more than <structfield>freeze_max_age</> transactions, whether the table
1403-
has been changed or not, even if
1404-
<structname>pg_autovacuum</>.<structfield>enabled</> is set to
1405-
<literal>false</> for it. The system will launch autovacuum to perform
1406-
such <command>VACUUM</>s even if autovacuum is otherwise disabled.
1407-
See <xref linkend="vacuum-for-wraparound"> for more about wraparound
1408-
prevention.
1409-
</para>
1410-
1411-
<para>
1412-
Any of the numerical fields can contain <literal>-1</> (or indeed
1413-
any negative value) to indicate that the system-wide default should
1414-
be used for this particular value. Observe that the
1415-
<structfield>vac_cost_delay</> variable inherits its default value from the
1416-
<xref linkend="guc-autovacuum-vacuum-cost-delay"> configuration parameter,
1417-
or from <xref linkend="guc-vacuum-cost-delay"> if the former is set to a
1418-
negative value. The same applies to <structfield>vac_cost_limit</>.
1419-
Also, autovacuum will ignore attempts to set a per-table
1420-
<structfield>freeze_max_age</> larger than the system-wide setting (it can
1421-
only be set smaller), and the <structfield>freeze_min_age</> value will be
1422-
limited to half the system-wide <xref
1423-
linkend="guc-autovacuum-freeze-max-age"> setting. Note that while you
1424-
can set <structfield>freeze_max_age</> very small, or even zero, this
1425-
is usually unwise since it will force frequent vacuuming.
1426-
</para>
1427-
1428-
</sect1>
1429-
1430-
14311254
<sect1 id="catalog-pg-cast">
14321255
<title><structname>pg_cast</structname></title>
14331256

doc/src/sgml/config.sgml

+15-15
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<!-- $PostgreSQL: pgsql/doc/src/sgml/config.sgml,v 1.206 2009/01/16 13:27:23 heikki Exp $ -->
1+
<!-- $PostgreSQL: pgsql/doc/src/sgml/config.sgml,v 1.207 2009/02/09 20:57:59 alvherre Exp $ -->
22

33
<chapter Id="runtime-config">
44
<title>Server Configuration</title>
@@ -3547,8 +3547,8 @@ COPY postgres_log FROM '/full/path/to/logfile.csv' WITH csv;
35473547
The default is 50 tuples.
35483548
This parameter can only be set in the <filename>postgresql.conf</>
35493549
file or on the server command line.
3550-
This setting can be overridden for individual tables by entries in
3551-
<structname>pg_autovacuum</>.
3550+
This setting can be overridden for individual tables by
3551+
changing storage parameters.
35523552
</para>
35533553
</listitem>
35543554
</varlistentry>
@@ -3565,8 +3565,8 @@ COPY postgres_log FROM '/full/path/to/logfile.csv' WITH csv;
35653565
The default is 50 tuples.
35663566
This parameter can only be set in the <filename>postgresql.conf</>
35673567
file or on the server command line.
3568-
This setting can be overridden for individual tables by entries in
3569-
<structname>pg_autovacuum</>.
3568+
This setting can be overridden for individual tables by
3569+
changing storage parameters.
35703570
</para>
35713571
</listitem>
35723572
</varlistentry>
@@ -3584,8 +3584,8 @@ COPY postgres_log FROM '/full/path/to/logfile.csv' WITH csv;
35843584
The default is 0.2 (20% of table size).
35853585
This parameter can only be set in the <filename>postgresql.conf</>
35863586
file or on the server command line.
3587-
This setting can be overridden for individual tables by entries in
3588-
<structname>pg_autovacuum</>.
3587+
This setting can be overridden for individual tables by
3588+
changing storage parameters.
35893589
</para>
35903590
</listitem>
35913591
</varlistentry>
@@ -3603,8 +3603,8 @@ COPY postgres_log FROM '/full/path/to/logfile.csv' WITH csv;
36033603
The default is 0.1 (10% of table size).
36043604
This parameter can only be set in the <filename>postgresql.conf</>
36053605
file or on the server command line.
3606-
This setting can be overridden for individual tables by entries in
3607-
<structname>pg_autovacuum</>.
3606+
This setting can be overridden for individual tables by
3607+
changing storage parameters.
36083608
</para>
36093609
</listitem>
36103610
</varlistentry>
@@ -3624,8 +3624,8 @@ COPY postgres_log FROM '/full/path/to/logfile.csv' WITH csv;
36243624
autovacuum is otherwise disabled.
36253625
The default is 200 million transactions.
36263626
This parameter can only be set at server start, but the setting
3627-
can be reduced for individual tables by entries in
3628-
<structname>pg_autovacuum</>.
3627+
can be reduced for individual tables by
3628+
changing storage parameters.
36293629
For more information see <xref linkend="vacuum-for-wraparound">.
36303630
</para>
36313631
</listitem>
@@ -3645,8 +3645,8 @@ COPY postgres_log FROM '/full/path/to/logfile.csv' WITH csv;
36453645
The default value is 20 milliseconds.
36463646
This parameter can only be set in the <filename>postgresql.conf</>
36473647
file or on the server command line.
3648-
This setting can be overridden for individual tables by entries in
3649-
<structname>pg_autovacuum</>.
3648+
This setting can be overridden for individual tables by
3649+
changing storage parameters.
36503650
</para>
36513651
</listitem>
36523652
</varlistentry>
@@ -3667,8 +3667,8 @@ COPY postgres_log FROM '/full/path/to/logfile.csv' WITH csv;
36673667
each worker never exceeds the limit on this variable.
36683668
This parameter can only be set in the <filename>postgresql.conf</>
36693669
file or on the server command line.
3670-
This setting can be overridden for individual tables by entries in
3671-
<structname>pg_autovacuum</>.
3670+
This setting can be overridden for individual tables by
3671+
changing storage parameters.
36723672
</para>
36733673
</listitem>
36743674
</varlistentry>

doc/src/sgml/maintenance.sgml

+26-50
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<!-- $PostgreSQL: pgsql/doc/src/sgml/maintenance.sgml,v 1.89 2009/01/16 13:27:23 heikki Exp $ -->
1+
<!-- $PostgreSQL: pgsql/doc/src/sgml/maintenance.sgml,v 1.90 2009/02/09 20:57:59 alvherre Exp $ -->
22

33
<chapter id="maintenance">
44
<title>Routine Database Maintenance Tasks</title>
@@ -573,7 +573,9 @@ HINT: Stop the postmaster and use a standalone backend to VACUUM in "mydb".
573573
<para>
574574
Tables whose <structfield>relfrozenxid</> value is more than
575575
<varname>autovacuum_freeze_max_age</> transactions old are always
576-
vacuumed. Otherwise, if the number of tuples obsoleted since the last
576+
vacuumed (this also applies to those tables whose freeze max age has
577+
been modified via storage parameters; see below). Otherwise, if the
578+
number of tuples obsoleted since the last
577579
<command>VACUUM</command> exceeds the <quote>vacuum threshold</quote>, the
578580
table is vacuumed. The vacuum threshold is defined as:
579581
<programlisting>
@@ -604,65 +606,39 @@ analyze threshold = analyze base threshold + analyze scale factor * number of tu
604606
<para>
605607
The default thresholds and scale factors are taken from
606608
<filename>postgresql.conf</filename>, but it is possible to override them
607-
on a table-by-table basis by making entries in the system catalog
608-
<link
609-
linkend="catalog-pg-autovacuum"><structname>pg_autovacuum</></link>.
610-
If a <structname>pg_autovacuum</structname> row exists for a particular
611-
table, the settings it specifies are applied; otherwise the global
612-
settings are used. See <xref linkend="runtime-config-autovacuum"> for
609+
on a table-by-table basis; see
610+
<xref linkend="sql-createtable-storage-parameters"
611+
endterm="sql-createtable-storage-parameters-title"> for more information.
612+
If a setting
613+
has been changed via storage parameters, that value is used; otherwise the
614+
global settings are used. See <xref linkend="runtime-config-autovacuum"> for
613615
more details on the global settings.
614616
</para>
615617

616618
<para>
617-
Besides the base threshold values and scale factors, there are five
618-
more parameters that can be set for each table in
619-
<structname>pg_autovacuum</structname>.
620-
The first, <structname>pg_autovacuum</>.<structfield>enabled</>,
619+
Besides the base threshold values and scale factors, there are six
620+
more autovacuum parameters that can be set for each table via
621+
storage parameters.
622+
The first parameter, <literal>autovacuum_enabled</>,
621623
can be set to <literal>false</literal> to instruct the autovacuum daemon
622624
to skip that particular table entirely. In this case
623625
autovacuum will only touch the table if it must do so
624626
to prevent transaction ID wraparound.
625-
The next two parameters, the vacuum cost delay
626-
(<structname>pg_autovacuum</structname>.<structfield>vac_cost_delay</structfield>)
627-
and the vacuum cost limit
628-
(<structname>pg_autovacuum</structname>.<structfield>vac_cost_limit</structfield>),
629-
are used to set table-specific values for the
630-
<xref linkend="runtime-config-resource-vacuum-cost" endterm="runtime-config-resource-vacuum-cost-title">
627+
Another two parameters,
628+
<literal>autovacuum_vacuum_cost_delay</literal> and
629+
<literal>autovacuum_vacuum_cost_limit</literal>, are used to set
630+
table-specific values for the
631+
<xref linkend="runtime-config-resource-vacuum-cost"
632+
endterm="runtime-config-resource-vacuum-cost-title">
631633
feature.
632-
The last two parameters,
633-
(<structname>pg_autovacuum</structname>.<structfield>freeze_min_age</structfield>)
634-
and
635-
(<structname>pg_autovacuum</structname>.<structfield>freeze_max_age</structfield>),
636-
are used to set table-specific values for
637-
<xref linkend="guc-vacuum-freeze-min-age"> and
638-
<xref linkend="guc-autovacuum-freeze-max-age"> respectively.
634+
<literal>autovacuum_freeze_min_age</literal>,
635+
<literal>autovacuum_freeze_max_age</literal> and
636+
<literal>autovacuum_freeze_table_age</literal> are used to set
637+
values for <xref linkend="guc-vacuum-freeze-min-age">,
638+
<xref linkend="guc-autovacuum-freeze-max-age"> and
639+
<xref linkend="guc-vacuum-freeze-table-age"> respectively.
639640
</para>
640641

641-
<para>
642-
If any of the values in <structname>pg_autovacuum</structname>
643-
are set to a negative number, or if a row is not present at all in
644-
<structname>pg_autovacuum</structname> for any particular table, the
645-
corresponding values from <filename>postgresql.conf</filename> are used.
646-
</para>
647-
648-
<para>
649-
There is not currently any support for making
650-
<structname>pg_autovacuum</structname> entries, except by doing
651-
manual <command>INSERT</>s into the catalog. This feature will be
652-
improved in future releases, and it is likely that the catalog
653-
definition will change.
654-
</para>
655-
656-
<caution>
657-
<para>
658-
The contents of the <structname>pg_autovacuum</structname> system
659-
catalog are currently not saved in database dumps created by the
660-
tools <application>pg_dump</> and <application>pg_dumpall</>. If
661-
you want to preserve them across a dump/reload cycle, make sure
662-
you dump the catalog manually.
663-
</para>
664-
</caution>
665-
666642
<para>
667643
When multiple workers are running, the cost limit is
668644
<quote>balanced</quote> among all the running workers, so that the

0 commit comments

Comments
 (0)