Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 48188e1

Browse files
committed
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.
1 parent 10c70b8 commit 48188e1

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+1284
-1062
lines changed

doc/src/sgml/catalogs.sgml

Lines changed: 43 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<!-- $PostgreSQL: pgsql/doc/src/sgml/catalogs.sgml,v 2.135 2006/10/23 18:10:30 petere Exp $ -->
1+
<!-- $PostgreSQL: pgsql/doc/src/sgml/catalogs.sgml,v 2.136 2006/11/05 22:42:06 tgl Exp $ -->
22
<!--
33
Documentation of the system catalogs, directed toward PostgreSQL developers
44
-->
@@ -1241,6 +1241,20 @@
12411241
<entry></entry>
12421242
<entry>Custom <varname>vacuum_cost_limit</> parameter</entry>
12431243
</row>
1244+
1245+
<row>
1246+
<entry><structfield>freeze_min_age</structfield></entry>
1247+
<entry><type>integer</type></entry>
1248+
<entry></entry>
1249+
<entry>Custom <varname>vacuum_freeze_min_age</> parameter</entry>
1250+
</row>
1251+
1252+
<row>
1253+
<entry><structfield>freeze_max_age</structfield></entry>
1254+
<entry><type>integer</type></entry>
1255+
<entry></entry>
1256+
<entry>Custom <varname>autovacuum_freeze_max_age</> parameter</entry>
1257+
</row>
12441258
</tbody>
12451259
</tgroup>
12461260
</table>
@@ -1258,6 +1272,17 @@
12581272
live tuples currently estimated to be in the relation.
12591273
</para>
12601274

1275+
<para>
1276+
Also, the autovacuum daemon will perform a <command>VACUUM</> operation
1277+
to prevent transaction ID wraparound if the table's
1278+
<structname>pg_class</>.<structfield>relfrozenxid</> field attains an age
1279+
of more than <structfield>freeze_max_age</> transactions, whether the table
1280+
has been changed or not. The system will launch autovacuum to perform
1281+
such <command>VACUUM</>s even if autovacuum is otherwise disabled.
1282+
See <xref linkend="vacuum-for-wraparound"> for more about wraparound
1283+
prevention.
1284+
</para>
1285+
12611286
<para>
12621287
Any of the numerical fields can contain <literal>-1</> (or indeed
12631288
any negative value) to indicate that the system-wide default should
@@ -1266,6 +1291,10 @@
12661291
<varname>autovacuum_vacuum_cost_delay</> configuration parameter,
12671292
or from <varname>vacuum_cost_delay</> if the former is set to a negative
12681293
value. The same applies to <structfield>vac_cost_limit</>.
1294+
Also, autovacuum will ignore attempts to set a per-table
1295+
freeze_max_age larger than the system-wide setting (it can only be set
1296+
smaller), and the freeze_min_age value will be limited to half the
1297+
system-wide <varname>autovacuum_freeze_max_age</> setting.
12691298
</para>
12701299

12711300
</sect1>
@@ -1633,26 +1662,15 @@
16331662
</row>
16341663

16351664
<row>
1636-
<entry><structfield>relminxid</structfield></entry>
1665+
<entry><structfield>relfrozenxid</structfield></entry>
16371666
<entry><type>xid</type></entry>
16381667
<entry></entry>
16391668
<entry>
1640-
The minimum transaction ID present in all rows in this table. This
1641-
value is used to determine the database-global
1642-
<structname>pg_database</>.<structfield>datminxid</> value.
1643-
</entry>
1644-
</row>
1645-
1646-
<row>
1647-
<entry><structfield>relvacuumxid</structfield></entry>
1648-
<entry><type>xid</type></entry>
1649-
<entry></entry>
1650-
<entry>
1651-
The transaction ID that was used as cleaning point as of the last vacuum
1652-
operation. All rows inserted, updated or deleted in this table by
1653-
transactions whose IDs are below this one have been marked as known good
1654-
or deleted. This is used to determine the database-global
1655-
<structname>pg_database</>.<structfield>datvacuumxid</> value.
1669+
All transaction IDs before this one have been replaced with a permanent
1670+
(<quote>frozen</>) transaction ID in this table. This is used to track
1671+
whether the table needs to be vacuumed in order to prevent transaction
1672+
ID wraparound or to allow <literal>pg_clog</> to be shrunk. Zero
1673+
(<symbol>InvalidTransactionId</symbol>) if the relation is not a table.
16561674
</entry>
16571675
</row>
16581676

@@ -2035,31 +2053,16 @@
20352053
</row>
20362054

