1
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
8
CONTENT="Modular DocBook HTML Stylesheet Version 1.79"><LINK
10
HREF="mailto:pgsql-docs@postgresql.org"><LINK
12
TITLE="PostgreSQL 9.1beta1 Documentation"
13
HREF="index.html"><LINK
15
TITLE="Reliability and the Write-Ahead Log"
18
TITLE="Reliability and the Write-Ahead Log"
21
TITLE="Write-Ahead Logging (WAL)"
22
HREF="wal-intro.html"><LINK
25
HREF="stylesheet.css"><META
26
HTTP-EQUIV="Content-Type"
27
CONTENT="text/html; charset=ISO-8859-1"><META
29
CONTENT="2011-04-27T21:20:33"></HEAD
35
SUMMARY="Header navigation table"
47
>PostgreSQL 9.1beta1 Documentation</A
56
TITLE="Reliability and the Write-Ahead Log"
66
TITLE="Reliability and the Write-Ahead Log"
74
>Chapter 29. Reliability and the Write-Ahead Log</TD
80
TITLE="Reliability and the Write-Ahead Log"
89
TITLE="Write-Ahead Logging (WAL)"
104
NAME="WAL-RELIABILITY"
105
>29.1. Reliability</A
108
> Reliability is an important property of any serious database
112
> does everything possible to
113
guarantee reliable operation. One aspect of reliable operation is
114
that all data recorded by a committed transaction should be stored
115
in a nonvolatile area that is safe from power loss, operating
116
system failure, and hardware failure (except failure of the
117
nonvolatile area itself, of course). Successfully writing the data
118
to the computer's permanent storage (disk drive or equivalent)
119
ordinarily meets this requirement. In fact, even if a computer is
120
fatally damaged, if the disk drives survive they can be moved to
121
another computer with similar hardware and all committed
122
transactions will remain intact.
125
> While forcing data to the disk platters periodically might seem like
126
a simple operation, it is not. Because disk drives are dramatically
127
slower than main memory and CPUs, several layers of caching exist
128
between the computer's main memory and the disk platters.
129
First, there is the operating system's buffer cache, which caches
130
frequently requested disk blocks and combines disk writes. Fortunately,
131
all operating systems give applications a way to force writes from
132
the buffer cache to disk, and <SPAN
136
features. (See the <A
137
HREF="runtime-config-wal.html#GUC-WAL-SYNC-METHOD"
140
to adjust how this is done.)
143
> Next, there might be a cache in the disk drive controller; this is
144
particularly common on <ACRONYM
147
> controller cards. Some of
151
>, meaning writes are sent
152
to the drive as soon as they arrive. Others are
156
>, meaning data is sent to the drive at
157
some later time. Such caches can be a reliability hazard because the
158
memory in the disk controller cache is volatile, and will lose its
159
contents in a power failure. Better controller cards have
162
>battery-backup units</I
167
the card has a battery that
168
maintains power to the cache in case of system power loss. After power
169
is restored the data will be written to the disk drives.
172
> And finally, most disk drives have caches. Some are write-through
173
while some are write-back, and the same concerns about data loss
174
exist for write-back drive caches as for disk controller
175
caches. Consumer-grade IDE and SATA drives are particularly likely
176
to have write-back caches that will not survive a power failure. Many
177
solid-state drives (SSD) also have volatile write-back caches.
180
> These caches can typically be disabled; however, the method for doing
181
this varies by operating system and drive type:
191
>, IDE drives can be queried using
195
>; write caching is enabled if there is
206
can be used to turn off write caching. SCSI drives can be queried
208
HREF="http://sg.danny.cz/sg/sdparm.html"
217
>sdparm --get=WCE</TT
219
whether the write cache is enabled and <TT
221
>sdparm --clear=WCE</TT
231
>, IDE drives can be queried using
235
> and write caching turned off using
241
>/boot/loader.conf</TT
254
>, the disk write cache is controlled by
256
HREF="http://www.sun.com/bigadmin/content/submitted/format_utility.jsp"
263
(The Solaris <ACRONYM
266
> file system is safe with disk write-cache
267
enabled because it issues its own disk cache flush commands.)
282
> (the default), write caching can be disabled
285
>My Computer\Open\<TT
290
>\Properties\Hardware\Properties\Policies\Enable write caching on the disk</TT
292
Alternatively, set <TT
301
>fsync_writethrough</TT
311
>, write caching can be prevented by
317
>fsync_writethrough</TT
323
> Recent SATA drives (those following <ACRONYM
327
offer a drive cache flush command (<TT
331
while SCSI drives have long supported a similar command
334
>SYNCHRONIZE CACHE</TT
335
>. These commands are not directly
339
>, but some file systems
346
>) can use them to flush
347
data to the platters on write-back-enabled drives. Unfortunately, such
348
file systems behave suboptimally when combined with battery-backup unit
352
>) disk controllers. In such setups, the synchronize
353
command forces all data from the controller cache to the disks,
354
eliminating much of the benefit of the BBU. You can run the
356
HREF="pgtestfsync.html"
359
if you are affected. If you are affected, the performance benefits
360
of the BBU can be regained by turning off write barriers in
361
the file system or reconfiguring the disk controller, if that is
362
an option. If write barriers are turned off, make sure the battery
363
remains functional; a faulty battery can potentially lead to data loss.
364
Hopefully file system and disk controller designers will eventually
365
address this suboptimal behavior.
368
> When the operating system sends a write request to the storage hardware,
369
there is little it can do to make sure the data has arrived at a truly
370
non-volatile storage area. Rather, it is the
371
administrator's responsibility to make certain that all storage components
372
ensure data integrity. Avoid disk controllers that have non-battery-backed
373
write caches. At the drive level, disable write-back caching if the
374
drive cannot guarantee the data will be written before shutdown.
375
If you use SSDs, be aware that many of these do not honor cache flush
377
You can test for reliable I/O subsystem behavior using <A
378
HREF="http://brad.livejournal.com/2116715.html"
387
> Another risk of data loss is posed by the disk platter write
388
operations themselves. Disk platters are divided into sectors,
389
commonly 512 bytes each. Every physical read or write operation
390
processes a whole sector.
391
When a write request arrives at the drive, it might be for some multiple
395
> typically writes 8192 bytes, or
396
16 sectors, at a time), and the process of writing could fail due
397
to power loss at any time, meaning some of the 512-byte sectors were
398
written while others were not. To guard against such failures,
402
> periodically writes full page images to
403
permanent WAL storage <SPAN
409
> modifying the actual page on
410
disk. By doing this, during crash recovery <SPAN
414
restore partially-written pages from WAL. If you have file-system software
415
that prevents partial page writes (e.g., ZFS), you can turn off
416
this page imaging by turning off the <A
417
HREF="runtime-config-wal.html#GUC-FULL-PAGE-WRITES"
419
> parameter. Battery-Backed Unit
420
(BBU) disk controllers do not prevent partial page writes unless
421
they guarantee that data is written to the BBU as full (8kB) pages.
429
SUMMARY="Footer navigation table"
458
HREF="wal-intro.html"
468
>Reliability and the Write-Ahead Log</TD
482
>Write-Ahead Logging (<ACRONYM
b'\\ No newline at end of file'