2010-09-20 22:08:53 +02:00
|
|
|
<!-- doc/src/sgml/maintenance.sgml -->
|
2001-08-26 23:17:12 +02:00
|
|
|
|
|
|
|
<chapter id="maintenance">
|
|
|
|
<title>Routine Database Maintenance Tasks</title>
|
|
|
|
|
2003-08-31 19:32:24 +02:00
|
|
|
<indexterm zone="maintenance">
|
|
|
|
<primary>maintenance</primary>
|
|
|
|
</indexterm>
|
|
|
|
|
2006-08-01 02:09:06 +02:00
|
|
|
<indexterm zone="maintenance">
|
2006-08-01 21:17:18 +02:00
|
|
|
<primary>routine maintenance</primary>
|
2006-08-01 02:09:06 +02:00
|
|
|
</indexterm>
|
|
|
|
|
2001-08-26 23:17:12 +02:00
|
|
|
<para>
|
2017-10-09 03:44:17 +02:00
|
|
|
<productname>PostgreSQL</productname>, like any database software, requires that certain tasks
|
2006-08-01 21:17:18 +02:00
|
|
|
be performed regularly to achieve optimum performance. The tasks
|
2006-08-01 02:09:06 +02:00
|
|
|
discussed here are <emphasis>required</emphasis>, but they
|
2006-08-01 21:17:18 +02:00
|
|
|
are repetitive in nature and can easily be automated using standard
|
2008-06-16 05:13:14 +02:00
|
|
|
tools such as <application>cron</application> scripts or
|
2017-10-09 03:44:17 +02:00
|
|
|
Windows' <application>Task Scheduler</application>. It is the database
|
2006-08-01 21:17:18 +02:00
|
|
|
administrator's responsibility to set up appropriate scripts, and to
|
|
|
|
check that they execute successfully.
|
2001-08-26 23:17:12 +02:00
|
|
|
</para>
|
2006-08-01 21:17:18 +02:00
|
|
|
|
2001-08-26 23:17:12 +02:00
|
|
|
<para>
|
2010-02-03 18:25:06 +01:00
|
|
|
One obvious maintenance task is the creation of backup copies of the data on a
|
2006-08-01 21:17:18 +02:00
|
|
|
regular schedule. Without a recent backup, you have no chance of recovery
|
|
|
|
after a catastrophe (disk failure, fire, mistakenly dropping a critical
|
|
|
|
table, etc.). The backup and recovery mechanisms available in
|
|
|
|
<productname>PostgreSQL</productname> are discussed at length in
|
2017-11-23 15:39:47 +01:00
|
|
|
<xref linkend="backup"/>.
|
2001-08-26 23:17:12 +02:00
|
|
|
</para>
|
|
|
|
|
|
|
|
<para>
|
2017-10-09 03:44:17 +02:00
|
|
|
The other main category of maintenance task is periodic <quote>vacuuming</quote>
|
2006-08-01 21:17:18 +02:00
|
|
|
of the database. This activity is discussed in
|
2017-11-23 15:39:47 +01:00
|
|
|
<xref linkend="routine-vacuuming"/>. Closely related to this is updating
|
2006-08-01 21:17:18 +02:00
|
|
|
the statistics that will be used by the query planner, as discussed in
|
2017-11-23 15:39:47 +01:00
|
|
|
<xref linkend="vacuum-for-statistics"/>.
|
2001-08-26 23:17:12 +02:00
|
|
|
</para>
|
|
|
|
|
2001-09-23 06:06:24 +02:00
|
|
|
<para>
|
2006-08-01 21:17:18 +02:00
|
|
|
Another task that might need periodic attention is log file management.
|
2017-11-23 15:39:47 +01:00
|
|
|
This is discussed in <xref linkend="logfile-maintenance"/>.
|
2001-09-23 06:06:24 +02:00
|
|
|
</para>
|
2001-08-26 23:17:12 +02:00
|
|
|
|
2009-04-06 19:55:19 +02:00
|
|
|
<para>
|
|
|
|
<ulink
|
2017-11-02 03:07:14 +01:00
|
|
|
url="https://bucardo.org/check_postgres/"><application>check_postgres</application></ulink>
|
2009-04-06 19:55:19 +02:00
|
|
|
is available for monitoring database health and reporting unusual
|
2017-10-09 03:44:17 +02:00
|
|
|
conditions. <application>check_postgres</application> integrates with
|
2009-04-06 19:56:31 +02:00
|
|
|
Nagios and MRTG, but can be run standalone too.
|
2009-04-06 19:55:19 +02:00
|
|
|
</para>
|
|
|
|
|
2006-08-01 21:17:18 +02:00
|
|
|
<para>
|
|
|
|
<productname>PostgreSQL</productname> is low-maintenance compared
|
|
|
|
to some other database management systems. Nonetheless,
|
|
|
|
appropriate attention to these tasks will go far towards ensuring a
|
|
|
|
pleasant and productive experience with the system.
|
|
|
|
</para>
|
2001-08-26 23:17:12 +02:00
|
|
|
|
|
|
|
<sect1 id="routine-vacuuming">
|
|
|
|
<title>Routine Vacuuming</title>
|
|
|
|
|
2001-11-12 20:19:39 +01:00
|
|
|
<indexterm zone="routine-vacuuming">
|
|
|
|
<primary>vacuum</primary>
|
|
|
|
</indexterm>
|
|
|
|
|
2001-08-26 23:17:12 +02:00
|
|
|
<para>
|
2008-06-16 05:13:14 +02:00
|
|
|
<productname>PostgreSQL</productname> databases require periodic
|
2017-10-09 03:44:17 +02:00
|
|
|
maintenance known as <firstterm>vacuuming</firstterm>. For many installations, it
|
2008-06-16 05:13:14 +02:00
|
|
|
is sufficient to let vacuuming be performed by the <firstterm>autovacuum
|
2017-11-23 15:39:47 +01:00
|
|
|
daemon</firstterm>, which is described in <xref linkend="autovacuum"/>. You might
|
2008-06-16 05:13:14 +02:00
|
|
|
need to adjust the autovacuuming parameters described there to obtain best
|
|
|
|
results for your situation. Some database administrators will want to
|
|
|
|
supplement or replace the daemon's activities with manually-managed
|
2017-10-09 03:44:17 +02:00
|
|
|
<command>VACUUM</command> commands, which typically are executed according to a
|
2008-06-16 05:13:14 +02:00
|
|
|
schedule by <application>cron</application> or <application>Task
|
2017-10-09 03:44:17 +02:00
|
|
|
Scheduler</application> scripts. To set up manually-managed vacuuming properly,
|
2008-06-16 05:13:14 +02:00
|
|
|
it is essential to understand the issues discussed in the next few
|
|
|
|
subsections. Administrators who rely on autovacuuming may still wish
|
|
|
|
to skim this material to help them understand and adjust autovacuuming.
|
|
|
|
</para>
|
|
|
|
|
|
|
|
<sect2 id="vacuum-basics">
|
|
|
|
<title>Vacuuming Basics</title>
|
|
|
|
|
|
|
|
<para>
|
|
|
|
<productname>PostgreSQL</productname>'s
|
Improve <xref> vs. <command> formatting in the documentation
SQL commands are generally marked up as <command>, except when a link
to a reference page is used using <xref>. But the latter doesn't
create monospace markup, so this looks strange especially when a
paragraph contains a mix of links and non-links.
We considered putting <command> in the <refentrytitle> on the target
side, but that creates some formatting side effects elsewhere.
Generally, it seems safer to solve this on the link source side.
We can't put the <xref> inside the <command>; the DTD doesn't allow
this. DocBook 5 would allow the <command> to have the linkend
attribute itself, but we are not there yet.
So to solve this for now, convert the <xref>s to <link> plus
<command>. This gives the correct look and also gives some more
flexibility what we can put into the link text (e.g., subcommands or
other clauses). In the future, these could then be converted to
DocBook 5 style.
I haven't converted absolutely all xrefs to SQL command reference
pages, only those where we care about the appearance of the link text
or where it was otherwise appropriate to make the appearance match a
bit better. Also in some cases, the links where repetitive, so in
those cases the links where just removed and replaced by a plain
<command>. In cases where we just want the link and don't
specifically care about the generated link text (typically phrased
"for further information see <xref ...>") the xref is kept.
Reported-by: Dagfinn Ilmari Mannsåker <ilmari@ilmari.org>
Discussion: https://www.postgresql.org/message-id/flat/87o8pco34z.fsf@wibble.ilmari.org
2020-10-03 16:16:51 +02:00
|
|
|
<link linkend="sql-vacuum"><command>VACUUM</command></link> command has to
|
2008-06-16 05:13:14 +02:00
|
|
|
process each table on a regular basis for several reasons:
|
2001-08-26 23:17:12 +02:00
|
|
|
|
|
|
|
<orderedlist>
|
|
|
|
<listitem>
|
2006-08-01 02:09:06 +02:00
|
|
|
<simpara>To recover or reuse disk space occupied by updated or deleted
|
2001-08-26 23:17:12 +02:00
|
|
|
rows.</simpara>
|
|
|
|
</listitem>
|
|
|
|
|
|
|
|
<listitem>
|
|
|
|
<simpara>To update data statistics used by the
|
|
|
|
<productname>PostgreSQL</productname> query planner.</simpara>
|
|
|
|
</listitem>
|
|
|
|
|
2012-03-21 19:51:11 +01:00
|
|
|
<listitem>
|
2016-05-08 22:36:19 +02:00
|
|
|
<simpara>To update the visibility map, which speeds
|
|
|
|
up <link linkend="indexes-index-only-scans">index-only
|
|
|
|
scans</link>.</simpara>
|
2012-03-21 19:51:11 +01:00
|
|
|
</listitem>
|
|
|
|
|
2001-08-26 23:17:12 +02:00
|
|
|
<listitem>
|
|
|
|
<simpara>To protect against loss of very old data due to
|
2017-10-09 03:44:17 +02:00
|
|
|
<firstterm>transaction ID wraparound</firstterm> or
|
|
|
|
<firstterm>multixact ID wraparound</firstterm>.</simpara>
|
2001-08-26 23:17:12 +02:00
|
|
|
</listitem>
|
|
|
|
</orderedlist>
|
|
|
|
|
2017-10-09 03:44:17 +02:00
|
|
|
Each of these reasons dictates performing <command>VACUUM</command> operations
|
2008-06-16 05:13:14 +02:00
|
|
|
of varying frequency and scope, as explained in the following subsections.
|
|
|
|
</para>
|
2004-12-27 23:30:10 +01:00
|
|
|
|
2008-06-16 05:13:14 +02:00
|
|
|
<para>
|
2017-10-09 03:44:17 +02:00
|
|
|
There are two variants of <command>VACUUM</command>: standard <command>VACUUM</command>
|
|
|
|
and <command>VACUUM FULL</command>. <command>VACUUM FULL</command> can reclaim more
|
2008-06-16 05:13:14 +02:00
|
|
|
disk space but runs much more slowly. Also,
|
2017-10-09 03:44:17 +02:00
|
|
|
the standard form of <command>VACUUM</command> can run in parallel with production
|
2008-06-16 05:13:14 +02:00
|
|
|
database operations. (Commands such as <command>SELECT</command>,
|
|
|
|
<command>INSERT</command>, <command>UPDATE</command>, and
|
2010-02-03 18:25:06 +01:00
|
|
|
<command>DELETE</command> will continue to function normally, though you
|
2008-06-16 05:13:14 +02:00
|
|
|
will not be able to modify the definition of a table with commands such as
|
|
|
|
<command>ALTER TABLE</command> while it is being vacuumed.)
|
2021-04-01 08:28:37 +02:00
|
|
|
<command>VACUUM FULL</command> requires an
|
|
|
|
<literal>ACCESS EXCLUSIVE</literal> lock on the table it is
|
2008-06-16 05:13:14 +02:00
|
|
|
working on, and therefore cannot be done in parallel with other use
|
2010-02-08 05:33:55 +01:00
|
|
|
of the table. Generally, therefore,
|
2017-10-09 03:44:17 +02:00
|
|
|
administrators should strive to use standard <command>VACUUM</command> and
|
|
|
|
avoid <command>VACUUM FULL</command>.
|
2008-06-16 05:13:14 +02:00
|
|
|
</para>
|
|
|
|
|
|
|
|
<para>
|
|
|
|
<command>VACUUM</command> creates a substantial amount of I/O
|
|
|
|
traffic, which can cause poor performance for other active sessions.
|
|
|
|
There are configuration parameters that can be adjusted to reduce the
|
|
|
|
performance impact of background vacuuming — see
|
2017-11-23 15:39:47 +01:00
|
|
|
<xref linkend="runtime-config-resource-vacuum-cost"/>.
|
2008-06-16 05:13:14 +02:00
|
|
|
</para>
|
|
|
|
</sect2>
|
2005-09-13 03:51:18 +02:00
|
|
|
|
2001-08-26 23:17:12 +02:00
|
|
|
<sect2 id="vacuum-for-space-recovery">
|
2007-09-14 01:43:35 +02:00
|
|
|
<title>Recovering Disk Space</title>
|
2001-08-26 23:17:12 +02:00
|
|
|
|
2001-11-12 20:19:39 +01:00
|
|
|
<indexterm zone="vacuum-for-space-recovery">
|
|
|
|
<primary>disk space</primary>
|
|
|
|
</indexterm>
|
|
|
|
|
2001-08-26 23:17:12 +02:00
|
|
|
<para>
|
2008-06-16 05:13:14 +02:00
|
|
|
In <productname>PostgreSQL</productname>, an
|
2017-10-09 03:44:17 +02:00
|
|
|
<command>UPDATE</command> or <command>DELETE</command> of a row does not
|
2003-11-01 02:56:29 +01:00
|
|
|
immediately remove the old version of the row.
|
2002-06-23 05:37:12 +02:00
|
|
|
This approach is necessary to gain the benefits of multiversion
|
2017-11-23 15:39:47 +01:00
|
|
|
concurrency control (<acronym>MVCC</acronym>, see <xref linkend="mvcc"/>): the row version
|
2002-06-23 05:37:12 +02:00
|
|
|
must not be deleted while it is still potentially visible to other
|
2003-11-01 02:56:29 +01:00
|
|
|
transactions. But eventually, an outdated or deleted row version is no
|
2008-06-16 05:13:14 +02:00
|
|
|
longer of interest to any transaction. The space it occupies must then be
|
2010-02-03 18:25:06 +01:00
|
|
|
reclaimed for reuse by new rows, to avoid unbounded growth of disk
|
2017-10-09 03:44:17 +02:00
|
|
|
space requirements. This is done by running <command>VACUUM</command>.
|
2001-08-26 23:17:12 +02:00
|
|
|
</para>
|
|
|
|
|
|
|
|
<para>
|
2008-06-16 05:13:14 +02:00
|
|
|
The standard form of <command>VACUUM</command> removes dead row
|
|
|
|
versions in tables and indexes and marks the space available for
|
|
|
|
future reuse. However, it will not return the space to the operating
|
|
|
|
system, except in the special case where one or more pages at the
|
|
|
|
end of a table become entirely free and an exclusive table lock can be
|
2017-10-09 03:44:17 +02:00
|
|
|
easily obtained. In contrast, <command>VACUUM FULL</command> actively compacts
|
2010-02-08 05:33:55 +01:00
|
|
|
tables by writing a complete new version of the table file with no dead
|
|
|
|
space. This minimizes the size of the table, but can take a long time.
|
|
|
|
It also requires extra disk space for the new copy of the table, until
|
|
|
|
the operation completes.
|
2003-12-14 01:10:32 +01:00
|
|
|
</para>
|
|
|
|
|
|
|
|
<para>
|
2017-10-09 03:44:17 +02:00
|
|
|
The usual goal of routine vacuuming is to do standard <command>VACUUM</command>s
|
|
|
|
often enough to avoid needing <command>VACUUM FULL</command>. The
|
2008-06-16 05:13:14 +02:00
|
|
|
autovacuum daemon attempts to work this way, and in fact will
|
2017-10-09 03:44:17 +02:00
|
|
|
never issue <command>VACUUM FULL</command>. In this approach, the idea
|
2008-06-16 05:13:14 +02:00
|
|
|
is not to keep tables at their minimum size, but to maintain steady-state
|
|
|
|
usage of disk space: each table occupies space equivalent to its
|
2021-04-09 06:53:07 +02:00
|
|
|
minimum size plus however much space gets used up between vacuum runs.
|
2017-10-09 03:44:17 +02:00
|
|
|
Although <command>VACUUM FULL</command> can be used to shrink a table back
|
2008-06-16 05:13:14 +02:00
|
|
|
to its minimum size and return the disk space to the operating system,
|
|
|
|
there is not much point in this if the table will just grow again in the
|
2017-10-09 03:44:17 +02:00
|
|
|
future. Thus, moderately-frequent standard <command>VACUUM</command> runs are a
|
|
|
|
better approach than infrequent <command>VACUUM FULL</command> runs for
|
2008-06-16 05:13:14 +02:00
|
|
|
maintaining heavily-updated tables.
|
2007-09-14 01:43:35 +02:00
|
|
|
</para>
|
|
|
|
|
|
|
|
<para>
|
2008-06-16 05:13:14 +02:00
|
|
|
Some administrators prefer to schedule vacuuming themselves, for example
|
|
|
|
doing all the work at night when load is low.
|
|
|
|
The difficulty with doing vacuuming according to a fixed schedule
|
|
|
|
is that if a table has an unexpected spike in update activity, it may
|
2017-10-09 03:44:17 +02:00
|
|
|
get bloated to the point that <command>VACUUM FULL</command> is really necessary
|
2008-06-16 05:13:14 +02:00
|
|
|
to reclaim space. Using the autovacuum daemon alleviates this problem,
|
|
|
|
since the daemon schedules vacuuming dynamically in response to update
|
|
|
|
activity. It is unwise to disable the daemon completely unless you
|
|
|
|
have an extremely predictable workload. One possible compromise is
|
|
|
|
to set the daemon's parameters so that it will only react to unusually
|
|
|
|
heavy update activity, thus keeping things from getting out of hand,
|
2017-10-09 03:44:17 +02:00
|
|
|
while scheduled <command>VACUUM</command>s are expected to do the bulk of the
|
2008-06-16 05:13:14 +02:00
|
|
|
work when the load is typical.
|
2001-08-26 23:17:12 +02:00
|
|
|
</para>
|
|
|
|
|
|
|
|
<para>
|
2008-06-16 05:13:14 +02:00
|
|
|
For those not using autovacuum, a typical approach is to schedule a
|
2017-10-09 03:44:17 +02:00
|
|
|
database-wide <command>VACUUM</command> once a day during a low-usage period,
|
2008-06-16 05:13:14 +02:00
|
|
|
supplemented by more frequent vacuuming of heavily-updated tables as
|
2007-09-14 01:43:35 +02:00
|
|
|
necessary. (Some installations with extremely high update rates vacuum
|
|
|
|
their busiest tables as often as once every few minutes.) If you have
|
|
|
|
multiple databases in a cluster, don't forget to
|
|
|
|
<command>VACUUM</command> each one; the program <xref
|
2017-11-23 15:39:47 +01:00
|
|
|
linkend="app-vacuumdb"/> might be helpful.
|
2001-08-26 23:17:12 +02:00
|
|
|
</para>
|
|
|
|
|
2008-06-16 05:13:14 +02:00
|
|
|
<tip>
|
2001-08-26 23:17:12 +02:00
|
|
|
<para>
|
2017-10-09 03:44:17 +02:00
|
|
|
Plain <command>VACUUM</command> may not be satisfactory when
|
2008-06-16 05:13:14 +02:00
|
|
|
a table contains large numbers of dead row versions as a result of
|
|
|
|
massive update or delete activity. If you have such a table and
|
2010-02-08 05:33:55 +01:00
|
|
|
you need to reclaim the excess disk space it occupies, you will need
|
2017-10-09 03:44:17 +02:00
|
|
|
to use <command>VACUUM FULL</command>, or alternatively
|
Improve <xref> vs. <command> formatting in the documentation
SQL commands are generally marked up as <command>, except when a link
to a reference page is used using <xref>. But the latter doesn't
create monospace markup, so this looks strange especially when a
paragraph contains a mix of links and non-links.
We considered putting <command> in the <refentrytitle> on the target
side, but that creates some formatting side effects elsewhere.
Generally, it seems safer to solve this on the link source side.
We can't put the <xref> inside the <command>; the DTD doesn't allow
this. DocBook 5 would allow the <command> to have the linkend
attribute itself, but we are not there yet.
So to solve this for now, convert the <xref>s to <link> plus
<command>. This gives the correct look and also gives some more
flexibility what we can put into the link text (e.g., subcommands or
other clauses). In the future, these could then be converted to
DocBook 5 style.
I haven't converted absolutely all xrefs to SQL command reference
pages, only those where we care about the appearance of the link text
or where it was otherwise appropriate to make the appearance match a
bit better. Also in some cases, the links where repetitive, so in
those cases the links where just removed and replaced by a plain
<command>. In cases where we just want the link and don't
specifically care about the generated link text (typically phrased
"for further information see <xref ...>") the xref is kept.
Reported-by: Dagfinn Ilmari Mannsåker <ilmari@ilmari.org>
Discussion: https://www.postgresql.org/message-id/flat/87o8pco34z.fsf@wibble.ilmari.org
2020-10-03 16:16:51 +02:00
|
|
|
<link linkend="sql-cluster"><command>CLUSTER</command></link>
|
2008-06-16 05:13:14 +02:00
|
|
|
or one of the table-rewriting variants of
|
Improve <xref> vs. <command> formatting in the documentation
SQL commands are generally marked up as <command>, except when a link
to a reference page is used using <xref>. But the latter doesn't
create monospace markup, so this looks strange especially when a
paragraph contains a mix of links and non-links.
We considered putting <command> in the <refentrytitle> on the target
side, but that creates some formatting side effects elsewhere.
Generally, it seems safer to solve this on the link source side.
We can't put the <xref> inside the <command>; the DTD doesn't allow
this. DocBook 5 would allow the <command> to have the linkend
attribute itself, but we are not there yet.
So to solve this for now, convert the <xref>s to <link> plus
<command>. This gives the correct look and also gives some more
flexibility what we can put into the link text (e.g., subcommands or
other clauses). In the future, these could then be converted to
DocBook 5 style.
I haven't converted absolutely all xrefs to SQL command reference
pages, only those where we care about the appearance of the link text
or where it was otherwise appropriate to make the appearance match a
bit better. Also in some cases, the links where repetitive, so in
those cases the links where just removed and replaced by a plain
<command>. In cases where we just want the link and don't
specifically care about the generated link text (typically phrased
"for further information see <xref ...>") the xref is kept.
Reported-by: Dagfinn Ilmari Mannsåker <ilmari@ilmari.org>
Discussion: https://www.postgresql.org/message-id/flat/87o8pco34z.fsf@wibble.ilmari.org
2020-10-03 16:16:51 +02:00
|
|
|
<link linkend="sql-altertable"><command>ALTER TABLE</command></link>.
|
2008-06-16 05:13:14 +02:00
|
|
|
These commands rewrite an entire new copy of the table and build
|
2021-04-01 08:28:37 +02:00
|
|
|
new indexes for it. All these options require an
|
|
|
|
<literal>ACCESS EXCLUSIVE</literal> lock. Note that
|
2010-02-08 05:33:55 +01:00
|
|
|
they also temporarily use extra disk space approximately equal to the size
|
|
|
|
of the table, since the old copies of the table and indexes can't be
|
|
|
|
released until the new ones are complete.
|
2001-08-26 23:17:12 +02:00
|
|
|
</para>
|
2008-06-16 05:13:14 +02:00
|
|
|
</tip>
|
2001-08-26 23:17:12 +02:00
|
|
|
|
2008-06-16 05:13:14 +02:00
|
|
|
<tip>
|
2001-08-26 23:17:12 +02:00
|
|
|
<para>
|
2006-08-01 02:09:06 +02:00
|
|
|
If you have a table whose entire contents are deleted on a periodic
|
2008-06-16 05:13:14 +02:00
|
|
|
basis, consider doing it with
|
Improve <xref> vs. <command> formatting in the documentation
SQL commands are generally marked up as <command>, except when a link
to a reference page is used using <xref>. But the latter doesn't
create monospace markup, so this looks strange especially when a
paragraph contains a mix of links and non-links.
We considered putting <command> in the <refentrytitle> on the target
side, but that creates some formatting side effects elsewhere.
Generally, it seems safer to solve this on the link source side.
We can't put the <xref> inside the <command>; the DTD doesn't allow
this. DocBook 5 would allow the <command> to have the linkend
attribute itself, but we are not there yet.
So to solve this for now, convert the <xref>s to <link> plus
<command>. This gives the correct look and also gives some more
flexibility what we can put into the link text (e.g., subcommands or
other clauses). In the future, these could then be converted to
DocBook 5 style.
I haven't converted absolutely all xrefs to SQL command reference
pages, only those where we care about the appearance of the link text
or where it was otherwise appropriate to make the appearance match a
bit better. Also in some cases, the links where repetitive, so in
those cases the links where just removed and replaced by a plain
<command>. In cases where we just want the link and don't
specifically care about the generated link text (typically phrased
"for further information see <xref ...>") the xref is kept.
Reported-by: Dagfinn Ilmari Mannsåker <ilmari@ilmari.org>
Discussion: https://www.postgresql.org/message-id/flat/87o8pco34z.fsf@wibble.ilmari.org
2020-10-03 16:16:51 +02:00
|
|
|
<link linkend="sql-truncate"><command>TRUNCATE</command></link> rather
|
2006-08-01 21:17:18 +02:00
|
|
|
than using <command>DELETE</command> followed by
|
2003-12-14 01:10:32 +01:00
|
|
|
<command>VACUUM</command>. <command>TRUNCATE</command> removes the
|
2004-12-13 19:05:10 +01:00
|
|
|
entire content of the table immediately, without requiring a
|
2003-12-14 01:10:32 +01:00
|
|
|
subsequent <command>VACUUM</command> or <command>VACUUM
|
|
|
|
FULL</command> to reclaim the now-unused disk space.
|
2008-06-16 05:13:14 +02:00
|
|
|
The disadvantage is that strict MVCC semantics are violated.
|
2001-08-26 23:17:12 +02:00
|
|
|
</para>
|
2008-06-16 05:13:14 +02:00
|
|
|
</tip>
|
2001-08-26 23:17:12 +02:00
|
|
|
</sect2>
|
|
|
|
|
|
|
|
<sect2 id="vacuum-for-statistics">
|
2010-04-03 09:23:02 +02:00
|
|
|
<title>Updating Planner Statistics</title>
|
2001-08-26 23:17:12 +02:00
|
|
|
|
2003-08-31 19:32:24 +02:00
|
|
|
<indexterm zone="vacuum-for-statistics">
|
|
|
|
<primary>statistics</primary>
|
|
|
|
<secondary>of the planner</secondary>
|
|
|
|
</indexterm>
|
|
|
|
|
|
|
|
<indexterm zone="vacuum-for-statistics">
|
|
|
|
<primary>ANALYZE</primary>
|
|
|
|
</indexterm>
|
|
|
|
|
2001-08-26 23:17:12 +02:00
|
|
|
<para>
|
|
|
|
The <productname>PostgreSQL</productname> query planner relies on
|
|
|
|
statistical information about the contents of tables in order to
|
|
|
|
generate good plans for queries. These statistics are gathered by
|
Improve <xref> vs. <command> formatting in the documentation
SQL commands are generally marked up as <command>, except when a link
to a reference page is used using <xref>. But the latter doesn't
create monospace markup, so this looks strange especially when a
paragraph contains a mix of links and non-links.
We considered putting <command> in the <refentrytitle> on the target
side, but that creates some formatting side effects elsewhere.
Generally, it seems safer to solve this on the link source side.
We can't put the <xref> inside the <command>; the DTD doesn't allow
this. DocBook 5 would allow the <command> to have the linkend
attribute itself, but we are not there yet.
So to solve this for now, convert the <xref>s to <link> plus
<command>. This gives the correct look and also gives some more
flexibility what we can put into the link text (e.g., subcommands or
other clauses). In the future, these could then be converted to
DocBook 5 style.
I haven't converted absolutely all xrefs to SQL command reference
pages, only those where we care about the appearance of the link text
or where it was otherwise appropriate to make the appearance match a
bit better. Also in some cases, the links where repetitive, so in
those cases the links where just removed and replaced by a plain
<command>. In cases where we just want the link and don't
specifically care about the generated link text (typically phrased
"for further information see <xref ...>") the xref is kept.
Reported-by: Dagfinn Ilmari Mannsåker <ilmari@ilmari.org>
Discussion: https://www.postgresql.org/message-id/flat/87o8pco34z.fsf@wibble.ilmari.org
2020-10-03 16:16:51 +02:00
|
|
|
the <link linkend="sql-analyze"><command>ANALYZE</command></link> command,
|
2007-10-07 03:16:42 +02:00
|
|
|
which can be invoked by itself or
|
2017-10-09 03:44:17 +02:00
|
|
|
as an optional step in <command>VACUUM</command>. It is important to have
|
Update documentation on may/can/might:
Standard English uses "may", "can", and "might" in different ways:
may - permission, "You may borrow my rake."
can - ability, "I can lift that log."
might - possibility, "It might rain today."
Unfortunately, in conversational English, their use is often mixed, as
in, "You may use this variable to do X", when in fact, "can" is a better
choice. Similarly, "It may crash" is better stated, "It might crash".
Also update two error messages mentioned in the documenation to match.
2007-01-31 21:56:20 +01:00
|
|
|
reasonably accurate statistics, otherwise poor choices of plans might
|
2001-08-26 23:17:12 +02:00
|
|
|
degrade database performance.
|
|
|
|
</para>
|
|
|
|
|
2008-06-16 05:13:14 +02:00
|
|
|
<para>
|
|
|
|
The autovacuum daemon, if enabled, will automatically issue
|
2017-10-09 03:44:17 +02:00
|
|
|
<command>ANALYZE</command> commands whenever the content of a table has
|
2008-06-16 05:13:14 +02:00
|
|
|
changed sufficiently. However, administrators might prefer to rely
|
2017-10-09 03:44:17 +02:00
|
|
|
on manually-scheduled <command>ANALYZE</command> operations, particularly
|
2008-06-16 05:13:14 +02:00
|
|
|
if it is known that update activity on a table will not affect the
|
2017-10-09 03:44:17 +02:00
|
|
|
statistics of <quote>interesting</quote> columns. The daemon schedules
|
|
|
|
<command>ANALYZE</command> strictly as a function of the number of rows
|
2008-06-16 05:13:14 +02:00
|
|
|
inserted or updated; it has no knowledge of whether that will lead
|
|
|
|
to meaningful statistical changes.
|
|
|
|
</para>
|
|
|
|
|
2022-03-28 14:27:36 +02:00
|
|
|
<para>
|
|
|
|
Tuples changed in partitions and inheritance children do not trigger
|
|
|
|
analyze on the parent table. If the parent table is empty or rarely
|
|
|
|
changed, it may never be processed by autovacuum, and the statistics for
|
|
|
|
the inheritance tree as a whole won't be collected. It is necessary to
|
|
|
|
run <command>ANALYZE</command> on the parent table manually in order to
|
|
|
|
keep the statistics up to date.
|
|
|
|
</para>
|
|
|
|
|
2001-08-26 23:17:12 +02:00
|
|
|
<para>
|
|
|
|
As with vacuuming for space recovery, frequent updates of statistics
|
2002-06-23 05:37:12 +02:00
|
|
|
are more useful for heavily-updated tables than for seldom-updated
|
Update documentation on may/can/might:
Standard English uses "may", "can", and "might" in different ways:
may - permission, "You may borrow my rake."
can - ability, "I can lift that log."
might - possibility, "It might rain today."
Unfortunately, in conversational English, their use is often mixed, as
in, "You may use this variable to do X", when in fact, "can" is a better
choice. Similarly, "It may crash" is better stated, "It might crash".
Also update two error messages mentioned in the documenation to match.
2007-01-31 21:56:20 +01:00
|
|
|
ones. But even for a heavily-updated table, there might be no need for
|
2002-06-23 05:37:12 +02:00
|
|
|
statistics updates if the statistical distribution of the data is
|
|
|
|
not changing much. A simple rule of thumb is to think about how much
|
2001-08-26 23:17:12 +02:00
|
|
|
the minimum and maximum values of the columns in the table change.
|
2002-06-23 05:37:12 +02:00
|
|
|
For example, a <type>timestamp</type> column that contains the time
|
|
|
|
of row update will have a constantly-increasing maximum value as
|
|
|
|
rows are added and updated; such a column will probably need more
|
|
|
|
frequent statistics updates than, say, a column containing URLs for
|
Update documentation on may/can/might:
Standard English uses "may", "can", and "might" in different ways:
may - permission, "You may borrow my rake."
can - ability, "I can lift that log."
might - possibility, "It might rain today."
Unfortunately, in conversational English, their use is often mixed, as
in, "You may use this variable to do X", when in fact, "can" is a better
choice. Similarly, "It may crash" is better stated, "It might crash".
Also update two error messages mentioned in the documenation to match.
2007-01-31 21:56:20 +01:00
|
|
|
pages accessed on a website. The URL column might receive changes just
|
2002-06-23 05:37:12 +02:00
|
|
|
as often, but the statistical distribution of its values probably
|
|
|
|
changes relatively slowly.
|
2001-08-26 23:17:12 +02:00
|
|
|
</para>
|
|
|
|
|
|
|
|
<para>
|
2017-10-09 03:44:17 +02:00
|
|
|
It is possible to run <command>ANALYZE</command> on specific tables and even
|
2001-08-26 23:17:12 +02:00
|
|
|
just specific columns of a table, so the flexibility exists to update some
|
|
|
|
statistics more frequently than others if your application requires it.
|
2008-06-16 05:13:14 +02:00
|
|
|
In practice, however, it is usually best to just analyze the entire
|
2017-10-09 03:44:17 +02:00
|
|
|
database, because it is a fast operation. <command>ANALYZE</command> uses a
|
2010-02-03 18:25:06 +01:00
|
|
|
statistically random sampling of the rows of a table rather than reading
|
2008-06-16 05:13:14 +02:00
|
|
|
every single row.
|
2001-08-26 23:17:12 +02:00
|
|
|
</para>
|
|
|
|
|
|
|
|
<tip>
|
|
|
|
<para>
|
2017-10-09 03:44:17 +02:00
|
|
|
Although per-column tweaking of <command>ANALYZE</command> frequency might not be
|
2010-02-03 18:25:06 +01:00
|
|
|
very productive, you might find it worthwhile to do per-column
|
2001-08-26 23:17:12 +02:00
|
|
|
adjustment of the level of detail of the statistics collected by
|
2017-10-09 03:44:17 +02:00
|
|
|
<command>ANALYZE</command>. Columns that are heavily used in <literal>WHERE</literal>
|
2008-06-16 05:13:14 +02:00
|
|
|
clauses and have highly irregular data distributions might require a
|
|
|
|
finer-grain data histogram than other columns. See <command>ALTER TABLE
|
2017-10-09 03:44:17 +02:00
|
|
|
SET STATISTICS</command>, or change the database-wide default using the <xref
|
2017-11-23 15:39:47 +01:00
|
|
|
linkend="guc-default-statistics-target"/> configuration parameter.
|
2001-08-26 23:17:12 +02:00
|
|
|
</para>
|
2010-02-23 03:47:27 +01:00
|
|
|
|
|
|
|
<para>
|
|
|
|
Also, by default there is limited information available about
|
2021-05-07 14:02:22 +02:00
|
|
|
the selectivity of functions. However, if you create a statistics
|
|
|
|
object or an expression
|
2010-02-23 03:47:27 +01:00
|
|
|
index that uses a function call, useful statistics will be
|
|
|
|
gathered about the function, which can greatly improve query
|
|
|
|
plans that use the expression index.
|
|
|
|
</para>
|
2001-08-26 23:17:12 +02:00
|
|
|
</tip>
|
2012-04-06 21:02:35 +02:00
|
|
|
|
|
|
|
<tip>
|
|
|
|
<para>
|
2017-10-09 03:44:17 +02:00
|
|
|
The autovacuum daemon does not issue <command>ANALYZE</command> commands for
|
2012-04-06 21:02:35 +02:00
|
|
|
foreign tables, since it has no means of determining how often that
|
|
|
|
might be useful. If your queries require statistics on foreign tables
|
|
|
|
for proper planning, it's a good idea to run manually-managed
|
2017-10-09 03:44:17 +02:00
|
|
|
<command>ANALYZE</command> commands on those tables on a suitable schedule.
|
2012-04-06 21:02:35 +02:00
|
|
|
</para>
|
|
|
|
</tip>
|
2022-03-28 14:27:36 +02:00
|
|
|
|
|
|
|
<tip>
|
|
|
|
<para>
|
|
|
|
The autovacuum daemon does not issue <command>ANALYZE</command> commands
|
|
|
|
for partitioned tables. Inheritance parents will only be analyzed if the
|
|
|
|
parent itself is changed - changes to child tables do not trigger
|
|
|
|
autoanalyze on the parent table. If your queries require statistics on
|
|
|
|
parent tables for proper planning, it is necessary to periodically run
|
|
|
|
a manual <command>ANALYZE</command> on those tables to keep the statistics
|
|
|
|
up to date.
|
|
|
|
</para>
|
|
|
|
</tip>
|
|
|
|
|
2001-08-26 23:17:12 +02:00
|
|
|
</sect2>
|
|
|
|
|
2012-03-21 19:51:11 +01:00
|
|
|
<sect2 id="vacuum-for-visibility-map">
|
2019-09-08 10:26:35 +02:00
|
|
|
<title>Updating the Visibility Map</title>
|
2012-03-21 19:51:11 +01:00
|
|
|
|
|
|
|
<para>
|
2017-10-09 03:44:17 +02:00
|
|
|
Vacuum maintains a <link linkend="storage-vm">visibility map</link> for each
|
2012-03-21 19:51:11 +01:00
|
|
|
table to keep track of which pages contain only tuples that are known to be
|
|
|
|
visible to all active transactions (and all future transactions, until the
|
|
|
|
page is again modified). This has two purposes. First, vacuum
|
|
|
|
itself can skip such pages on the next run, since there is nothing to
|
|
|
|
clean up.
|
|
|
|
</para>
|
|
|
|
|
|
|
|
<para>
|
|
|
|
Second, it allows <productname>PostgreSQL</productname> to answer some
|
|
|
|
queries using only the index, without reference to the underlying table.
|
|
|
|
Since <productname>PostgreSQL</productname> indexes don't contain tuple
|
|
|
|
visibility information, a normal index scan fetches the heap tuple for each
|
|
|
|
matching index entry, to check whether it should be seen by the current
|
2016-05-08 22:36:19 +02:00
|
|
|
transaction.
|
|
|
|
An <link linkend="indexes-index-only-scans"><firstterm>index-only
|
2017-10-09 03:44:17 +02:00
|
|
|
scan</firstterm></link>, on the other hand, checks the visibility map first.
|
2016-05-08 22:36:19 +02:00
|
|
|
If it's known that all tuples on the page are
|
|
|
|
visible, the heap fetch can be skipped. This is most useful on
|
2012-03-21 19:51:11 +01:00
|
|
|
large data sets where the visibility map can prevent disk accesses.
|
|
|
|
The visibility map is vastly smaller than the heap, so it can easily be
|
|
|
|
cached even when the heap is very large.
|
|
|
|
</para>
|
|
|
|
</sect2>
|
|
|
|
|
2001-08-26 23:17:12 +02:00
|
|
|
<sect2 id="vacuum-for-wraparound">
|
2007-09-24 05:12:23 +02:00
|
|
|
<title>Preventing Transaction ID Wraparound Failures</title>
|
2001-08-26 23:17:12 +02:00
|
|
|
|
2001-11-12 20:19:39 +01:00
|
|
|
<indexterm zone="vacuum-for-wraparound">
|
|
|
|
<primary>transaction ID</primary>
|
|
|
|
<secondary>wraparound</secondary>
|
|
|
|
</indexterm>
|
|
|
|
|
Separate multixact freezing parameters from xid's
Previously we were piggybacking on transaction ID parameters to freeze
multixacts; but since there isn't necessarily any relationship between
rates of Xid and multixact consumption, this turns out not to be a good
idea.
Therefore, we now have multixact-specific freezing parameters:
vacuum_multixact_freeze_min_age: when to remove multis as we come across
them in vacuum (default to 5 million, i.e. early in comparison to Xid's
default of 50 million)
vacuum_multixact_freeze_table_age: when to force whole-table scans
instead of scanning only the pages marked as not all visible in
visibility map (default to 150 million, same as for Xids). Whichever of
both which reaches the 150 million mark earlier will cause a whole-table
scan.
autovacuum_multixact_freeze_max_age: when for cause emergency,
uninterruptible whole-table scans (default to 400 million, double as
that for Xids). This means there shouldn't be more frequent emergency
vacuuming than previously, unless multixacts are being used very
rapidly.
Backpatch to 9.3 where multixacts were made to persist enough to require
freezing. To avoid an ABI break in 9.3, VacuumStmt has a couple of
fields in an unnatural place, and StdRdOptions is split in two so that
the newly added fields can go at the end.
Patch by me, reviewed by Robert Haas, with additional input from Andres
Freund and Tom Lane.
2014-02-13 23:30:30 +01:00
|
|
|
<indexterm>
|
|
|
|
<primary>wraparound</primary>
|
|
|
|
<secondary>of transaction IDs</secondary>
|
|
|
|
</indexterm>
|
|
|
|
|
2001-08-26 23:17:12 +02:00
|
|
|
<para>
|
2016-09-06 23:50:53 +02:00
|
|
|
<productname>PostgreSQL</productname>'s
|
|
|
|
<link linkend="mvcc-intro">MVCC</link> transaction semantics
|
2017-10-09 03:44:17 +02:00
|
|
|
depend on being able to compare transaction ID (<acronym>XID</acronym>)
|
2003-11-01 02:56:29 +01:00
|
|
|
numbers: a row version with an insertion XID greater than the current
|
2017-10-09 03:44:17 +02:00
|
|
|
transaction's XID is <quote>in the future</quote> and should not be visible
|
2001-08-26 23:17:12 +02:00
|
|
|
to the current transaction. But since transaction IDs have limited size
|
2010-02-03 18:25:06 +01:00
|
|
|
(32 bits) a cluster that runs for a long time (more
|
2005-02-20 03:22:07 +01:00
|
|
|
than 4 billion transactions) would suffer <firstterm>transaction ID
|
2017-10-09 03:44:17 +02:00
|
|
|
wraparound</firstterm>: the XID counter wraps around to zero, and all of a sudden
|
2004-11-15 07:32:15 +01:00
|
|
|
transactions that were in the past appear to be in the future — which
|
2010-02-03 18:25:06 +01:00
|
|
|
means their output become invisible. In short, catastrophic data loss.
|
Wording cleanup for error messages. Also change can't -> cannot.
Standard English uses "may", "can", and "might" in different ways:
may - permission, "You may borrow my rake."
can - ability, "I can lift that log."
might - possibility, "It might rain today."
Unfortunately, in conversational English, their use is often mixed, as
in, "You may use this variable to do X", when in fact, "can" is a better
choice. Similarly, "It may crash" is better stated, "It might crash".
2007-02-01 20:10:30 +01:00
|
|
|
(Actually the data is still there, but that's cold comfort if you cannot
|
Fix recently-understood problems with handling of XID freezing, particularly
in PITR scenarios. We now WAL-log the replacement of old XIDs with
FrozenTransactionId, so that such replacement is guaranteed to propagate to
PITR slave databases. Also, rather than relying on hint-bit updates to be
preserved, pg_clog is not truncated until all instances of an XID are known to
have been replaced by FrozenTransactionId. Add new GUC variables and
pg_autovacuum columns to allow management of the freezing policy, so that
users can trade off the size of pg_clog against the amount of freezing work
done. Revise the already-existing code that forces autovacuum of tables
approaching the wraparound point to make it more bulletproof; also, revise the
autovacuum logic so that anti-wraparound vacuuming is done per-table rather
than per-database. initdb forced because of changes in pg_class, pg_database,
and pg_autovacuum catalogs. Heikki Linnakangas, Simon Riggs, and Tom Lane.
2006-11-05 23:42:10 +01:00
|
|
|
get at it.) To avoid this, it is necessary to vacuum every table
|
|
|
|
in every database at least once every two billion transactions.
|
2001-08-26 23:17:12 +02:00
|
|
|
</para>
|
|
|
|
|
|
|
|
<para>
|
Fix recently-understood problems with handling of XID freezing, particularly
in PITR scenarios. We now WAL-log the replacement of old XIDs with
FrozenTransactionId, so that such replacement is guaranteed to propagate to
PITR slave databases. Also, rather than relying on hint-bit updates to be
preserved, pg_clog is not truncated until all instances of an XID are known to
have been replaced by FrozenTransactionId. Add new GUC variables and
pg_autovacuum columns to allow management of the freezing policy, so that
users can trade off the size of pg_clog against the amount of freezing work
done. Revise the already-existing code that forces autovacuum of tables
approaching the wraparound point to make it more bulletproof; also, revise the
autovacuum logic so that anti-wraparound vacuuming is done per-table rather
than per-database. initdb forced because of changes in pg_class, pg_database,
and pg_autovacuum catalogs. Heikki Linnakangas, Simon Riggs, and Tom Lane.
2006-11-05 23:42:10 +01:00
|
|
|
The reason that periodic vacuuming solves the problem is that
|
2017-10-09 03:44:17 +02:00
|
|
|
<command>VACUUM</command> will mark rows as <emphasis>frozen</emphasis>, indicating that
|
2016-09-06 23:50:53 +02:00
|
|
|
they were inserted by a transaction that committed sufficiently far in
|
|
|
|
the past that the effects of the inserting transaction are certain to be
|
|
|
|
visible to all current and future transactions.
|
|
|
|
Normal XIDs are
|
2017-10-09 03:44:17 +02:00
|
|
|
compared using modulo-2<superscript>32</superscript> arithmetic. This means
|
2001-08-26 23:17:12 +02:00
|
|
|
that for every normal XID, there are two billion XIDs that are
|
2017-10-09 03:44:17 +02:00
|
|
|
<quote>older</quote> and two billion that are <quote>newer</quote>; another
|
2002-06-23 05:37:12 +02:00
|
|
|
way to say it is that the normal XID space is circular with no
|
2003-11-01 02:56:29 +01:00
|
|
|
endpoint. Therefore, once a row version has been created with a particular
|
2017-10-09 03:44:17 +02:00
|
|
|
normal XID, the row version will appear to be <quote>in the past</quote> for
|
2002-06-23 05:37:12 +02:00
|
|
|
the next two billion transactions, no matter which normal XID we are
|
2003-11-01 02:56:29 +01:00
|
|
|
talking about. If the row version still exists after more than two billion
|
2002-06-23 05:37:12 +02:00
|
|
|
transactions, it will suddenly appear to be in the future. To
|
2017-10-09 03:44:17 +02:00
|
|
|
prevent this, <productname>PostgreSQL</productname> reserves a special XID,
|
|
|
|
<literal>FrozenTransactionId</literal>, which does not follow the normal XID
|
2016-09-06 23:50:53 +02:00
|
|
|
comparison rules and is always considered older
|
|
|
|
than every normal XID.
|
|
|
|
Frozen row versions are treated as if the inserting XID were
|
2017-10-09 03:44:17 +02:00
|
|
|
<literal>FrozenTransactionId</literal>, so that they will appear to be
|
|
|
|
<quote>in the past</quote> to all normal transactions regardless of wraparound
|
2013-12-24 02:32:29 +01:00
|
|
|
issues, and so such row versions will be valid until deleted, no matter
|
|
|
|
how long that is.
|
Fix recently-understood problems with handling of XID freezing, particularly
in PITR scenarios. We now WAL-log the replacement of old XIDs with
FrozenTransactionId, so that such replacement is guaranteed to propagate to
PITR slave databases. Also, rather than relying on hint-bit updates to be
preserved, pg_clog is not truncated until all instances of an XID are known to
have been replaced by FrozenTransactionId. Add new GUC variables and
pg_autovacuum columns to allow management of the freezing policy, so that
users can trade off the size of pg_clog against the amount of freezing work
done. Revise the already-existing code that forces autovacuum of tables
approaching the wraparound point to make it more bulletproof; also, revise the
autovacuum logic so that anti-wraparound vacuuming is done per-table rather
than per-database. initdb forced because of changes in pg_class, pg_database,
and pg_autovacuum catalogs. Heikki Linnakangas, Simon Riggs, and Tom Lane.
2006-11-05 23:42:10 +01:00
|
|
|
</para>
|
|
|
|
|
2016-09-06 23:50:53 +02:00
|
|
|
<note>
|
|
|
|
<para>
|
2017-10-09 03:44:17 +02:00
|
|
|
In <productname>PostgreSQL</productname> versions before 9.4, freezing was
|
2016-09-06 23:50:53 +02:00
|
|
|
implemented by actually replacing a row's insertion XID
|
2017-10-09 03:44:17 +02:00
|
|
|
with <literal>FrozenTransactionId</literal>, which was visible in the
|
|
|
|
row's <structname>xmin</structname> system column. Newer versions just set a flag
|
|
|
|
bit, preserving the row's original <structname>xmin</structname> for possible
|
|
|
|
forensic use. However, rows with <structname>xmin</structname> equal
|
|
|
|
to <literal>FrozenTransactionId</literal> (2) may still be found
|
|
|
|
in databases <application>pg_upgrade</application>'d from pre-9.4 versions.
|
2016-09-06 23:50:53 +02:00
|
|
|
</para>
|
|
|
|
<para>
|
2017-10-09 03:44:17 +02:00
|
|
|
Also, system catalogs may contain rows with <structname>xmin</structname> equal
|
|
|
|
to <literal>BootstrapTransactionId</literal> (1), indicating that they were
|
|
|
|
inserted during the first phase of <application>initdb</application>.
|
|
|
|
Like <literal>FrozenTransactionId</literal>, this special XID is treated as
|
2016-09-06 23:50:53 +02:00
|
|
|
older than every normal XID.
|
|
|
|
</para>
|
|
|
|
</note>
|
|
|
|
|
Fix recently-understood problems with handling of XID freezing, particularly
in PITR scenarios. We now WAL-log the replacement of old XIDs with
FrozenTransactionId, so that such replacement is guaranteed to propagate to
PITR slave databases. Also, rather than relying on hint-bit updates to be
preserved, pg_clog is not truncated until all instances of an XID are known to
have been replaced by FrozenTransactionId. Add new GUC variables and
pg_autovacuum columns to allow management of the freezing policy, so that
users can trade off the size of pg_clog against the amount of freezing work
done. Revise the already-existing code that forces autovacuum of tables
approaching the wraparound point to make it more bulletproof; also, revise the
autovacuum logic so that anti-wraparound vacuuming is done per-table rather
than per-database. initdb forced because of changes in pg_class, pg_database,
and pg_autovacuum catalogs. Heikki Linnakangas, Simon Riggs, and Tom Lane.
2006-11-05 23:42:10 +01:00
|
|
|
<para>
|
2023-01-26 07:22:27 +01:00
|
|
|
<xref linkend="guc-vacuum-freeze-min-age"/>
|
|
|
|
controls how old an XID value has to be before rows bearing that XID will be
|
|
|
|
frozen. Increasing this setting may avoid unnecessary work if the
|
|
|
|
rows that would otherwise be frozen will soon be modified again,
|
|
|
|
but decreasing this setting increases
|
|
|
|
the number of transactions that can elapse before the table must be
|
|
|
|
vacuumed again.
|
Fix recently-understood problems with handling of XID freezing, particularly
in PITR scenarios. We now WAL-log the replacement of old XIDs with
FrozenTransactionId, so that such replacement is guaranteed to propagate to
PITR slave databases. Also, rather than relying on hint-bit updates to be
preserved, pg_clog is not truncated until all instances of an XID are known to
have been replaced by FrozenTransactionId. Add new GUC variables and
pg_autovacuum columns to allow management of the freezing policy, so that
users can trade off the size of pg_clog against the amount of freezing work
done. Revise the already-existing code that forces autovacuum of tables
approaching the wraparound point to make it more bulletproof; also, revise the
autovacuum logic so that anti-wraparound vacuuming is done per-table rather
than per-database. initdb forced because of changes in pg_class, pg_database,
and pg_autovacuum catalogs. Heikki Linnakangas, Simon Riggs, and Tom Lane.
2006-11-05 23:42:10 +01:00
|
|
|
</para>
|
|
|
|
|
2009-05-17 00:51:24 +02:00
|
|
|
<para>
|
2017-10-09 03:44:17 +02:00
|
|
|
<command>VACUUM</command> uses the <link linkend="storage-vm">visibility map</link>
|
2016-09-06 23:50:53 +02:00
|
|
|
to determine which pages of a table must be scanned. Normally, it
|
|
|
|
will skip pages that don't have any dead row versions even if those pages
|
2016-03-10 22:12:10 +01:00
|
|
|
might still have row versions with old XID values. Therefore, normal
|
2017-10-09 03:44:17 +02:00
|
|
|
<command>VACUUM</command>s won't always freeze every old row version in the table.
|
2022-04-02 21:29:35 +02:00
|
|
|
When that happens, <command>VACUUM</command> will eventually need to perform an
|
|
|
|
<firstterm>aggressive vacuum</firstterm>, which will freeze all eligible unfrozen
|
|
|
|
XID and MXID values, including those from all-visible but not all-frozen pages.
|
|
|
|
In practice most tables require periodic aggressive vacuuming.
|
2017-11-23 15:39:47 +01:00
|
|
|
<xref linkend="guc-vacuum-freeze-table-age"/>
|
2017-10-09 03:44:17 +02:00
|
|
|
controls when <command>VACUUM</command> does that: all-visible but not all-frozen
|
2016-03-10 22:12:10 +01:00
|
|
|
pages are scanned if the number of transactions that have passed since the
|
2017-10-09 03:44:17 +02:00
|
|
|
last such scan is greater than <varname>vacuum_freeze_table_age</varname> minus
|
|
|
|
<varname>vacuum_freeze_min_age</varname>. Setting
|
|
|
|
<varname>vacuum_freeze_table_age</varname> to 0 forces <command>VACUUM</command> to
|
2022-04-02 21:29:35 +02:00
|
|
|
always use its aggressive strategy.
|
2009-05-17 00:51:24 +02:00
|
|
|
</para>
|
|
|
|
|
Fix recently-understood problems with handling of XID freezing, particularly
in PITR scenarios. We now WAL-log the replacement of old XIDs with
FrozenTransactionId, so that such replacement is guaranteed to propagate to
PITR slave databases. Also, rather than relying on hint-bit updates to be
preserved, pg_clog is not truncated until all instances of an XID are known to
have been replaced by FrozenTransactionId. Add new GUC variables and
pg_autovacuum columns to allow management of the freezing policy, so that
users can trade off the size of pg_clog against the amount of freezing work
done. Revise the already-existing code that forces autovacuum of tables
approaching the wraparound point to make it more bulletproof; also, revise the
autovacuum logic so that anti-wraparound vacuuming is done per-table rather
than per-database. initdb forced because of changes in pg_class, pg_database,
and pg_autovacuum catalogs. Heikki Linnakangas, Simon Riggs, and Tom Lane.
2006-11-05 23:42:10 +01:00
|
|
|
<para>
|
|
|
|
The maximum time that a table can go unvacuumed is two billion
|
2017-10-09 03:44:17 +02:00
|
|
|
transactions minus the <varname>vacuum_freeze_min_age</varname> value at
|
2016-03-10 22:12:10 +01:00
|
|
|
the time of the last aggressive vacuum. If it were to go
|
2023-01-26 07:22:27 +01:00
|
|
|
unvacuumed for longer than
|
|
|
|
that, data loss could result. To ensure that this does not happen,
|
2013-12-24 02:32:29 +01:00
|
|
|
autovacuum is invoked on any table that might contain unfrozen rows with
|
|
|
|
XIDs older than the age specified by the configuration parameter <xref
|
2017-11-23 15:39:47 +01:00
|
|
|
linkend="guc-autovacuum-freeze-max-age"/>. (This will happen even if
|
2010-02-03 18:25:06 +01:00
|
|
|
autovacuum is disabled.)
|
Fix recently-understood problems with handling of XID freezing, particularly
in PITR scenarios. We now WAL-log the replacement of old XIDs with
FrozenTransactionId, so that such replacement is guaranteed to propagate to
PITR slave databases. Also, rather than relying on hint-bit updates to be
preserved, pg_clog is not truncated until all instances of an XID are known to
have been replaced by FrozenTransactionId. Add new GUC variables and
pg_autovacuum columns to allow management of the freezing policy, so that
users can trade off the size of pg_clog against the amount of freezing work
done. Revise the already-existing code that forces autovacuum of tables
approaching the wraparound point to make it more bulletproof; also, revise the
autovacuum logic so that anti-wraparound vacuuming is done per-table rather
than per-database. initdb forced because of changes in pg_class, pg_database,
and pg_autovacuum catalogs. Heikki Linnakangas, Simon Riggs, and Tom Lane.
2006-11-05 23:42:10 +01:00
|
|
|
</para>
|
|
|
|
|
|
|
|
<para>
|
|
|
|
This implies that if a table is not otherwise vacuumed,
|
|
|
|
autovacuum will be invoked on it approximately once every
|
2017-10-09 03:44:17 +02:00
|
|
|
<varname>autovacuum_freeze_max_age</varname> minus
|
|
|
|
<varname>vacuum_freeze_min_age</varname> transactions.
|
Fix recently-understood problems with handling of XID freezing, particularly
in PITR scenarios. We now WAL-log the replacement of old XIDs with
FrozenTransactionId, so that such replacement is guaranteed to propagate to
PITR slave databases. Also, rather than relying on hint-bit updates to be
preserved, pg_clog is not truncated until all instances of an XID are known to
have been replaced by FrozenTransactionId. Add new GUC variables and
pg_autovacuum columns to allow management of the freezing policy, so that
users can trade off the size of pg_clog against the amount of freezing work
done. Revise the already-existing code that forces autovacuum of tables
approaching the wraparound point to make it more bulletproof; also, revise the
autovacuum logic so that anti-wraparound vacuuming is done per-table rather
than per-database. initdb forced because of changes in pg_class, pg_database,
and pg_autovacuum catalogs. Heikki Linnakangas, Simon Riggs, and Tom Lane.
2006-11-05 23:42:10 +01:00
|
|
|
For tables that are regularly vacuumed for space reclamation purposes,
|
|
|
|
this is of little importance. However, for static tables
|
|
|
|
(including tables that receive inserts, but no updates or deletes),
|
2010-02-03 18:25:06 +01:00
|
|
|
there is no need to vacuum for space reclamation, so it can
|
Fix recently-understood problems with handling of XID freezing, particularly
in PITR scenarios. We now WAL-log the replacement of old XIDs with
FrozenTransactionId, so that such replacement is guaranteed to propagate to
PITR slave databases. Also, rather than relying on hint-bit updates to be
preserved, pg_clog is not truncated until all instances of an XID are known to
have been replaced by FrozenTransactionId. Add new GUC variables and
pg_autovacuum columns to allow management of the freezing policy, so that
users can trade off the size of pg_clog against the amount of freezing work
done. Revise the already-existing code that forces autovacuum of tables
approaching the wraparound point to make it more bulletproof; also, revise the
autovacuum logic so that anti-wraparound vacuuming is done per-table rather
than per-database. initdb forced because of changes in pg_class, pg_database,
and pg_autovacuum catalogs. Heikki Linnakangas, Simon Riggs, and Tom Lane.
2006-11-05 23:42:10 +01:00
|
|
|
be useful to try to maximize the interval between forced autovacuums
|
|
|
|
on very large static tables. Obviously one can do this either by
|
2017-10-09 03:44:17 +02:00
|
|
|
increasing <varname>autovacuum_freeze_max_age</varname> or decreasing
|
|
|
|
<varname>vacuum_freeze_min_age</varname>.
|
Fix recently-understood problems with handling of XID freezing, particularly
in PITR scenarios. We now WAL-log the replacement of old XIDs with
FrozenTransactionId, so that such replacement is guaranteed to propagate to
PITR slave databases. Also, rather than relying on hint-bit updates to be
preserved, pg_clog is not truncated until all instances of an XID are known to
have been replaced by FrozenTransactionId. Add new GUC variables and
pg_autovacuum columns to allow management of the freezing policy, so that
users can trade off the size of pg_clog against the amount of freezing work
done. Revise the already-existing code that forces autovacuum of tables
approaching the wraparound point to make it more bulletproof; also, revise the
autovacuum logic so that anti-wraparound vacuuming is done per-table rather
than per-database. initdb forced because of changes in pg_class, pg_database,
and pg_autovacuum catalogs. Heikki Linnakangas, Simon Riggs, and Tom Lane.
2006-11-05 23:42:10 +01:00
|
|
|
</para>
|
|
|
|
|
|
|
|
<para>
|
2017-10-09 03:44:17 +02:00
|
|
|
The effective maximum for <varname>vacuum_freeze_table_age</varname> is 0.95 *
|
|
|
|
<varname>autovacuum_freeze_max_age</varname>; a setting higher than that will be
|
2009-05-17 00:51:24 +02:00
|
|
|
capped to the maximum. A value higher than
|
2017-10-09 03:44:17 +02:00
|
|
|
<varname>autovacuum_freeze_max_age</varname> wouldn't make sense because an
|
2009-04-23 12:09:11 +02:00
|
|
|
anti-wraparound autovacuum would be triggered at that point anyway, and
|
|
|
|
the 0.95 multiplier leaves some breathing room to run a manual
|
2017-10-09 03:44:17 +02:00
|
|
|
<command>VACUUM</command> before that happens. As a rule of thumb,
|
|
|
|
<command>vacuum_freeze_table_age</command> should be set to a value somewhat
|
|
|
|
below <varname>autovacuum_freeze_max_age</varname>, leaving enough gap so that
|
|
|
|
a regularly scheduled <command>VACUUM</command> or an autovacuum triggered by
|
2009-04-23 12:09:11 +02:00
|
|
|
normal delete and update activity is run in that window. Setting it too
|
|
|
|
close could lead to anti-wraparound autovacuums, even though the table
|
|
|
|
was recently vacuumed to reclaim space, whereas lower values lead to more
|
2016-03-10 22:12:10 +01:00
|
|
|
frequent aggressive vacuuming.
|
2009-04-23 12:09:11 +02:00
|
|
|
</para>
|
|
|
|
|
|
|
|
<para>
|
2023-01-26 07:22:27 +01:00
|
|
|
The sole disadvantage of increasing <varname>autovacuum_freeze_max_age</varname>
|
2017-10-09 03:44:17 +02:00
|
|
|
(and <varname>vacuum_freeze_table_age</varname> along with it) is that
|
|
|
|
the <filename>pg_xact</filename> and <filename>pg_commit_ts</filename>
|
2017-09-01 08:57:05 +02:00
|
|
|
subdirectories of the database cluster will take more space, because it
|
2017-10-09 03:44:17 +02:00
|
|
|
must store the commit status and (if <varname>track_commit_timestamp</varname> is
|
2017-09-01 08:57:05 +02:00
|
|
|
enabled) timestamp of all transactions back to
|
2017-10-09 03:44:17 +02:00
|
|
|
the <varname>autovacuum_freeze_max_age</varname> horizon. The commit status uses
|
2017-09-01 08:57:05 +02:00
|
|
|
two bits per transaction, so if
|
2017-10-09 03:44:17 +02:00
|
|
|
<varname>autovacuum_freeze_max_age</varname> is set to its maximum allowed value
|
|
|
|
of two billion, <filename>pg_xact</filename> can be expected to grow to about half
|
2017-09-01 08:57:05 +02:00
|
|
|
a gigabyte and <filename>pg_commit_ts</filename> to about 20GB. If this
|
|
|
|
is trivial compared to your total database size,
|
2017-10-09 03:44:17 +02:00
|
|
|
setting <varname>autovacuum_freeze_max_age</varname> to its maximum allowed value
|
2017-09-01 08:57:05 +02:00
|
|
|
is recommended. Otherwise, set it depending on what you are willing to
|
2017-10-09 03:44:17 +02:00
|
|
|
allow for <filename>pg_xact</filename> and <filename>pg_commit_ts</filename> storage.
|
2017-09-01 08:57:05 +02:00
|
|
|
(The default, 200 million transactions, translates to about 50MB
|
2017-10-09 03:44:17 +02:00
|
|
|
of <filename>pg_xact</filename> storage and about 2GB of <filename>pg_commit_ts</filename>
|
2017-09-01 08:57:05 +02:00
|
|
|
storage.)
|
2001-08-26 23:17:12 +02:00
|
|
|
</para>
|
|
|
|
|
|
|
|
<para>
|
2017-10-09 03:44:17 +02:00
|
|
|
One disadvantage of decreasing <varname>vacuum_freeze_min_age</varname> is that
|
|
|
|
it might cause <command>VACUUM</command> to do useless work: freezing a row
|
2013-12-24 02:32:29 +01:00
|
|
|
version is a waste of time if the row is modified
|
Fix recently-understood problems with handling of XID freezing, particularly
in PITR scenarios. We now WAL-log the replacement of old XIDs with
FrozenTransactionId, so that such replacement is guaranteed to propagate to
PITR slave databases. Also, rather than relying on hint-bit updates to be
preserved, pg_clog is not truncated until all instances of an XID are known to
have been replaced by FrozenTransactionId. Add new GUC variables and
pg_autovacuum columns to allow management of the freezing policy, so that
users can trade off the size of pg_clog against the amount of freezing work
done. Revise the already-existing code that forces autovacuum of tables
approaching the wraparound point to make it more bulletproof; also, revise the
autovacuum logic so that anti-wraparound vacuuming is done per-table rather
than per-database. initdb forced because of changes in pg_class, pg_database,
and pg_autovacuum catalogs. Heikki Linnakangas, Simon Riggs, and Tom Lane.
2006-11-05 23:42:10 +01:00
|
|
|
soon thereafter (causing it to acquire a new XID). So the setting should
|
|
|
|
be large enough that rows are not frozen until they are unlikely to change
|
2013-12-24 02:32:29 +01:00
|
|
|
any more.
|
2001-08-26 23:17:12 +02:00
|
|
|
</para>
|
|
|
|
|
|
|
|
<para>
|
2013-12-24 02:32:29 +01:00
|
|
|
To track the age of the oldest unfrozen XIDs in a database,
|
2017-10-09 03:44:17 +02:00
|
|
|
<command>VACUUM</command> stores XID
|
|
|
|
statistics in the system tables <structname>pg_class</structname> and
|
|
|
|
<structname>pg_database</structname>. In particular,
|
|
|
|
the <structfield>relfrozenxid</structfield> column of a table's
|
2022-04-03 18:57:21 +02:00
|
|
|
<structname>pg_class</structname> row contains the oldest remaining unfrozen
|
|
|
|
XID at the end of the most recent <command>VACUUM</command> that successfully
|
|
|
|
advanced <structfield>relfrozenxid</structfield> (typically the most recent
|
|
|
|
aggressive VACUUM). Similarly, the
|
|
|
|
<structfield>datfrozenxid</structfield> column of a database's
|
2017-10-09 03:44:17 +02:00
|
|
|
<structname>pg_database</structname> row is a lower bound on the unfrozen XIDs
|
Fix recently-understood problems with handling of XID freezing, particularly
in PITR scenarios. We now WAL-log the replacement of old XIDs with
FrozenTransactionId, so that such replacement is guaranteed to propagate to
PITR slave databases. Also, rather than relying on hint-bit updates to be
preserved, pg_clog is not truncated until all instances of an XID are known to
have been replaced by FrozenTransactionId. Add new GUC variables and
pg_autovacuum columns to allow management of the freezing policy, so that
users can trade off the size of pg_clog against the amount of freezing work
done. Revise the already-existing code that forces autovacuum of tables
approaching the wraparound point to make it more bulletproof; also, revise the
autovacuum logic so that anti-wraparound vacuuming is done per-table rather
than per-database. initdb forced because of changes in pg_class, pg_database,
and pg_autovacuum catalogs. Heikki Linnakangas, Simon Riggs, and Tom Lane.
2006-11-05 23:42:10 +01:00
|
|
|
appearing in that database — it is just the minimum of the
|
2017-10-09 03:44:17 +02:00
|
|
|
per-table <structfield>relfrozenxid</structfield> values within the database.
|
Fix recently-understood problems with handling of XID freezing, particularly
in PITR scenarios. We now WAL-log the replacement of old XIDs with
FrozenTransactionId, so that such replacement is guaranteed to propagate to
PITR slave databases. Also, rather than relying on hint-bit updates to be
preserved, pg_clog is not truncated until all instances of an XID are known to
have been replaced by FrozenTransactionId. Add new GUC variables and
pg_autovacuum columns to allow management of the freezing policy, so that
users can trade off the size of pg_clog against the amount of freezing work
done. Revise the already-existing code that forces autovacuum of tables
approaching the wraparound point to make it more bulletproof; also, revise the
autovacuum logic so that anti-wraparound vacuuming is done per-table rather
than per-database. initdb forced because of changes in pg_class, pg_database,
and pg_autovacuum catalogs. Heikki Linnakangas, Simon Riggs, and Tom Lane.
2006-11-05 23:42:10 +01:00
|
|
|
A convenient way to
|
2007-02-01 01:28:19 +01:00
|
|
|
examine this information is to execute queries such as:
|
2002-11-11 21:14:04 +01:00
|
|
|
|
2001-08-26 23:17:12 +02:00
|
|
|
<programlisting>
|
2013-09-02 20:38:12 +02:00
|
|
|
SELECT c.oid::regclass as table_name,
|
|
|
|
greatest(age(c.relfrozenxid),age(t.relfrozenxid)) as age
|
|
|
|
FROM pg_class c
|
|
|
|
LEFT JOIN pg_class t ON c.reltoastrelid = t.oid
|
|
|
|
WHERE c.relkind IN ('r', 'm');
|
|
|
|
|
2001-10-13 01:32:34 +02:00
|
|
|
SELECT datname, age(datfrozenxid) FROM pg_database;
|
2001-08-26 23:17:12 +02:00
|
|
|
</programlisting>
|
2002-11-11 21:14:04 +01:00
|
|
|
|
2017-10-09 03:44:17 +02:00
|
|
|
The <literal>age</literal> column measures the number of transactions from the
|
2009-05-17 00:51:24 +02:00
|
|
|
cutoff XID to the current transaction's XID.
|
|
|
|
</para>
|
|
|
|
|
2022-04-02 22:34:57 +02:00
|
|
|
<tip>
|
|
|
|
<para>
|
|
|
|
When the <command>VACUUM</command> command's <literal>VERBOSE</literal>
|
|
|
|
parameter is specified, <command>VACUUM</command> prints various
|
|
|
|
statistics about the table. This includes information about how
|
|
|
|
<structfield>relfrozenxid</structfield> and
|
2023-01-25 23:31:41 +01:00
|
|
|
<structfield>relminmxid</structfield> advanced, and the number of
|
|
|
|
newly frozen pages. The same details appear in the server log when
|
|
|
|
autovacuum logging (controlled by <xref
|
2022-04-02 22:34:57 +02:00
|
|
|
linkend="guc-log-autovacuum-min-duration"/>) reports on a
|
|
|
|
<command>VACUUM</command> operation executed by autovacuum.
|
|
|
|
</para>
|
|
|
|
</tip>
|
|
|
|
|
2009-05-17 00:51:24 +02:00
|
|
|
<para>
|
2017-10-09 03:44:17 +02:00
|
|
|
<command>VACUUM</command> normally only scans pages that have been modified
|
|
|
|
since the last vacuum, but <structfield>relfrozenxid</structfield> can only be
|
2016-03-10 22:12:10 +01:00
|
|
|
advanced when every page of the table
|
2016-05-31 19:56:25 +02:00
|
|
|
that might contain unfrozen XIDs is scanned. This happens when
|
2017-10-09 03:44:17 +02:00
|
|
|
<structfield>relfrozenxid</structfield> is more than
|
|
|
|
<varname>vacuum_freeze_table_age</varname> transactions old, when
|
|
|
|
<command>VACUUM</command>'s <literal>FREEZE</literal> option is used, or when all
|
2016-03-10 22:12:10 +01:00
|
|
|
pages that are not already all-frozen happen to
|
2017-10-09 03:44:17 +02:00
|
|
|
require vacuuming to remove dead row versions. When <command>VACUUM</command>
|
2016-03-10 22:12:10 +01:00
|
|
|
scans every page in the table that is not already all-frozen, it should
|
2017-10-09 03:44:17 +02:00
|
|
|
set <literal>age(relfrozenxid)</literal> to a value just a little more than the
|
|
|
|
<varname>vacuum_freeze_min_age</varname> setting
|
2017-06-18 20:01:45 +02:00
|
|
|
that was used (more by the number of transactions started since the
|
2022-04-03 18:57:21 +02:00
|
|
|
<command>VACUUM</command> started). <command>VACUUM</command>
|
|
|
|
will set <structfield>relfrozenxid</structfield> to the oldest XID
|
|
|
|
that remains in the table, so it's possible that the final value
|
|
|
|
will be much more recent than strictly required.
|
|
|
|
If no <structfield>relfrozenxid</structfield>-advancing
|
2017-10-09 03:44:17 +02:00
|
|
|
<command>VACUUM</command> is issued on the table until
|
|
|
|
<varname>autovacuum_freeze_max_age</varname> is reached, an autovacuum will soon
|
2016-03-10 22:12:10 +01:00
|
|
|
be forced for the table.
|
2001-08-26 23:17:12 +02:00
|
|
|
</para>
|
|
|
|
|
|
|
|
<para>
|
2020-06-28 07:05:04 +02:00
|
|
|
If for some reason autovacuum fails to clear old XIDs from a table, the
|
|
|
|
system will begin to emit warning messages like this when the database's
|
2020-08-02 00:31:01 +02:00
|
|
|
oldest XIDs reach forty million transactions from the wraparound point:
|
2002-11-11 21:14:04 +01:00
|
|
|
|
2001-08-26 23:17:12 +02:00
|
|
|
<programlisting>
|
2020-08-02 00:31:01 +02:00
|
|
|
WARNING: database "mydb" must be vacuumed within 39985967 transactions
|
2020-06-28 07:05:04 +02:00
|
|
|
HINT: To avoid a database shutdown, execute a database-wide VACUUM in that database.
|
2001-08-26 23:17:12 +02:00
|
|
|
</programlisting>
|
|
|
|
|
2017-10-09 03:44:17 +02:00
|
|
|
(A manual <command>VACUUM</command> should fix the problem, as suggested by the
|
|
|
|
hint; but note that the <command>VACUUM</command> must be performed by a
|
2008-12-11 19:16:18 +01:00
|
|
|
superuser, else it will fail to process system catalogs and thus not
|
2017-10-09 03:44:17 +02:00
|
|
|
be able to advance the database's <structfield>datfrozenxid</structfield>.)
|
Fix recently-understood problems with handling of XID freezing, particularly
in PITR scenarios. We now WAL-log the replacement of old XIDs with
FrozenTransactionId, so that such replacement is guaranteed to propagate to
PITR slave databases. Also, rather than relying on hint-bit updates to be
preserved, pg_clog is not truncated until all instances of an XID are known to
have been replaced by FrozenTransactionId. Add new GUC variables and
pg_autovacuum columns to allow management of the freezing policy, so that
users can trade off the size of pg_clog against the amount of freezing work
done. Revise the already-existing code that forces autovacuum of tables
approaching the wraparound point to make it more bulletproof; also, revise the
autovacuum logic so that anti-wraparound vacuuming is done per-table rather
than per-database. initdb forced because of changes in pg_class, pg_database,
and pg_autovacuum catalogs. Heikki Linnakangas, Simon Riggs, and Tom Lane.
2006-11-05 23:42:10 +01:00
|
|
|
If these warnings are
|
2010-02-03 18:25:06 +01:00
|
|
|
ignored, the system will shut down and refuse to start any new
|
2020-08-02 00:31:01 +02:00
|
|
|
transactions once there are fewer than three million transactions left
|
2005-02-20 03:22:07 +01:00
|
|
|
until wraparound:
|
|
|
|
|
|
|
|
<programlisting>
|
2007-09-14 04:43:18 +02:00
|
|
|
ERROR: database is not accepting commands to avoid wraparound data loss in database "mydb"
|
2013-06-21 05:03:18 +02:00
|
|
|
HINT: Stop the postmaster and vacuum that database in single-user mode.
|
2005-02-20 03:22:07 +01:00
|
|
|
</programlisting>
|
|
|
|
|
2020-08-02 00:31:01 +02:00
|
|
|
The three-million-transaction safety margin exists to let the
|
2005-02-20 03:22:07 +01:00
|
|
|
administrator recover without data loss, by manually executing the
|
2017-10-09 03:44:17 +02:00
|
|
|
required <command>VACUUM</command> commands. However, since the system will not
|
2005-02-20 03:22:07 +01:00
|
|
|
execute commands once it has gone into the safety shutdown mode,
|
2013-06-21 05:03:18 +02:00
|
|
|
the only way to do this is to stop the server and start the server in single-user
|
2017-10-09 03:44:17 +02:00
|
|
|
mode to execute <command>VACUUM</command>. The shutdown mode is not enforced
|
2017-11-23 15:39:47 +01:00
|
|
|
in single-user mode. See the <xref linkend="app-postgres"/> reference
|
2013-06-21 05:03:18 +02:00
|
|
|
page for details about using single-user mode.
|
2005-02-20 03:22:07 +01:00
|
|
|
</para>
|
|
|
|
|
Separate multixact freezing parameters from xid's
Previously we were piggybacking on transaction ID parameters to freeze
multixacts; but since there isn't necessarily any relationship between
rates of Xid and multixact consumption, this turns out not to be a good
idea.
Therefore, we now have multixact-specific freezing parameters:
vacuum_multixact_freeze_min_age: when to remove multis as we come across
them in vacuum (default to 5 million, i.e. early in comparison to Xid's
default of 50 million)
vacuum_multixact_freeze_table_age: when to force whole-table scans
instead of scanning only the pages marked as not all visible in
visibility map (default to 150 million, same as for Xids). Whichever of
both which reaches the 150 million mark earlier will cause a whole-table
scan.
autovacuum_multixact_freeze_max_age: when for cause emergency,
uninterruptible whole-table scans (default to 400 million, double as
that for Xids). This means there shouldn't be more frequent emergency
vacuuming than previously, unless multixacts are being used very
rapidly.
Backpatch to 9.3 where multixacts were made to persist enough to require
freezing. To avoid an ABI break in 9.3, VacuumStmt has a couple of
fields in an unnatural place, and StdRdOptions is split in two so that
the newly added fields can go at the end.
Patch by me, reviewed by Robert Haas, with additional input from Andres
Freund and Tom Lane.
2014-02-13 23:30:30 +01:00
|
|
|
<sect3 id="vacuum-for-multixact-wraparound">
|
|
|
|
<title>Multixacts and Wraparound</title>
|
|
|
|
|
|
|
|
<indexterm>
|
|
|
|
<primary>MultiXactId</primary>
|
|
|
|
</indexterm>
|
|
|
|
|
|
|
|
<indexterm>
|
|
|
|
<primary>wraparound</primary>
|
|
|
|
<secondary>of multixact IDs</secondary>
|
|
|
|
</indexterm>
|
|
|
|
|
|
|
|
<para>
|
2017-10-09 03:44:17 +02:00
|
|
|
<firstterm>Multixact IDs</firstterm> are used to support row locking by
|
2014-02-17 18:20:57 +01:00
|
|
|
multiple transactions. Since there is only limited space in a tuple
|
|
|
|
header to store lock information, that information is encoded as
|
2017-10-09 03:44:17 +02:00
|
|
|
a <quote>multiple transaction ID</quote>, or multixact ID for short,
|
2014-02-17 18:20:57 +01:00
|
|
|
whenever there is more than one transaction concurrently locking a
|
|
|
|
row. Information about which transaction IDs are included in any
|
|
|
|
particular multixact ID is stored separately in
|
2017-10-09 03:44:17 +02:00
|
|
|
the <filename>pg_multixact</filename> subdirectory, and only the multixact ID
|
|
|
|
appears in the <structfield>xmax</structfield> field in the tuple header.
|
2014-02-17 18:20:57 +01:00
|
|
|
Like transaction IDs, multixact IDs are implemented as a
|
Separate multixact freezing parameters from xid's
Previously we were piggybacking on transaction ID parameters to freeze
multixacts; but since there isn't necessarily any relationship between
rates of Xid and multixact consumption, this turns out not to be a good
idea.
Therefore, we now have multixact-specific freezing parameters:
vacuum_multixact_freeze_min_age: when to remove multis as we come across
them in vacuum (default to 5 million, i.e. early in comparison to Xid's
default of 50 million)
vacuum_multixact_freeze_table_age: when to force whole-table scans
instead of scanning only the pages marked as not all visible in
visibility map (default to 150 million, same as for Xids). Whichever of
both which reaches the 150 million mark earlier will cause a whole-table
scan.
autovacuum_multixact_freeze_max_age: when for cause emergency,
uninterruptible whole-table scans (default to 400 million, double as
that for Xids). This means there shouldn't be more frequent emergency
vacuuming than previously, unless multixacts are being used very
rapidly.
Backpatch to 9.3 where multixacts were made to persist enough to require
freezing. To avoid an ABI break in 9.3, VacuumStmt has a couple of
fields in an unnatural place, and StdRdOptions is split in two so that
the newly added fields can go at the end.
Patch by me, reviewed by Robert Haas, with additional input from Andres
Freund and Tom Lane.
2014-02-13 23:30:30 +01:00
|
|
|
32-bit counter and corresponding storage, all of which requires
|
|
|
|
careful aging management, storage cleanup, and wraparound handling.
|
2015-05-08 18:09:14 +02:00
|
|
|
There is a separate storage area which holds the list of members in
|
|
|
|
each multixact, which also uses a 32-bit counter and which must also
|
|
|
|
be managed.
|
Separate multixact freezing parameters from xid's
Previously we were piggybacking on transaction ID parameters to freeze
multixacts; but since there isn't necessarily any relationship between
rates of Xid and multixact consumption, this turns out not to be a good
idea.
Therefore, we now have multixact-specific freezing parameters:
vacuum_multixact_freeze_min_age: when to remove multis as we come across
them in vacuum (default to 5 million, i.e. early in comparison to Xid's
default of 50 million)
vacuum_multixact_freeze_table_age: when to force whole-table scans
instead of scanning only the pages marked as not all visible in
visibility map (default to 150 million, same as for Xids). Whichever of
both which reaches the 150 million mark earlier will cause a whole-table
scan.
autovacuum_multixact_freeze_max_age: when for cause emergency,
uninterruptible whole-table scans (default to 400 million, double as
that for Xids). This means there shouldn't be more frequent emergency
vacuuming than previously, unless multixacts are being used very
rapidly.
Backpatch to 9.3 where multixacts were made to persist enough to require
freezing. To avoid an ABI break in 9.3, VacuumStmt has a couple of
fields in an unnatural place, and StdRdOptions is split in two so that
the newly added fields can go at the end.
Patch by me, reviewed by Robert Haas, with additional input from Andres
Freund and Tom Lane.
2014-02-13 23:30:30 +01:00
|
|
|
</para>
|
|
|
|
|
|
|
|
<para>
|
2017-10-09 03:44:17 +02:00
|
|
|
Whenever <command>VACUUM</command> scans any part of a table, it will replace
|
2016-03-10 22:12:10 +01:00
|
|
|
any multixact ID it encounters which is older than
|
2017-11-23 15:39:47 +01:00
|
|
|
<xref linkend="guc-vacuum-multixact-freeze-min-age"/>
|
2016-03-10 22:12:10 +01:00
|
|
|
by a different value, which can be the zero value, a single
|
Separate multixact freezing parameters from xid's
Previously we were piggybacking on transaction ID parameters to freeze
multixacts; but since there isn't necessarily any relationship between
rates of Xid and multixact consumption, this turns out not to be a good
idea.
Therefore, we now have multixact-specific freezing parameters:
vacuum_multixact_freeze_min_age: when to remove multis as we come across
them in vacuum (default to 5 million, i.e. early in comparison to Xid's
default of 50 million)
vacuum_multixact_freeze_table_age: when to force whole-table scans
instead of scanning only the pages marked as not all visible in
visibility map (default to 150 million, same as for Xids). Whichever of
both which reaches the 150 million mark earlier will cause a whole-table
scan.
autovacuum_multixact_freeze_max_age: when for cause emergency,
uninterruptible whole-table scans (default to 400 million, double as
that for Xids). This means there shouldn't be more frequent emergency
vacuuming than previously, unless multixacts are being used very
rapidly.
Backpatch to 9.3 where multixacts were made to persist enough to require
freezing. To avoid an ABI break in 9.3, VacuumStmt has a couple of
fields in an unnatural place, and StdRdOptions is split in two so that
the newly added fields can go at the end.
Patch by me, reviewed by Robert Haas, with additional input from Andres
Freund and Tom Lane.
2014-02-13 23:30:30 +01:00
|
|
|
transaction ID, or a newer multixact ID. For each table,
|
2017-10-09 03:44:17 +02:00
|
|
|
<structname>pg_class</structname>.<structfield>relminmxid</structfield> stores the oldest
|
2014-02-17 18:20:57 +01:00
|
|
|
possible multixact ID still appearing in any tuple of that table.
|
|
|
|
If this value is older than
|
2017-11-23 15:39:47 +01:00
|
|
|
<xref linkend="guc-vacuum-multixact-freeze-table-age"/>, an aggressive
|
2016-03-10 22:12:10 +01:00
|
|
|
vacuum is forced. As discussed in the previous section, an aggressive
|
|
|
|
vacuum means that only those pages which are known to be all-frozen will
|
2017-10-09 03:44:17 +02:00
|
|
|
be skipped. <function>mxid_age()</function> can be used on
|
|
|
|
<structname>pg_class</structname>.<structfield>relminmxid</structfield> to find its age.
|
2014-09-10 23:13:04 +02:00
|
|
|
</para>
|
|
|
|
|
|
|
|
<para>
|
2022-04-02 21:29:35 +02:00
|
|
|
Aggressive <command>VACUUM</command>s, regardless of what causes
|
|
|
|
them, are <emphasis>guaranteed</emphasis> to be able to advance
|
|
|
|
the table's <structfield>relminmxid</structfield>.
|
Separate multixact freezing parameters from xid's
Previously we were piggybacking on transaction ID parameters to freeze
multixacts; but since there isn't necessarily any relationship between
rates of Xid and multixact consumption, this turns out not to be a good
idea.
Therefore, we now have multixact-specific freezing parameters:
vacuum_multixact_freeze_min_age: when to remove multis as we come across
them in vacuum (default to 5 million, i.e. early in comparison to Xid's
default of 50 million)
vacuum_multixact_freeze_table_age: when to force whole-table scans
instead of scanning only the pages marked as not all visible in
visibility map (default to 150 million, same as for Xids). Whichever of
both which reaches the 150 million mark earlier will cause a whole-table
scan.
autovacuum_multixact_freeze_max_age: when for cause emergency,
uninterruptible whole-table scans (default to 400 million, double as
that for Xids). This means there shouldn't be more frequent emergency
vacuuming than previously, unless multixacts are being used very
rapidly.
Backpatch to 9.3 where multixacts were made to persist enough to require
freezing. To avoid an ABI break in 9.3, VacuumStmt has a couple of
fields in an unnatural place, and StdRdOptions is split in two so that
the newly added fields can go at the end.
Patch by me, reviewed by Robert Haas, with additional input from Andres
Freund and Tom Lane.
2014-02-13 23:30:30 +01:00
|
|
|
Eventually, as all tables in all databases are scanned and their
|
|
|
|
oldest multixact values are advanced, on-disk storage for older
|
|
|
|
multixacts can be removed.
|
|
|
|
</para>
|
|
|
|
|
|
|
|
<para>
|
2021-07-03 00:00:30 +02:00
|
|
|
As a safety device, an aggressive vacuum scan will
|
2022-04-02 18:49:08 +02:00
|
|
|
occur for any table whose multixact-age is greater than <xref
|
2021-07-03 00:00:30 +02:00
|
|
|
linkend="guc-autovacuum-multixact-freeze-max-age"/>. Also, if the
|
|
|
|
storage occupied by multixacts members exceeds 2GB, aggressive vacuum
|
|
|
|
scans will occur more often for all tables, starting with those that
|
|
|
|
have the oldest multixact-age. Both of these kinds of aggressive
|
|
|
|
scans will occur even if autovacuum is nominally disabled.
|
Separate multixact freezing parameters from xid's
Previously we were piggybacking on transaction ID parameters to freeze
multixacts; but since there isn't necessarily any relationship between
rates of Xid and multixact consumption, this turns out not to be a good
idea.
Therefore, we now have multixact-specific freezing parameters:
vacuum_multixact_freeze_min_age: when to remove multis as we come across
them in vacuum (default to 5 million, i.e. early in comparison to Xid's
default of 50 million)
vacuum_multixact_freeze_table_age: when to force whole-table scans
instead of scanning only the pages marked as not all visible in
visibility map (default to 150 million, same as for Xids). Whichever of
both which reaches the 150 million mark earlier will cause a whole-table
scan.
autovacuum_multixact_freeze_max_age: when for cause emergency,
uninterruptible whole-table scans (default to 400 million, double as
that for Xids). This means there shouldn't be more frequent emergency
vacuuming than previously, unless multixacts are being used very
rapidly.
Backpatch to 9.3 where multixacts were made to persist enough to require
freezing. To avoid an ABI break in 9.3, VacuumStmt has a couple of
fields in an unnatural place, and StdRdOptions is split in two so that
the newly added fields can go at the end.
Patch by me, reviewed by Robert Haas, with additional input from Andres
Freund and Tom Lane.
2014-02-13 23:30:30 +01:00
|
|
|
</para>
|
|
|
|
</sect3>
|
2001-08-26 23:17:12 +02:00
|
|
|
</sect2>
|
2005-09-13 03:51:18 +02:00
|
|
|
|
2020-06-12 00:19:25 +02:00
|
|
|
<sect2 id="autovacuum">
|
2010-04-03 09:23:02 +02:00
|
|
|
<title>The Autovacuum Daemon</title>
|
2005-09-13 03:51:18 +02:00
|
|
|
|
|
|
|
<indexterm>
|
|
|
|
<primary>autovacuum</primary>
|
|
|
|
<secondary>general information</secondary>
|
|
|
|
</indexterm>
|
|
|
|
<para>
|
2008-06-16 05:13:14 +02:00
|
|
|
<productname>PostgreSQL</productname> has an optional but highly
|
|
|
|
recommended feature called <firstterm>autovacuum</firstterm>,
|
2007-04-16 20:30:04 +02:00
|
|
|
whose purpose is to automate the execution of
|
2021-04-24 03:44:13 +02:00
|
|
|
<command>VACUUM</command> and <command>ANALYZE</command> commands.
|
2007-04-16 20:30:04 +02:00
|
|
|
When enabled, autovacuum checks for
|
2005-09-13 03:51:18 +02:00
|
|
|
tables that have had a large number of inserted, updated or deleted
|
2007-09-24 05:12:23 +02:00
|
|
|
tuples. These checks use the statistics collection facility;
|
2007-04-16 20:30:04 +02:00
|
|
|
therefore, autovacuum cannot be used unless <xref
|
2017-11-23 15:39:47 +01:00
|
|
|
linkend="guc-track-counts"/> is set to <literal>true</literal>.
|
2007-04-16 20:30:04 +02:00
|
|
|
In the default configuration, autovacuuming is enabled and the related
|
2007-01-16 19:26:02 +01:00
|
|
|
configuration parameters are appropriately set.
|
2005-09-13 03:51:18 +02:00
|
|
|
</para>
|
|
|
|
|
|
|
|
<para>
|
2017-10-09 03:44:17 +02:00
|
|
|
The <quote>autovacuum daemon</quote> actually consists of multiple processes.
|
2008-06-16 05:13:14 +02:00
|
|
|
There is a persistent daemon process, called the
|
2007-04-18 22:44:53 +02:00
|
|
|
<firstterm>autovacuum launcher</firstterm>, which is in charge of starting
|
2008-12-08 21:30:58 +01:00
|
|
|
<firstterm>autovacuum worker</firstterm> processes for all databases. The
|
2009-05-17 00:51:24 +02:00
|
|
|
launcher will distribute the work across time, attempting to start one
|
2017-11-23 15:39:47 +01:00
|
|
|
worker within each database every <xref linkend="guc-autovacuum-naptime"/>
|
2017-10-09 03:44:17 +02:00
|
|
|
seconds. (Therefore, if the installation has <replaceable>N</replaceable> databases,
|
2010-02-08 05:33:55 +01:00
|
|
|
a new worker will be launched every
|
2017-10-09 03:44:17 +02:00
|
|
|
<varname>autovacuum_naptime</varname>/<replaceable>N</replaceable> seconds.)
|
2017-11-23 15:39:47 +01:00
|
|
|
A maximum of <xref linkend="guc-autovacuum-max-workers"/> worker processes
|
2010-02-08 05:33:55 +01:00
|
|
|
are allowed to run at the same time. If there are more than
|
2017-10-09 03:44:17 +02:00
|
|
|
<varname>autovacuum_max_workers</varname> databases to be processed,
|
2008-12-08 21:30:58 +01:00
|
|
|
the next database will be processed as soon as the first worker finishes.
|
2009-05-17 00:51:24 +02:00
|
|
|
Each worker process will check each table within its database and
|
2017-10-09 03:44:17 +02:00
|
|
|
execute <command>VACUUM</command> and/or <command>ANALYZE</command> as needed.
|
2017-11-23 15:39:47 +01:00
|
|
|
<xref linkend="guc-log-autovacuum-min-duration"/> can be set to monitor
|
2015-11-11 23:13:38 +01:00
|
|
|
autovacuum workers' activity.
|
2007-04-16 20:30:04 +02:00
|
|
|
</para>
|
|
|
|
|
|
|
|
<para>
|
2010-02-08 05:33:55 +01:00
|
|
|
If several large tables all become eligible for vacuuming in a short
|
|
|
|
amount of time, all autovacuum workers might become occupied with
|
|
|
|
vacuuming those tables for a long period. This would result
|
2015-11-11 23:13:38 +01:00
|
|
|
in other tables and databases not being vacuumed until a worker becomes
|
2010-02-03 18:25:06 +01:00
|
|
|
available. There is no limit on how many workers might be in a
|
2007-09-24 05:12:23 +02:00
|
|
|
single database, but workers do try to avoid repeating work that has
|
2007-07-23 19:22:00 +02:00
|
|
|
already been done by other workers. Note that the number of running
|
2017-11-23 15:39:47 +01:00
|
|
|
workers does not count towards <xref linkend="guc-max-connections"/> or
|
|
|
|
<xref linkend="guc-superuser-reserved-connections"/> limits.
|
2007-04-16 20:30:04 +02:00
|
|
|
</para>
|
|
|
|
|
2005-09-13 03:51:18 +02:00
|
|
|
<para>
|
2017-10-09 03:44:17 +02:00
|
|
|
Tables whose <structfield>relfrozenxid</structfield> value is more than
|
2017-11-23 15:39:47 +01:00
|
|
|
<xref linkend="guc-autovacuum-freeze-max-age"/> transactions old are always
|
2009-02-09 21:57:59 +01:00
|
|
|
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
|
2005-09-13 03:51:18 +02:00
|
|
|
<command>VACUUM</command> exceeds the <quote>vacuum threshold</quote>, the
|
2005-10-21 21:39:08 +02:00
|
|
|
table is vacuumed. The vacuum threshold is defined as:
|
2005-09-13 03:51:18 +02:00
|
|
|
<programlisting>
|
|
|
|
vacuum threshold = vacuum base threshold + vacuum scale factor * number of tuples
|
|
|
|
</programlisting>
|
|
|
|
where the vacuum base threshold is
|
2017-11-23 15:39:47 +01:00
|
|
|
<xref linkend="guc-autovacuum-vacuum-threshold"/>,
|
2005-09-13 03:51:18 +02:00
|
|
|
the vacuum scale factor is
|
2017-11-23 15:39:47 +01:00
|
|
|
<xref linkend="guc-autovacuum-vacuum-scale-factor"/>,
|
2005-09-13 03:51:18 +02:00
|
|
|
and the number of tuples is
|
|
|
|
<structname>pg_class</structname>.<structfield>reltuples</structfield>.
|
Trigger autovacuum based on number of INSERTs
Traditionally autovacuum has only ever invoked a worker based on the
estimated number of dead tuples in a table and for anti-wraparound
purposes. For the latter, with certain classes of tables such as
insert-only tables, anti-wraparound vacuums could be the first vacuum that
the table ever receives. This could often lead to autovacuum workers being
busy for extended periods of time due to having to potentially freeze
every page in the table. This could be particularly bad for very large
tables. New clusters, or recently pg_restored clusters could suffer even
more as many large tables may have the same relfrozenxid, which could
result in large numbers of tables requiring an anti-wraparound vacuum all
at once.
Here we aim to reduce the work required by anti-wraparound and aggressive
vacuums in general, by triggering autovacuum when the table has received
enough INSERTs. This is controlled by adding two new GUCs and reloptions;
autovacuum_vacuum_insert_threshold and
autovacuum_vacuum_insert_scale_factor. These work exactly the same as the
existing scale factor and threshold controls, only base themselves off the
number of inserts since the last vacuum, rather than the number of dead
tuples. New controls were added rather than reusing the existing
controls, to allow these new vacuums to be tuned independently and perhaps
even completely disabled altogether, which can be done by setting
autovacuum_vacuum_insert_threshold to -1.
We make no attempt to skip index cleanup operations on these vacuums as
they may trigger for an insert-mostly table which continually doesn't have
enough dead tuples to trigger an autovacuum for the purpose of removing
those dead tuples. If we were to skip cleaning the indexes in this case,
then it is possible for the index(es) to become bloated over time.
There are additional benefits to triggering autovacuums based on inserts,
as tables which never contain enough dead tuples to trigger an autovacuum
are now more likely to receive a vacuum, which can mark more of the table
as "allvisible" and encourage the query planner to make use of Index Only
Scans.
Currently, we still obey vacuum_freeze_min_age when triggering these new
autovacuums based on INSERTs. For large insert-only tables, it may be
beneficial to lower the table's autovacuum_freeze_min_age so that tuples
are eligible to be frozen sooner. Here we've opted not to zero that for
these types of vacuums, since the table may just be insert-mostly and we
may otherwise freeze tuples that are still destined to be updated or
removed in the near future.
There was some debate to what exactly the new scale factor and threshold
should default to. For now, these are set to 0.2 and 1000, respectively.
There may be some motivation to adjust these before the release.
Author: Laurenz Albe, Darafei Praliaskouski
Reviewed-by: Alvaro Herrera, Masahiko Sawada, Chris Travers, Andres Freund, Justin Pryzby
Discussion: https://postgr.es/m/CAC8Q8t%2Bj36G_bLF%3D%2B0iMo6jGNWnLnWb1tujXuJr-%2Bx8ZCCTqoQ%40mail.gmail.com
2020-03-28 07:20:12 +01:00
|
|
|
</para>
|
|
|
|
|
|
|
|
<para>
|
|
|
|
The table is also vacuumed if the number of tuples inserted since the last
|
|
|
|
vacuum has exceeded the defined insert threshold, which is defined as:
|
|
|
|
<programlisting>
|
|
|
|
vacuum insert threshold = vacuum base insert threshold + vacuum insert scale factor * number of tuples
|
|
|
|
</programlisting>
|
|
|
|
where the vacuum insert base threshold is
|
|
|
|
<xref linkend="guc-autovacuum-vacuum-insert-threshold"/>,
|
|
|
|
and vacuum insert scale factor is
|
|
|
|
<xref linkend="guc-autovacuum-vacuum-insert-scale-factor"/>.
|
|
|
|
Such vacuums may allow portions of the table to be marked as
|
|
|
|
<firstterm>all visible</firstterm> and also allow tuples to be frozen, which
|
|
|
|
can reduce the work required in subsequent vacuums.
|
|
|
|
For tables which receive <command>INSERT</command> operations but no or
|
|
|
|
almost no <command>UPDATE</command>/<command>DELETE</command> operations,
|
|
|
|
it may be beneficial to lower the table's
|
2023-01-26 07:22:27 +01:00
|
|
|
<xref linkend="reloption-autovacuum-freeze-min-age"/> as this may allow
|
|
|
|
tuples to be frozen by earlier vacuums. The number of obsolete tuples and
|
2022-04-08 06:35:35 +02:00
|
|
|
the number of inserted tuples are obtained from the cumulative statistics system;
|
Trigger autovacuum based on number of INSERTs
Traditionally autovacuum has only ever invoked a worker based on the
estimated number of dead tuples in a table and for anti-wraparound
purposes. For the latter, with certain classes of tables such as
insert-only tables, anti-wraparound vacuums could be the first vacuum that
the table ever receives. This could often lead to autovacuum workers being
busy for extended periods of time due to having to potentially freeze
every page in the table. This could be particularly bad for very large
tables. New clusters, or recently pg_restored clusters could suffer even
more as many large tables may have the same relfrozenxid, which could
result in large numbers of tables requiring an anti-wraparound vacuum all
at once.
Here we aim to reduce the work required by anti-wraparound and aggressive
vacuums in general, by triggering autovacuum when the table has received
enough INSERTs. This is controlled by adding two new GUCs and reloptions;
autovacuum_vacuum_insert_threshold and
autovacuum_vacuum_insert_scale_factor. These work exactly the same as the
existing scale factor and threshold controls, only base themselves off the
number of inserts since the last vacuum, rather than the number of dead
tuples. New controls were added rather than reusing the existing
controls, to allow these new vacuums to be tuned independently and perhaps
even completely disabled altogether, which can be done by setting
autovacuum_vacuum_insert_threshold to -1.
We make no attempt to skip index cleanup operations on these vacuums as
they may trigger for an insert-mostly table which continually doesn't have
enough dead tuples to trigger an autovacuum for the purpose of removing
those dead tuples. If we were to skip cleaning the indexes in this case,
then it is possible for the index(es) to become bloated over time.
There are additional benefits to triggering autovacuums based on inserts,
as tables which never contain enough dead tuples to trigger an autovacuum
are now more likely to receive a vacuum, which can mark more of the table
as "allvisible" and encourage the query planner to make use of Index Only
Scans.
Currently, we still obey vacuum_freeze_min_age when triggering these new
autovacuums based on INSERTs. For large insert-only tables, it may be
beneficial to lower the table's autovacuum_freeze_min_age so that tuples
are eligible to be frozen sooner. Here we've opted not to zero that for
these types of vacuums, since the table may just be insert-mostly and we
may otherwise freeze tuples that are still destined to be updated or
removed in the near future.
There was some debate to what exactly the new scale factor and threshold
should default to. For now, these are set to 0.2 and 1000, respectively.
There may be some motivation to adjust these before the release.
Author: Laurenz Albe, Darafei Praliaskouski
Reviewed-by: Alvaro Herrera, Masahiko Sawada, Chris Travers, Andres Freund, Justin Pryzby
Discussion: https://postgr.es/m/CAC8Q8t%2Bj36G_bLF%3D%2B0iMo6jGNWnLnWb1tujXuJr-%2Bx8ZCCTqoQ%40mail.gmail.com
2020-03-28 07:20:12 +01:00
|
|
|
it is a semi-accurate count updated by each <command>UPDATE</command>,
|
|
|
|
<command>DELETE</command> and <command>INSERT</command> operation. (It is
|
|
|
|
only semi-accurate because some information might be lost under heavy
|
|
|
|
load.) If the <structfield>relfrozenxid</structfield> value of the table
|
|
|
|
is more than <varname>vacuum_freeze_table_age</varname> transactions old,
|
|
|
|
an aggressive vacuum is performed to freeze old tuples and advance
|
2017-10-09 03:44:17 +02:00
|
|
|
<structfield>relfrozenxid</structfield>; otherwise, only pages that have been modified
|
2009-05-17 00:51:24 +02:00
|
|
|
since the last vacuum are scanned.
|
2008-06-16 05:13:14 +02:00
|
|
|
</para>
|
|
|
|
|
|
|
|
<para>
|
|
|
|
For analyze, a similar condition is used: the threshold, defined as:
|
2005-10-21 21:39:08 +02:00
|
|
|
<programlisting>
|
|
|
|
analyze threshold = analyze base threshold + analyze scale factor * number of tuples
|
|
|
|
</programlisting>
|
2010-09-21 22:40:41 +02:00
|
|
|
is compared to the total number of tuples inserted, updated, or deleted
|
2005-10-21 21:39:08 +02:00
|
|
|
since the last <command>ANALYZE</command>.
|
2005-09-13 03:51:18 +02:00
|
|
|
</para>
|
|
|
|
|
2022-03-28 14:27:36 +02:00
|
|
|
<para>
|
|
|
|
Partitioned tables are not processed by autovacuum. Statistics
|
|
|
|
should be collected by running a manual <command>ANALYZE</command> when it is
|
|
|
|
first populated, and again whenever the distribution of data in its
|
|
|
|
partitions changes significantly.
|
|
|
|
</para>
|
|
|
|
|
2010-04-16 04:22:33 +02:00
|
|
|
<para>
|
|
|
|
Temporary tables cannot be accessed by autovacuum. Therefore,
|
|
|
|
appropriate vacuum and analyze operations should be performed via
|
|
|
|
session SQL commands.
|
|
|
|
</para>
|
|
|
|
|
2005-09-13 03:51:18 +02:00
|
|
|
<para>
|
2005-10-21 21:39:08 +02:00
|
|
|
The default thresholds and scale factors are taken from
|
|
|
|
<filename>postgresql.conf</filename>, but it is possible to override them
|
2015-11-11 23:13:38 +01:00
|
|
|
(and many other autovacuum control parameters) on a per-table basis; see
|
Doc: fix "Unresolved ID reference" warnings, clean up man page cross-refs.
Use xreflabel attributes instead of endterm attributes to control the
appearance of links to subsections of SQL command reference pages.
This is simpler, it matches what we do elsewhere (e.g. for GUC variables),
and it doesn't draw "Unresolved ID reference" warnings from the PDF
toolchain.
Fix some places where the text was absolutely dependent on an <xref>
rendering exactly so, by using a <link> around the required text
instead. At least one of those spots had already been turned into
bad grammar by subsequent changes, and the whole idea is just too
fragile for my taste. <xref> does NOT have fixed output, don't write
as if it does.
Consistently include a page-level link in cross-man-page references,
because otherwise they are useless/nonsensical in man-page output.
Likewise, be consistent about mentioning "below" or "above" in same-page
references; we were doing that in about 90% of the cases, but now it's
100%.
Also get rid of another nonfunctional-in-PDF idea, of making
cross-references to functions by sticking ID tags on <row> constructs.
We can put the IDs on <indexterm>s instead --- which is probably not any
more sensible in abstract terms, but it works where the other doesn't.
(There is talk of attaching cross-reference IDs to most or all of
the docs' function descriptions, but for now I just fixed the two
that exist.)
Discussion: https://postgr.es/m/14480.1589154358@sss.pgh.pa.us
2020-05-11 20:15:49 +02:00
|
|
|
<xref linkend="sql-createtable-storage-parameters"/> for more information.
|
2015-11-11 23:13:38 +01:00
|
|
|
If a setting has been changed via a table's storage parameters, that value
|
|
|
|
is used when processing that table; otherwise the global settings are
|
2017-11-23 15:39:47 +01:00
|
|
|
used. See <xref linkend="runtime-config-autovacuum"/> for more details on
|
2015-11-11 23:13:38 +01:00
|
|
|
the global settings.
|
|
|
|
</para>
|
|
|
|
|
|
|
|
<para>
|
|
|
|
When multiple workers are running, the autovacuum cost delay parameters
|
2017-11-23 15:39:47 +01:00
|
|
|
(see <xref linkend="runtime-config-resource-vacuum-cost"/>) are
|
2007-05-15 17:52:40 +02:00
|
|
|
<quote>balanced</quote> among all the running workers, so that the
|
Don't balance vacuum cost delay when per-table settings are in effect
When there are cost-delay-related storage options set for a table,
trying to make that table participate in the autovacuum cost-limit
balancing algorithm produces undesirable results: instead of using the
configured values, the global values are always used,
as illustrated by Mark Kirkwood in
http://www.postgresql.org/message-id/52FACF15.8020507@catalyst.net.nz
Since the mechanism is already complicated, just disable it for those
cases rather than trying to make it cope. There are undesirable
side-effects from this too, namely that the total I/O impact on the
system will be higher whenever such tables are vacuumed. However, this
is seen as less harmful than slowing down vacuum, because that would
cause bloat to accumulate. Anyway, in the new system it is possible to
tweak options to get the precise behavior one wants, whereas with the
previous system one was simply hosed.
This has been broken forever, so backpatch to all supported branches.
This might affect systems where cost_limit and cost_delay have been set
for individual tables.
2014-10-03 18:01:27 +02:00
|
|
|
total I/O impact on the system is the same regardless of the number
|
|
|
|
of workers actually running. However, any workers processing tables whose
|
2017-10-09 03:44:17 +02:00
|
|
|
per-table <literal>autovacuum_vacuum_cost_delay</literal> or
|
|
|
|
<literal>autovacuum_vacuum_cost_limit</literal> storage parameters have been set
|
2015-11-11 23:13:38 +01:00
|
|
|
are not considered in the balancing algorithm.
|
2007-04-16 20:30:04 +02:00
|
|
|
</para>
|
2019-09-19 04:32:12 +02:00
|
|
|
|
|
|
|
<para>
|
|
|
|
Autovacuum workers generally don't block other commands. If a process
|
2019-09-20 04:08:06 +02:00
|
|
|
attempts to acquire a lock that conflicts with the
|
2019-09-19 04:32:12 +02:00
|
|
|
<literal>SHARE UPDATE EXCLUSIVE</literal> lock held by autovacuum, lock
|
|
|
|
acquisition will interrupt the autovacuum. For conflicting lock modes,
|
|
|
|
see <xref linkend="table-lock-compatibility"/>. However, if the autovacuum
|
|
|
|
is running to prevent transaction ID wraparound (i.e., the autovacuum query
|
|
|
|
name in the <structname>pg_stat_activity</structname> view ends with
|
|
|
|
<literal>(to prevent wraparound)</literal>), the autovacuum is not
|
|
|
|
automatically interrupted.
|
|
|
|
</para>
|
|
|
|
|
|
|
|
<warning>
|
|
|
|
<para>
|
|
|
|
Regularly running commands that acquire locks conflicting with a
|
|
|
|
<literal>SHARE UPDATE EXCLUSIVE</literal> lock (e.g., ANALYZE) can
|
|
|
|
effectively prevent autovacuums from ever completing.
|
|
|
|
</para>
|
|
|
|
</warning>
|
2005-09-13 03:51:18 +02:00
|
|
|
</sect2>
|
2001-08-26 23:17:12 +02:00
|
|
|
</sect1>
|
2001-11-20 05:27:49 +01:00
|
|
|
|
2002-06-13 06:36:50 +02:00
|
|
|
|
2002-06-22 06:08:07 +02:00
|
|
|
<sect1 id="routine-reindex">
|
|
|
|
<title>Routine Reindexing</title>
|
|
|
|
|
|
|
|
<indexterm zone="routine-reindex">
|
|
|
|
<primary>reindex</primary>
|
|
|
|
</indexterm>
|
|
|
|
|
|
|
|
<para>
|
2003-09-13 00:17:24 +02:00
|
|
|
In some situations it is worthwhile to rebuild indexes periodically
|
2017-11-23 15:39:47 +01:00
|
|
|
with the <xref linkend="sql-reindex"/> command or a series of individual
|
2014-01-30 18:14:24 +01:00
|
|
|
rebuilding steps.
|
|
|
|
|
2005-10-21 21:39:08 +02:00
|
|
|
</para>
|
|
|
|
|
|
|
|
<para>
|
2010-02-08 05:33:55 +01:00
|
|
|
B-tree index pages that have become completely empty are reclaimed for
|
|
|
|
re-use. However, there is still a possibility
|
2010-02-03 18:25:06 +01:00
|
|
|
of inefficient use of space: if all but a few index keys on a page have
|
|
|
|
been deleted, the page remains allocated. Therefore, a usage
|
|
|
|
pattern in which most, but not all, keys in each range are eventually
|
|
|
|
deleted will see poor use of space. For such usage patterns,
|
|
|
|
periodic reindexing is recommended.
|
2005-10-21 21:39:08 +02:00
|
|
|
</para>
|
|
|
|
|
|
|
|
<para>
|
2005-11-05 00:14:02 +01:00
|
|
|
The potential for bloat in non-B-tree indexes has not been well
|
2010-02-03 18:25:06 +01:00
|
|
|
researched. It is a good idea to periodically monitor the index's physical
|
2005-11-05 00:14:02 +01:00
|
|
|
size when using any non-B-tree index type.
|
2005-10-21 21:39:08 +02:00
|
|
|
</para>
|
|
|
|
|
|
|
|
<para>
|
2010-02-03 18:25:06 +01:00
|
|
|
Also, for B-tree indexes, a freshly-constructed index is slightly faster to
|
|
|
|
access than one that has been updated many times because logically
|
2005-10-21 21:39:08 +02:00
|
|
|
adjacent pages are usually also physically adjacent in a newly built index.
|
2010-02-03 18:25:06 +01:00
|
|
|
(This consideration does not apply to non-B-tree indexes.) It
|
2005-10-21 21:39:08 +02:00
|
|
|
might be worthwhile to reindex periodically just to improve access speed.
|
2002-06-22 06:08:07 +02:00
|
|
|
</para>
|
2014-01-30 18:14:24 +01:00
|
|
|
|
|
|
|
<para>
|
2017-11-23 15:39:47 +01:00
|
|
|
<xref linkend="sql-reindex"/> can be used safely and easily in all cases.
|
2019-04-27 02:06:39 +02:00
|
|
|
This command requires an <literal>ACCESS EXCLUSIVE</literal> lock by
|
|
|
|
default, hence it is often preferable to execute it with its
|
2019-08-20 05:36:31 +02:00
|
|
|
<literal>CONCURRENTLY</literal> option, which requires only a
|
2019-04-27 02:06:39 +02:00
|
|
|
<literal>SHARE UPDATE EXCLUSIVE</literal> lock.
|
2014-01-30 18:14:24 +01:00
|
|
|
</para>
|
2002-06-22 06:08:07 +02:00
|
|
|
</sect1>
|
|
|
|
|
|
|
|
|
2001-11-20 05:27:49 +01:00
|
|
|
<sect1 id="logfile-maintenance">
|
|
|
|
<title>Log File Maintenance</title>
|
|
|
|
|
|
|
|
<indexterm zone="logfile-maintenance">
|
2003-08-31 19:32:24 +02:00
|
|
|
<primary>server log</primary>
|
|
|
|
<secondary>log file maintenance</secondary>
|
2001-11-20 05:27:49 +01:00
|
|
|
</indexterm>
|
|
|
|
|
|
|
|
<para>
|
2003-12-14 01:10:32 +01:00
|
|
|
It is a good idea to save the database server's log output
|
2017-10-09 03:44:17 +02:00
|
|
|
somewhere, rather than just discarding it via <filename>/dev/null</filename>.
|
2010-02-03 18:25:06 +01:00
|
|
|
The log output is invaluable when diagnosing
|
2022-08-12 18:02:21 +02:00
|
|
|
problems.
|
|
|
|
</para>
|
|
|
|
|
|
|
|
<note>
|
|
|
|
<para>
|
|
|
|
The server log can contain sensitive information and needs to be protected,
|
|
|
|
no matter how or where it is stored, or the destination to which it is routed.
|
|
|
|
For example, some DDL statements might contain plaintext passwords or other
|
|
|
|
authentication details. Logged statements at the <literal>ERROR</literal>
|
|
|
|
level might show the SQL source code for applications
|
|
|
|
and might also contain some parts of data rows. Recording data, events and
|
|
|
|
related information is the intended function of this facility, so this is
|
|
|
|
not a leakage or a bug. Please ensure the server logs are visible only to
|
|
|
|
appropriately authorized people.
|
|
|
|
</para>
|
|
|
|
</note>
|
|
|
|
|
|
|
|
<para>
|
|
|
|
Log output tends to be voluminous
|
2010-02-03 18:25:06 +01:00
|
|
|
(especially at higher debug levels) so you won't want to save it
|
2017-10-09 03:44:17 +02:00
|
|
|
indefinitely. You need to <emphasis>rotate</emphasis> the log files so that
|
2003-12-14 01:10:32 +01:00
|
|
|
new log files are started and old ones removed after a reasonable
|
|
|
|
period of time.
|
2001-11-20 05:27:49 +01:00
|
|
|
</para>
|
|
|
|
|
|
|
|
<para>
|
2017-10-09 03:44:17 +02:00
|
|
|
If you simply direct the <systemitem>stderr</systemitem> of
|
2006-06-18 17:38:37 +02:00
|
|
|
<command>postgres</command> into a
|
2004-08-06 01:32:13 +02:00
|
|
|
file, you will have log output, but
|
|
|
|
the only way to truncate the log file is to stop and restart
|
2010-02-03 18:25:06 +01:00
|
|
|
the server. This might be acceptable if you are using
|
2003-12-14 01:10:32 +01:00
|
|
|
<productname>PostgreSQL</productname> in a development environment,
|
|
|
|
but few production servers would find this behavior acceptable.
|
2001-11-20 05:27:49 +01:00
|
|
|
</para>
|
|
|
|
|
|
|
|
<para>
|
2006-06-18 17:38:37 +02:00
|
|
|
A better approach is to send the server's
|
2017-10-09 03:44:17 +02:00
|
|
|
<systemitem>stderr</systemitem> output to some type of log rotation program.
|
2010-02-03 18:25:06 +01:00
|
|
|
There is a built-in log rotation facility, which you can use by
|
2017-10-09 03:44:17 +02:00
|
|
|
setting the configuration parameter <varname>logging_collector</varname> to
|
|
|
|
<literal>true</literal> in <filename>postgresql.conf</filename>. The control
|
2004-08-06 01:32:13 +02:00
|
|
|
parameters for this program are described in <xref
|
2017-11-23 15:39:47 +01:00
|
|
|
linkend="runtime-config-logging-where"/>. You can also use this approach
|
2017-10-09 03:44:17 +02:00
|
|
|
to capture the log data in machine readable <acronym>CSV</acronym>
|
2010-02-03 18:25:06 +01:00
|
|
|
(comma-separated values) format.
|
2004-08-06 01:32:13 +02:00
|
|
|
</para>
|
|
|
|
|
|
|
|
<para>
|
|
|
|
Alternatively, you might prefer to use an external log rotation
|
2010-02-03 18:25:06 +01:00
|
|
|
program if you have one that you are already using with other
|
2004-08-06 01:32:13 +02:00
|
|
|
server software. For example, the <application>rotatelogs</application>
|
|
|
|
tool included in the <productname>Apache</productname> distribution
|
2018-09-01 18:46:49 +02:00
|
|
|
can be used with <productname>PostgreSQL</productname>. One way to
|
|
|
|
do this is to pipe the server's
|
2017-10-09 03:44:17 +02:00
|
|
|
<systemitem>stderr</systemitem> output to the desired program.
|
2004-08-06 01:32:13 +02:00
|
|
|
If you start the server with
|
2017-10-09 03:44:17 +02:00
|
|
|
<command>pg_ctl</command>, then <systemitem>stderr</systemitem>
|
|
|
|
is already redirected to <systemitem>stdout</systemitem>, so you just need a
|
2004-12-27 23:30:10 +01:00
|
|
|
pipe command, for example:
|
2004-08-06 01:32:13 +02:00
|
|
|
|
|
|
|
<programlisting>
|
|
|
|
pg_ctl start | rotatelogs /var/log/pgsql_log 86400
|
|
|
|
</programlisting>
|
|
|
|
</para>
|
|
|
|
|
2018-09-01 18:46:49 +02:00
|
|
|
<para>
|
|
|
|
You can combine these approaches by setting up <application>logrotate</application>
|
|
|
|
to collect log files produced by <productname>PostgreSQL</productname> built-in
|
|
|
|
logging collector. In this case, the logging collector defines the names and
|
|
|
|
location of the log files, while <application>logrotate</application>
|
|
|
|
periodically archives these files. When initiating log rotation,
|
|
|
|
<application>logrotate</application> must ensure that the application
|
|
|
|
sends further output to the new file. This is commonly done with a
|
|
|
|
<literal>postrotate</literal> script that sends a <literal>SIGHUP</literal>
|
|
|
|
signal to the application, which then reopens the log file.
|
|
|
|
In <productname>PostgreSQL</productname>, you can run <command>pg_ctl</command>
|
|
|
|
with the <literal>logrotate</literal> option instead. When the server receives
|
|
|
|
this command, the server either switches to a new log file or reopens the
|
|
|
|
existing file, depending on the logging configuration
|
|
|
|
(see <xref linkend="runtime-config-logging-where"/>).
|
|
|
|
</para>
|
|
|
|
|
|
|
|
<note>
|
|
|
|
<para>
|
|
|
|
When using static log file names, the server might fail to reopen the log
|
|
|
|
file if the max open file limit is reached or a file table overflow occurs.
|
|
|
|
In this case, log messages are sent to the old log file until a
|
|
|
|
successful log rotation. If <application>logrotate</application> is
|
|
|
|
configured to compress the log file and delete it, the server may lose
|
2020-07-05 15:37:57 +02:00
|
|
|
the messages logged in this time frame. To avoid this issue, you can
|
2018-09-01 18:46:49 +02:00
|
|
|
configure the logging collector to dynamically assign log file names
|
|
|
|
and use a <literal>prerotate</literal> script to ignore open log files.
|
|
|
|
</para>
|
|
|
|
</note>
|
|
|
|
|
2004-08-06 01:32:13 +02:00
|
|
|
<para>
|
|
|
|
Another production-grade approach to managing log output is to
|
2017-10-09 03:44:17 +02:00
|
|
|
send it to <application>syslog</application> and let
|
|
|
|
<application>syslog</application> deal with file rotation. To do this, set the
|
|
|
|
configuration parameter <varname>log_destination</varname> to <literal>syslog</literal>
|
|
|
|
(to log to <application>syslog</application> only) in
|
|
|
|
<filename>postgresql.conf</filename>. Then you can send a <literal>SIGHUP</literal>
|
|
|
|
signal to the <application>syslog</application> daemon whenever you want to force it
|
2004-08-06 01:32:13 +02:00
|
|
|
to start writing a new log file. If you want to automate log
|
2004-05-16 21:34:46 +02:00
|
|
|
rotation, the <application>logrotate</application> program can be
|
2003-11-01 02:56:29 +01:00
|
|
|
configured to work with log files from
|
|
|
|
<application>syslog</application>.
|
2004-03-15 15:15:45 +01:00
|
|
|
</para>
|
2003-10-09 21:05:09 +02:00
|
|
|
|
2004-03-15 15:15:45 +01:00
|
|
|
<para>
|
2017-10-09 03:44:17 +02:00
|
|
|
On many systems, however, <application>syslog</application> is not very reliable,
|
Update documentation on may/can/might:
Standard English uses "may", "can", and "might" in different ways:
may - permission, "You may borrow my rake."
can - ability, "I can lift that log."
might - possibility, "It might rain today."
Unfortunately, in conversational English, their use is often mixed, as
in, "You may use this variable to do X", when in fact, "can" is a better
choice. Similarly, "It may crash" is better stated, "It might crash".
Also update two error messages mentioned in the documenation to match.
2007-01-31 21:56:20 +01:00
|
|
|
particularly with large log messages; it might truncate or drop messages
|
2017-10-09 03:44:17 +02:00
|
|
|
just when you need them the most. Also, on <productname>Linux</productname>,
|
|
|
|
<application>syslog</application> will flush each message to disk, yielding poor
|
|
|
|
performance. (You can use a <quote><literal>-</literal></quote> at the start of the file name
|
|
|
|
in the <application>syslog</application> configuration file to disable syncing.)
|
2001-11-20 05:27:49 +01:00
|
|
|
</para>
|
|
|
|
|
|
|
|
<para>
|
2004-08-06 01:32:13 +02:00
|
|
|
Note that all the solutions described above take care of starting new
|
|
|
|
log files at configurable intervals, but they do not handle deletion
|
2010-02-03 18:25:06 +01:00
|
|
|
of old, no-longer-useful log files. You will probably want to set
|
2004-12-27 23:30:10 +01:00
|
|
|
up a batch job to periodically delete old log files. Another possibility
|
|
|
|
is to configure the rotation program so that old log files are overwritten
|
|
|
|
cyclically.
|
2001-11-20 05:27:49 +01:00
|
|
|
</para>
|
2010-05-27 01:29:45 +02:00
|
|
|
|
|
|
|
<para>
|
2018-12-18 02:02:23 +01:00
|
|
|
<ulink url="https://pgbadger.darold.net/"><productname>pgBadger</productname></ulink>
|
2010-05-27 01:29:45 +02:00
|
|
|
is an external project that does sophisticated log file analysis.
|
|
|
|
<ulink
|
2017-11-02 03:07:14 +01:00
|
|
|
url="https://bucardo.org/check_postgres/"><productname>check_postgres</productname></ulink>
|
2010-05-27 01:29:45 +02:00
|
|
|
provides Nagios alerts when important messages appear in the log
|
|
|
|
files, as well as detection of many other extraordinary conditions.
|
|
|
|
</para>
|
2001-11-20 05:27:49 +01:00
|
|
|
</sect1>
|
2001-08-26 23:17:12 +02:00
|
|
|
</chapter>
|