|
1 |
| -<!-- $PostgreSQL: pgsql/doc/src/sgml/maintenance.sgml,v 1.78 2007/08/19 01:41:24 adunstan Exp $ --> |
| 1 | +<!-- $PostgreSQL: pgsql/doc/src/sgml/maintenance.sgml,v 1.79 2007/09/13 23:43:35 momjian Exp $ --> |
2 | 2 |
|
3 | 3 | <chapter id="maintenance">
|
4 | 4 | <title>Routine Database Maintenance Tasks</title>
|
|
59 | 59 | </indexterm>
|
60 | 60 |
|
61 | 61 | <para>
|
62 |
| - <productname>PostgreSQL</productname>'s <command>VACUUM</> command |
63 |
| - <emphasis>must</emphasis> be run on a regular basis for several reasons: |
| 62 | + <productname>PostgreSQL</productname>'s <command>VACUUM</> (<xref |
| 63 | + linkend="sql-vacuum"> command has to run on a regular basis for several |
| 64 | + reasons: |
64 | 65 |
|
65 | 66 | <orderedlist>
|
66 | 67 | <listitem>
|
|
78 | 79 | <firstterm>transaction ID wraparound</>.</simpara>
|
79 | 80 | </listitem>
|
80 | 81 | </orderedlist>
|
81 |
| - |
82 |
| - The frequency and scope of the <command>VACUUM</> operations |
83 |
| - performed for each of these reasons will vary depending on the |
84 |
| - needs of each site. Therefore, database administrators must |
85 |
| - understand these issues and develop an appropriate maintenance |
86 |
| - strategy. This section concentrates on explaining the high-level |
87 |
| - issues; for details about command syntax and so on, see the <xref |
88 |
| - linkend="sql-vacuum" endterm="sql-vacuum-title"> reference page. |
89 | 82 | </para>
|
90 | 83 |
|
91 | 84 | <para>
|
|
103 | 96 | </para>
|
104 | 97 |
|
105 | 98 | <para>
|
106 |
| - An automated mechanism for performing the necessary <command>VACUUM</> |
107 |
| - operations has been added in <productname>PostgreSQL</productname> 8.1. |
108 |
| - See <xref linkend="autovacuum">. |
| 99 | + Fortunately, autovacuum (<xref linkend="autovacuum">) monitors table |
| 100 | + activity and performs <command>VACUUM</command>s when necessary. |
| 101 | + Autovacuum works dynamically so it is often better |
| 102 | + administration-scheduled vacuuming. |
109 | 103 | </para>
|
110 | 104 |
|
111 | 105 | <sect2 id="vacuum-for-space-recovery">
|
112 |
| - <title>Recovering disk space</title> |
| 106 | + <title>Recovering Disk Space</title> |
113 | 107 |
|
114 | 108 | <indexterm zone="vacuum-for-space-recovery">
|
115 | 109 | <primary>disk space</primary>
|
|
128 | 122 | space requirements. This is done by running <command>VACUUM</>.
|
129 | 123 | </para>
|
130 | 124 |
|
131 |
| - <para> |
132 |
| - Clearly, a table that receives frequent updates or deletes will need |
133 |
| - to be vacuumed more often than tables that are seldom updated. It |
134 |
| - might be useful to set up periodic <application>cron</> tasks that |
135 |
| - <command>VACUUM</command> only selected tables, skipping tables that are known not to |
136 |
| - change often. This is only likely to be helpful if you have both |
137 |
| - large heavily-updated tables and large seldom-updated tables — the |
138 |
| - extra cost of vacuuming a small table isn't enough to be worth |
139 |
| - worrying about. |
140 |
| - </para> |
141 |
| - |
142 | 125 | <para>
|
143 | 126 | There are two variants of the <command>VACUUM</command>
|
144 | 127 | command. The first form, known as <quote>lazy vacuum</quote> or
|
|
167 | 150 | </para>
|
168 | 151 |
|
169 | 152 | <para>
|
170 |
| - The standard form of <command>VACUUM</> is best used with the goal |
171 |
| - of maintaining a fairly level steady-state usage of disk space. If |
172 |
| - you need to return disk space to the operating system, you can use |
173 |
| - <command>VACUUM FULL</> — but what's the point of releasing disk |
174 |
| - space that will only have to be allocated again soon? Moderately |
175 |
| - frequent standard <command>VACUUM</> runs are a better approach |
176 |
| - than infrequent <command>VACUUM FULL</> runs for maintaining |
177 |
| - heavily-updated tables. However, if some heavily-updated tables |
178 |
| - have gone too long with infrequent <command>VACUUM</>, you can |
| 153 | + Fortunately, autovacuum (<xref linkend="autovacuum">) monitors table |
| 154 | + activity and performs <command>VACUUM</command>s when necessary. This |
| 155 | + eliminates the need for administrators to worry about disk space |
| 156 | + recovery in all but the most unusual cases. |
| 157 | + </para> |
| 158 | + |
| 159 | + <para> |
| 160 | + For administrators who want to control <command>VACUUM</command> |
| 161 | + themselves, the standard form of <command>VACUUM</> is best used to |
| 162 | + maintain a steady-state usage of disk space. If you need to return |
| 163 | + disk space to the operating system, you can use <command>VACUUM |
| 164 | + FULL</>, but this is unwise if the table will just grow again in the |
| 165 | + future. Moderately-frequent standard <command>VACUUM</> runs are a |
| 166 | + better approach than infrequent <command>VACUUM FULL</> runs for |
| 167 | + maintaining heavily-updated tables. However, if some heavily-updated |
| 168 | + tables have gone too long with infrequent <command>VACUUM</>, you can |
179 | 169 | use <command>VACUUM FULL</> or <command>CLUSTER</> to get performance
|
180 | 170 | back (it is much slower to scan a table containing almost only dead
|
181 | 171 | rows).
|
182 | 172 | </para>
|
183 | 173 |
|
184 | 174 | <para>
|
185 |
| - Recommended practice for most sites is to schedule a database-wide |
186 |
| - <command>VACUUM</> once a day at a low-usage time of day, |
187 |
| - supplemented by more frequent vacuuming of heavily-updated tables |
188 |
| - if necessary. (Some installations with extremely high update rates |
189 |
| - vacuum their busiest tables as often as once every few minutes.) |
190 |
| - If you have multiple databases |
191 |
| - in a cluster, don't forget to <command>VACUUM</command> each one; |
192 |
| - the program <xref linkend="app-vacuumdb" endterm="app-vacuumdb-title"> |
193 |
| - might be helpful. |
| 175 | + For those not using autovacuum, one approach is to schedule a |
| 176 | + database-wide <command>VACUUM</> once a day during low-usage period, |
| 177 | + supplemented by more frequent vacuuming of heavily-updated tables if |
| 178 | + necessary. (Some installations with extremely high update rates vacuum |
| 179 | + their busiest tables as often as once every few minutes.) If you have |
| 180 | + multiple databases in a cluster, don't forget to |
| 181 | + <command>VACUUM</command> each one; the program <xref |
| 182 | + linkend="app-vacuumdb" endterm="app-vacuumdb-title"> might be helpful. |
194 | 183 | </para>
|
195 | 184 |
|
196 | 185 | <para>
|
|
0 commit comments