|
1 | 1 | <!--
|
2 |
| -$PostgreSQL: pgsql/doc/src/sgml/maintenance.sgml,v 1.45 2005/06/22 21:14:28 tgl Exp $ |
| 2 | +$PostgreSQL: pgsql/doc/src/sgml/maintenance.sgml,v 1.46 2005/09/13 01:51:18 alvherre Exp $ |
3 | 3 | -->
|
4 | 4 |
|
5 | 5 | <chapter id="maintenance">
|
@@ -99,6 +99,12 @@ $PostgreSQL: pgsql/doc/src/sgml/maintenance.sgml,v 1.45 2005/06/22 21:14:28 tgl
|
99 | 99 | <xref linkend="runtime-config-resource-vacuum-cost">.
|
100 | 100 | </para>
|
101 | 101 |
|
| 102 | + <para> |
| 103 | + An automated mechanism for performing the necessary <command>VACUUM</> |
| 104 | + operations has been added in <productname>PostgreSQL</productname> 8.1. |
| 105 | + See <xref linkend="autovacuum">. |
| 106 | + </para> |
| 107 | + |
102 | 108 | <sect2 id="vacuum-for-space-recovery">
|
103 | 109 | <title>Recovering disk space</title>
|
104 | 110 |
|
@@ -177,13 +183,6 @@ $PostgreSQL: pgsql/doc/src/sgml/maintenance.sgml,v 1.45 2005/06/22 21:14:28 tgl
|
177 | 183 | the program <filename>vacuumdb</> may be helpful.
|
178 | 184 | </para>
|
179 | 185 |
|
180 |
| - <tip> |
181 |
| - <para> |
182 |
| - The <filename>contrib/pg_autovacuum</> program can be useful for |
183 |
| - automating high-frequency vacuuming operations. |
184 |
| - </para> |
185 |
| - </tip> |
186 |
| - |
187 | 186 | <para>
|
188 | 187 | <command>VACUUM FULL</> is recommended for cases where you know
|
189 | 188 | you have deleted the majority of rows in a table, so that the
|
@@ -456,6 +455,98 @@ HINT: Stop the postmaster and use a standalone backend to VACUUM in "mydb".
|
456 | 455 | </para>
|
457 | 456 | </warning>
|
458 | 457 | </sect2>
|
| 458 | + |
| 459 | + <sect2 id="autovacuum"> |
| 460 | + <title id="autovacuum-title">The auto-vacuum daemon</title> |
| 461 | + |
| 462 | + <indexterm> |
| 463 | + <primary>autovacuum</primary> |
| 464 | + <secondary>general information</secondary> |
| 465 | + </indexterm> |
| 466 | + <para> |
| 467 | + Beginning in <productname>PostgreSQL </productname> 8.1, there is a |
| 468 | + separate optional server process called the <firstterm>autovacuum |
| 469 | + daemon</firstterm>, whose purpose is to automate the issuance of |
| 470 | + <command>VACUUM</command> and <command>ANALYZE </command> commands. |
| 471 | + When enabled, the autovacuum daemon runs periodically and checks for |
| 472 | + tables that have had a large number of inserted, updated or deleted |
| 473 | + tuples. These checks use the row-level statistics collection facility; |
| 474 | + therefore, the autovacuum daemon cannot be used unless <xref |
| 475 | + linkend="guc-stats-start-collector"> and <xref |
| 476 | + linkend="guc-stats-row-level"> are set <literal>true</literal>. Also, it's |
| 477 | + important to allow a slot for the autovacuum process when choosing the |
| 478 | + value of <xref linkend="guc-superuser-reserved-connections">. |
| 479 | + </para> |
| 480 | + |
| 481 | + <para> |
| 482 | + The autovacuum daemon, when enabled, runs every <xref |
| 483 | + linkend="guc-autovacuum-naptime"> seconds and determines which database |
| 484 | + to process. Any database which is close to transaction ID wraparound |
| 485 | + is immediately processed. In this case, autovacuum issues a |
| 486 | + database-wide <command>VACUUM</command> call, or <command>VACUUM |
| 487 | + FREEZE</command> if it's a template database, and then terminates. If |
| 488 | + no database fulfills this criterion, the one that was least recently |
| 489 | + processed by autovacuum itself is chosen. In this mode, each table in |
| 490 | + the database is checked for new and obsolete tuples, according to the |
| 491 | + applicable autovacuum parameters. If a <link linkend="catalog-pg-autovacuum"> |
| 492 | + <structname>pg_autovacuum</structname></link> tuple is found for this |
| 493 | + table, these settings are applied; otherwise the global values in |
| 494 | + <filename>postgresql.conf</filename> are used. See <xref linkend="runtime-config-autovacuum"> |
| 495 | + for more details on the global settings. |
| 496 | + </para> |
| 497 | + |
| 498 | + <para> |
| 499 | + For each table, two conditions are used to determine which operation to |
| 500 | + apply. If the number of obsolete tuples since the last |
| 501 | + <command>VACUUM</command> exceeds the <quote>vacuum threshold</quote>, the |
| 502 | + table is vacuumed and analyzed. The vacuum threshold is defined as: |
| 503 | +<programlisting> |
| 504 | +vacuum threshold = vacuum base threshold + vacuum scale factor * number of tuples |
| 505 | +</programlisting> |
| 506 | + where the vacuum base threshold is |
| 507 | + <structname>pg_autovacuum</structname>.<structfield>vac_base_thresh</structfield>, |
| 508 | + the vacuum scale factor is |
| 509 | + <structname>pg_autovacuum</structname>.<structfield>vac_scale_factor</structfield> |
| 510 | + and the number of tuples is |
| 511 | + <structname>pg_class</structname>.<structfield>reltuples</structfield>. |
| 512 | + The number of obsolete tuples is taken from the statistics |
| 513 | + collector, which is a semi-accurate count updated by each |
| 514 | + <command>UPDATE</command> and <command>DELETE</command> operation. (It |
| 515 | + is only semi-accurate because some information may be lost under heavy |
| 516 | + load.) For analyze, a similar condition is used: the threshold, calculated |
| 517 | + by an equivalent equation to that above, is compared to the number of |
| 518 | + new tuples, that is, those created by the <command>INSERT</command> and |
| 519 | + <command>COPY</command> commands. |
| 520 | + </para> |
| 521 | + |
| 522 | + <para> |
| 523 | + Note that if any of the values in <structname>pg_autovacuum</structname> |
| 524 | + is set to a negative number, or if a tuple is not present at all in |
| 525 | + <structname>pg_autovacuum</structname> for any particular table, the |
| 526 | + equivalent value from <filename>postgresql.conf</filename> is used. |
| 527 | + </para> |
| 528 | + |
| 529 | + <para> |
| 530 | + Besides the base threshold values and scale factors, there are three |
| 531 | + parameters that can be set for each table in <structname>pg_autovacuum</structname>: |
| 532 | + the vacuum cost delay |
| 533 | + (<structname>pg_autovacuum</structname>.<structfield>vac_cost_delay</structfield>) |
| 534 | + and the vacuum cost limit |
| 535 | + (<structname>pg_autovacuum</structname>.<structfield>vac_cost_limit</structfield>). |
| 536 | + They are used to set table-specific values for the |
| 537 | + <xref linkend="runtime-config-resource-vacuum-cost" endterm="runtime-config-resource-vacuum-cost-title"> |
| 538 | + feature. The above note about negative values also applies here, but |
| 539 | + also note that if the <filename>postgresql.conf</filename> variables |
| 540 | + <varname>autovacuum_vacuum_cost_limit</varname> and |
| 541 | + <varname>autovacuum_vacuum_cost_delay</varname> are also set to negative |
| 542 | + values, the <varname>vacuum_cost_limit</varname> and |
| 543 | + <varname>vacuum_cost_delay</varname> values will be used instead. |
| 544 | + The other parameter, <structname>pg_autovacuum</>.<structfield>enabled</>, |
| 545 | + can be used to instruct the autovacuum daemon to skip any particular table |
| 546 | + by setting it to <literal>false</literal>. |
| 547 | + </para> |
| 548 | + |
| 549 | + </sect2> |
459 | 550 | </sect1>
|
460 | 551 |
|
461 | 552 |
|
|
0 commit comments