20372055
<row>
2038-
<entry><structfield>datvacuumxid</structfield></entry>
2039-
<entry><type>xid</type></entry>
2040-
<entry></entry>
2041-
<entry>
2042-
The transaction ID that was used as cleaning point as of the last vacuum
2043-
operation. All rows inserted or deleted by transaction IDs before this one
2044-
have been marked as known good or deleted. This
2045-
is used to determine when commit-log space can be recycled.
2046-
If <symbol>InvalidTransactionId</symbol>, then the minimum is unknown and can be
2047-
determined by scanning <structname>pg_class</>.<structfield>relvacuumxid</>.
2048-
</entry>
2049-
</row>
2050-
2051-
<row>
2052-
<entry><structfield>datminxid</structfield></entry>
2056+
<entry><structfield>datfrozenxid</structfield></entry>
20532057
<entry><type>xid</type></entry>
20542058
<entry></entry>
20552059
<entry>
2056-
The minimum transaction ID present in all tables in this database.
2057-
All rows inserted by transaction IDs before this one have been
2058-
relabeled with a permanent (<quote>frozen</>) transaction ID in this
2059-
database. This is useful to check whether a database must be
2060-
vacuumed soon to avoid transaction ID wrap-around problems.
2061-
If <symbol>InvalidTransactionId</symbol>, then the minimum is unknown and can be
2062-
determined by scanning <structname>pg_class</>.<structfield>relminxid</>.
2060+
All transaction IDs before this one have been replaced with a permanent
2061+
(<quote>frozen</>) transaction ID in this database. This is used to
2062+
track whether the database needs to be vacuumed in order to prevent
2063+
transaction ID wraparound or to allow <literal>pg_clog</> to be shrunk.
2064+
It is the minimum of the per-table
2065+
<structname>pg_class</>.<structfield>relfrozenxid</> values.
20632066
</entry>
20642067
</row>
20652068

doc/src/sgml/config.sgml

Lines changed: 44 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<!-- $PostgreSQL: pgsql/doc/src/sgml/config.sgml,v 1.93 2006/11/04 18:20:27 tgl Exp $ -->
1+
<!-- $PostgreSQL: pgsql/doc/src/sgml/config.sgml,v 1.94 2006/11/05 22:42:07 tgl Exp $ -->
22

33
<chapter Id="runtime-config">
44
<title>Server Configuration</title>
@@ -3217,6 +3217,28 @@ SELECT * FROM parent WHERE key = 2400;
32173217
</listitem>
32183218
</varlistentry>
32193219

3220+
<varlistentry id="guc-autovacuum-freeze-max-age" xreflabel="autovacuum_freeze_max_age">
3221+
<term><varname>autovacuum_freeze_max_age</varname> (<type>integer</type>)</term>
3222+
<indexterm>
3223+
<primary><varname>autovacuum_freeze_max_age</> configuration parameter</primary>
3224+
</indexterm>
3225+
<listitem>
3226+
<para>
3227+
Specifies the maximum age (in transactions) that a table's
3228+
<structname>pg_class</>.<structfield>relfrozenxid</> field can
3229+
attain before a <command>VACUUM</> operation is forced to prevent
3230+
transaction ID wraparound within the table. Note that the system
3231+
will launch autovacuum processes to prevent wraparound even when
3232+
autovacuum is otherwise disabled.
3233+
The default is 200000000 (200 million).
3234+
This parameter can only be set at server start, but the setting
3235+
can be reduced for individual tables by entries in
3236+
<structname>pg_autovacuum</>.
3237+
For more information see <xref linkend="vacuum-for-wraparound">.
3238+
</para>
3239+
</listitem>
3240+
</varlistentry>
3241+
32203242
<varlistentry id="guc-autovacuum-vacuum-cost-delay" xreflabel="autovacuum_vacuum_cost_delay">
32213243
<term><varname>autovacuum_vacuum_cost_delay</varname> (<type>integer</type>)</term>
32223244
<indexterm>
@@ -3427,7 +3449,7 @@ SELECT * FROM parent WHERE key = 2400;
34273449
</para>
34283450
</listitem>
34293451
</varlistentry>
3430-
3452+
34313453
<varlistentry id="guc-statement-timeout" xreflabel="statement_timeout">
34323454
<term><varname>statement_timeout</varname> (<type>integer</type>)</term>
34333455
<indexterm>
@@ -3444,6 +3466,26 @@ SELECT * FROM parent WHERE key = 2400;
34443466
</para>
34453467
</listitem>
34463468
</varlistentry>
3469+
3470+
<varlistentry id="guc-vacuum-freeze-min-age" xreflabel="vacuum_freeze_min_age">
3471+
<term><varname>vacuum_freeze_min_age</varname> (<type>integer</type>)</term>
3472+
<indexterm>
3473+
<primary><varname>vacuum_freeze_min_age</> configuration parameter</primary>
3474+
</indexterm>
3475+
<listitem>
3476+
<para>
3477+
Specifies the cutoff age (in transactions) that <command>VACUUM</>
3478+
should use to decide whether to replace transaction IDs with
3479+
<literal>FrozenXID</> while scanning a table.
3480+
The default is 100000000 (100 million). Although users can set this
3481+
value anywhere from zero to 1000000000, <command>VACUUM</> will
3482+
silently limit the effective value to half the value of <xref
3483+
linkend="guc-autovacuum-freeze-max-age">, so that there is not an
3484+
unreasonably short time between forced autovacuums.
3485+
For more information see <xref linkend="vacuum-for-wraparound">.
3486+
</para>
3487+
</listitem>
3488+
</varlistentry>
34473489

34483490
</variablelist>
34493491
</sect2>

0 commit comments

Comments
 (0)