OSDN Git Service

FIRST REPOSITORY
[eos/hostdependOTHERS.git] / I386LINUX / util / I386LINUX / doc / postgresql / html / wal.html
1 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
2 <HTML
3 ><HEAD
4 ><TITLE
5 >Write-Ahead Logging (WAL)</TITLE
6 ><META
7 NAME="GENERATOR"
8 CONTENT="Modular DocBook HTML Stylesheet Version 1.7"><LINK
9 REV="MADE"
10 HREF="mailto:pgsql-docs@postgresql.org"><LINK
11 REL="HOME"
12 TITLE="PostgreSQL 7.4.1 Documentation"
13 HREF="index.html"><LINK
14 REL="UP"
15 TITLE="Server Administration"
16 HREF="admin.html"><LINK
17 REL="PREVIOUS"
18 TITLE="Disk Full Failure"
19 HREF="disk-full.html"><LINK
20 REL="NEXT"
21 TITLE="Future Benefits"
22 HREF="wal-benefits-later.html"><LINK
23 REL="STYLESHEET"
24 TYPE="text/css"
25 HREF="stylesheet.css"><META
26 NAME="creation"
27 CONTENT="2003-12-22T03:48:47"></HEAD
28 ><BODY
29 CLASS="CHAPTER"
30 ><DIV
31 CLASS="NAVHEADER"
32 ><TABLE
33 SUMMARY="Header navigation table"
34 WIDTH="100%"
35 BORDER="0"
36 CELLPADDING="0"
37 CELLSPACING="0"
38 ><TR
39 ><TH
40 COLSPAN="5"
41 ALIGN="center"
42 VALIGN="bottom"
43 >PostgreSQL 7.4.1 Documentation</TH
44 ></TR
45 ><TR
46 ><TD
47 WIDTH="10%"
48 ALIGN="left"
49 VALIGN="top"
50 ><A
51 HREF="disk-full.html"
52 ACCESSKEY="P"
53 >Prev</A
54 ></TD
55 ><TD
56 WIDTH="10%"
57 ALIGN="left"
58 VALIGN="top"
59 ><A
60 HREF="diskusage.html"
61 >Fast Backward</A
62 ></TD
63 ><TD
64 WIDTH="60%"
65 ALIGN="center"
66 VALIGN="bottom"
67 ></TD
68 ><TD
69 WIDTH="10%"
70 ALIGN="right"
71 VALIGN="top"
72 ><A
73 HREF="regress.html"
74 >Fast Forward</A
75 ></TD
76 ><TD
77 WIDTH="10%"
78 ALIGN="right"
79 VALIGN="top"
80 ><A
81 HREF="wal-benefits-later.html"
82 ACCESSKEY="N"
83 >Next</A
84 ></TD
85 ></TR
86 ></TABLE
87 ><HR
88 ALIGN="LEFT"
89 WIDTH="100%"></DIV
90 ><DIV
91 CLASS="CHAPTER"
92 ><H1
93 ><A
94 NAME="WAL"
95 ></A
96 >Chapter 25. Write-Ahead Logging (<ACRONYM
97 CLASS="ACRONYM"
98 >WAL</ACRONYM
99 >)</H1
100 ><DIV
101 CLASS="TOC"
102 ><DL
103 ><DT
104 ><B
105 >Table of Contents</B
106 ></DT
107 ><DT
108 >25.1. <A
109 HREF="wal.html#WAL-BENEFITS-NOW"
110 >Benefits of <ACRONYM
111 CLASS="ACRONYM"
112 >WAL</ACRONYM
113 ></A
114 ></DT
115 ><DT
116 >25.2. <A
117 HREF="wal-benefits-later.html"
118 >Future Benefits</A
119 ></DT
120 ><DT
121 >25.3. <A
122 HREF="wal-configuration.html"
123 ><ACRONYM
124 CLASS="ACRONYM"
125 >WAL</ACRONYM
126 > Configuration</A
127 ></DT
128 ><DT
129 >25.4. <A
130 HREF="wal-internals.html"
131 >Internals</A
132 ></DT
133 ></DL
134 ></DIV
135 ><A
136 NAME="AEN19540"
137 ></A
138 ><A
139 NAME="AEN19542"
140 ></A
141 ><P
142 >   <I
143 CLASS="FIRSTTERM"
144 >Write-Ahead Logging</I
145 > (<ACRONYM
146 CLASS="ACRONYM"
147 >WAL</ACRONYM
148 >)
149    is a standard approach to transaction logging.  Its detailed
150    description may be found in most (if not all) books about
151    transaction processing. Briefly, <ACRONYM
152 CLASS="ACRONYM"
153 >WAL</ACRONYM
154 >'s central
155    concept is that changes to data files (where tables and indexes
156    reside) must be written only after those changes have been logged,
157    that is, when log records have been flushed to permanent
158    storage. If we follow this procedure, we do not need to flush
159    data pages to disk on every transaction commit, because we know
160    that in the event of a crash we will be able to recover the
161    database using the log: any changes that have not been applied to
162    the data pages will first be redone from the log records (this is
163    roll-forward recovery, also known as REDO) and then changes made by
164    uncommitted transactions will be removed from the data pages
165    (roll-backward recovery, UNDO).
166   </P
167 ><DIV
168 CLASS="SECT1"
169 ><H1
170 CLASS="SECT1"
171 ><A
172 NAME="WAL-BENEFITS-NOW"
173 >25.1. Benefits of <ACRONYM
174 CLASS="ACRONYM"
175 >WAL</ACRONYM
176 ></A
177 ></H1
178 ><A
179 NAME="AEN19552"
180 ></A
181 ><P
182 >    The first obvious benefit of using <ACRONYM
183 CLASS="ACRONYM"
184 >WAL</ACRONYM
185 > is a
186     significantly reduced number of disk writes, since only the log
187     file needs to be flushed to disk at the time of transaction
188     commit; in multiuser environments, commits of many transactions
189     may be accomplished with a single <CODE
190 CLASS="FUNCTION"
191 >fsync()</CODE
192 > of
193     the log file. Furthermore, the log file is written sequentially,
194     and so the cost of syncing the log is much less than the cost of
195     flushing the data pages.
196    </P
197 ><P
198 >    The next benefit is consistency of the data pages. The truth is
199     that, before <ACRONYM
200 CLASS="ACRONYM"
201 >WAL</ACRONYM
202 >,
203     <SPAN
204 CLASS="PRODUCTNAME"
205 >PostgreSQL</SPAN
206 > was never able to guarantee
207     consistency in the case of a crash.  Before
208     <ACRONYM
209 CLASS="ACRONYM"
210 >WAL</ACRONYM
211 >, any crash during writing could result in:
212
213     <P
214 ></P
215 ></P><OL
216 TYPE="1"
217 ><LI
218 ><P
219 >index rows pointing to nonexistent table rows</P
220 ></LI
221 ><LI
222 ><P
223 >index rows lost in split operations</P
224 ></LI
225 ><LI
226 ><P
227 >totally corrupted table or index page content, because
228       of partially written data pages</P
229 ></LI
230 ></OL
231 ><P>
232
233     Problems with indexes (problems 1 and 2) could possibly have been
234     fixed by additional <CODE
235 CLASS="FUNCTION"
236 >fsync()</CODE
237 > calls, but it is
238     not obvious how to handle the last case without
239     <ACRONYM
240 CLASS="ACRONYM"
241 >WAL</ACRONYM
242 >; <ACRONYM
243 CLASS="ACRONYM"
244 >WAL</ACRONYM
245 > saves the entire data
246     page content in the log if that is required to ensure page
247     consistency for after-crash recovery.
248    </P
249 ></DIV
250 ></DIV
251 ><DIV
252 CLASS="NAVFOOTER"
253 ><HR
254 ALIGN="LEFT"
255 WIDTH="100%"><TABLE
256 SUMMARY="Footer navigation table"
257 WIDTH="100%"
258 BORDER="0"
259 CELLPADDING="0"
260 CELLSPACING="0"
261 ><TR
262 ><TD
263 WIDTH="33%"
264 ALIGN="left"
265 VALIGN="top"
266 ><A
267 HREF="disk-full.html"
268 ACCESSKEY="P"
269 >Prev</A
270 ></TD
271 ><TD
272 WIDTH="34%"
273 ALIGN="center"
274 VALIGN="top"
275 ><A
276 HREF="index.html"
277 ACCESSKEY="H"
278 >Home</A
279 ></TD
280 ><TD
281 WIDTH="33%"
282 ALIGN="right"
283 VALIGN="top"
284 ><A
285 HREF="wal-benefits-later.html"
286 ACCESSKEY="N"
287 >Next</A
288 ></TD
289 ></TR
290 ><TR
291 ><TD
292 WIDTH="33%"
293 ALIGN="left"
294 VALIGN="top"
295 >Disk Full Failure</TD
296 ><TD
297 WIDTH="34%"
298 ALIGN="center"
299 VALIGN="top"
300 ><A
301 HREF="admin.html"
302 ACCESSKEY="U"
303 >Up</A
304 ></TD
305 ><TD
306 WIDTH="33%"
307 ALIGN="right"
308 VALIGN="top"
309 >Future Benefits</TD
310 ></TR
311 ></TABLE
312 ></DIV
313 ></BODY
314 ></HTML
315 >