|
1 | | -<!-- $Header: /cvsroot/pgsql/doc/src/sgml/wal.sgml,v 1.20 2002/09/06 20:26:00 momjian Exp $ --> |
| 1 | +<!-- $Header: /cvsroot/pgsql/doc/src/sgml/wal.sgml,v 1.21 2002/11/02 22:23:01 tgl Exp $ --> |
2 | 2 |
|
3 | 3 | <chapter id="wal"> |
4 | 4 | <title>Write-Ahead Logging (<acronym>WAL</acronym>)</title> |
|
222 | 222 | configuration parameters. |
223 | 223 | </para> |
224 | 224 |
|
225 | | - <para> |
226 | | - There are two commonly used <acronym>WAL</acronym> functions: |
227 | | - <function>LogInsert</function> and <function>LogFlush</function>. |
228 | | - <function>LogInsert</function> is used to place a new record into |
229 | | - the <acronym>WAL</acronym> buffers in shared memory. If there is no |
230 | | - space for the new record, <function>LogInsert</function> will have |
231 | | - to write (move to kernel cache) a few filled <acronym>WAL</acronym> |
232 | | - buffers. This is undesirable because <function>LogInsert</function> |
233 | | - is used on every database low level modification (for example, |
234 | | - tuple insertion) at a time when an exclusive lock is held on |
235 | | - affected data pages, so the operation needs to be as fast as |
236 | | - possible. What is worse, writing <acronym>WAL</acronym> buffers may |
237 | | - also force the creation of a new log segment, which takes even more |
238 | | - time. Normally, <acronym>WAL</acronym> buffers should be written |
239 | | - and flushed by a <function>LogFlush</function> request, which is |
240 | | - made, for the most part, at transaction commit time to ensure that |
241 | | - transaction records are flushed to permanent storage. On systems |
242 | | - with high log output, <function>LogFlush</function> requests may |
243 | | - not occur often enough to prevent <acronym>WAL</acronym> buffers |
244 | | - being written by <function>LogInsert</function>. On such systems |
245 | | - one should increase the number of <acronym>WAL</acronym> buffers by |
246 | | - modifying the <filename>postgresql.conf</filename> <varname> |
247 | | - WAL_BUFFERS</varname> parameter. The default number of <acronym> |
248 | | - WAL</acronym> buffers is 8. Increasing this value will |
249 | | - correspondingly increase shared memory usage. |
250 | | - </para> |
251 | | - |
252 | 225 | <para> |
253 | 226 | <firstterm>Checkpoints</firstterm> are points in the sequence of |
254 | 227 | transactions at which it is guaranteed that the data files have |
|
265 | 238 | or removed.) |
266 | 239 | </para> |
267 | 240 |
|
268 | | - <para> |
269 | | - The checkpoint maker is also able to create a few log segments for |
270 | | - future use, so as to avoid the need for |
271 | | - <function>LogInsert</function> or <function>LogFlush</function> to |
272 | | - spend time in creating them. (If that happens, the entire database |
273 | | - system will be delayed by the creation operation, so it's better if |
274 | | - the files can be created in the checkpoint maker, which is not on |
275 | | - anyone's critical path.) |
276 | | - By default a new 16MB segment file is created only if more than 75% of |
277 | | - the current segment has been used. This is inadequate if the system |
278 | | - generates more than 4MB of log output between checkpoints. |
279 | | - </para> |
280 | | - |
281 | 241 | <para> |
282 | 242 | The postmaster spawns a special backend process every so often |
283 | 243 | to create the next checkpoint. A checkpoint is created every |
|
303 | 263 |
|
304 | 264 | <para> |
305 | 265 | There will be at least one 16MB segment file, and will normally |
306 | | - not be more than <varname>CHECKPOINT_SEGMENTS</varname> |
| 266 | + not be more than2 *<varname>CHECKPOINT_SEGMENTS</varname> |
307 | 267 | + 1 files. You can use this to estimate space requirements for |
308 | 268 | WAL. Ordinarily, when old log segment files are no longer needed, |
309 | 269 | they are recycled (renamed to become the next sequential future |
310 | 270 | segments). If, due to a short-term peak of log output rate, there |
311 | | - are more than <varname>CHECKPOINT_SEGMENTS</varname> + 1 segment files, |
| 271 | + are more than2 *<varname>CHECKPOINT_SEGMENTS</varname> + 1 segment files, |
312 | 272 | the unneeded segment files will be deleted instead of recycled until the |
313 | 273 | system gets back under this limit. |
314 | 274 | </para> |
315 | 275 |
|
| 276 | + <para> |
| 277 | + There are two commonly used <acronym>WAL</acronym> functions: |
| 278 | + <function>LogInsert</function> and <function>LogFlush</function>. |
| 279 | + <function>LogInsert</function> is used to place a new record into |
| 280 | + the <acronym>WAL</acronym> buffers in shared memory. If there is no |
| 281 | + space for the new record, <function>LogInsert</function> will have |
| 282 | + to write (move to kernel cache) a few filled <acronym>WAL</acronym> |
| 283 | + buffers. This is undesirable because <function>LogInsert</function> |
| 284 | + is used on every database low level modification (for example, |
| 285 | + tuple insertion) at a time when an exclusive lock is held on |
| 286 | + affected data pages, so the operation needs to be as fast as |
| 287 | + possible. What is worse, writing <acronym>WAL</acronym> buffers may |
| 288 | + also force the creation of a new log segment, which takes even more |
| 289 | + time. Normally, <acronym>WAL</acronym> buffers should be written |
| 290 | + and flushed by a <function>LogFlush</function> request, which is |
| 291 | + made, for the most part, at transaction commit time to ensure that |
| 292 | + transaction records are flushed to permanent storage. On systems |
| 293 | + with high log output, <function>LogFlush</function> requests may |
| 294 | + not occur often enough to prevent <acronym>WAL</acronym> buffers |
| 295 | + being written by <function>LogInsert</function>. On such systems |
| 296 | + one should increase the number of <acronym>WAL</acronym> buffers by |
| 297 | + modifying the <filename>postgresql.conf</filename> <varname> |
| 298 | + WAL_BUFFERS</varname> parameter. The default number of <acronym> |
| 299 | + WAL</acronym> buffers is 8. Increasing this value will |
| 300 | + correspondingly increase shared memory usage. |
| 301 | + </para> |
| 302 | + |
316 | 303 | <para> |
317 | 304 | The <varname>COMMIT_DELAY</varname> parameter defines for how many |
318 | 305 | microseconds the backend will sleep after writing a commit |
|