Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitad42957

Browse files
committed
Create a new dedicated Postgres process, "wal writer", which exists to write
and fsync WAL at convenient intervals. For the moment it just tries tooffload this work from backends, but soon it will be responsible forguaranteeing a maximum delay before asynchronously-committed transactionswill be flushed to disk.This is a portion of Simon Riggs' async-commit patch, committed to CVSseparately because a background WAL writer seems like it might be a good ideaindependently of the async-commit feature. I rebased walwriter.c onbgwriter.c because it seemed like a more appropriate way of handling signals;while the startup/shutdown logic in postmaster.c is more like autovac becausewe want walwriter to quit before we start the shutdown checkpoint.
1 parent53d2951 commitad42957

File tree

11 files changed

+547
-70
lines changed

11 files changed

+547
-70
lines changed

‎doc/src/sgml/config.sgml

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<!-- $PostgreSQL: pgsql/doc/src/sgml/config.sgml,v 1.132 2007/07/2401:53:55 alvherre Exp $ -->
1+
<!-- $PostgreSQL: pgsql/doc/src/sgml/config.sgml,v 1.133 2007/07/2404:54:08 tgl Exp $ -->
22

33
<chapter Id="runtime-config">
44
<title>Server Configuration</title>
@@ -1413,7 +1413,7 @@ SET ENABLE_SEQSCAN TO OFF;
14131413
</para>
14141414
</listitem>
14151415
</varlistentry>
1416-
1416+
14171417
<varlistentry id="guc-wal-buffers" xreflabel="wal_buffers">
14181418
<term><varname>wal_buffers</varname> (<type>integer</type>)</term>
14191419
<indexterm>
@@ -1438,7 +1438,27 @@ SET ENABLE_SEQSCAN TO OFF;
14381438
</para>
14391439
</listitem>
14401440
</varlistentry>
1441-
1441+
1442+
<varlistentry id="guc-wal-writer-delay" xreflabel="wal_writer_delay">
1443+
<term><varname>wal_writer_delay</varname> (<type>integer</type>)</term>
1444+
<indexterm>
1445+
<primary><varname>wal_writer_delay</> configuration parameter</primary>
1446+
</indexterm>
1447+
<listitem>
1448+
<para>
1449+
Specifies the delay between activity rounds for the WAL writer.
1450+
In each round the writer will flush WAL to disk. It then sleeps for
1451+
<varname>wal_writer_delay</> milliseconds, and repeats. The default
1452+
value is 200 milliseconds (<literal>200ms</>). Note that on many
1453+
systems, the effective resolution of sleep delays is 10 milliseconds;
1454+
setting <varname>wal_writer_delay</> to a value that is not a multiple
1455+
of 10 might have the same results as setting it to the next higher
1456+
multiple of 10. This parameter can only be set in the
1457+
<filename>postgresql.conf</> file or on the server command line.
1458+
</para>
1459+
</listitem>
1460+
</varlistentry>
1461+
14421462
<varlistentry id="guc-commit-delay" xreflabel="commit_delay">
14431463
<term><varname>commit_delay</varname> (<type>integer</type>)</term>
14441464
<indexterm>
@@ -1521,7 +1541,7 @@ SET ENABLE_SEQSCAN TO OFF;
15211541
</indexterm>
15221542
<listitem>
15231543
<para>
1524-
Specifies the target length of checkpoints, as a fraction of
1544+
Specifies the target length of checkpoints, as a fraction of
15251545
the checkpoint interval. The default is 0.5.
15261546

15271547
This parameter can only be set in the <filename>postgresql.conf</>

‎src/backend/access/transam/xlog.c

Lines changed: 80 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
* Portions Copyright (c) 1996-2007, PostgreSQL Global Development Group
88
* Portions Copyright (c) 1994, Regents of the University of California
99
*
10-
* $PostgreSQL: pgsql/src/backend/access/transam/xlog.c,v 1.274 2007/06/30 19:12:01 tgl Exp $
10+
* $PostgreSQL: pgsql/src/backend/access/transam/xlog.c,v 1.275 2007/07/24 04:54:08 tgl Exp $
1111
*
1212
*-------------------------------------------------------------------------
1313
*/
@@ -484,7 +484,6 @@ XLogInsert(RmgrId rmid, uint8 info, XLogRecData *rdata)
484484
uint32len,
485485
write_len;
486486
unsignedi;
487-
XLogwrtRqstLogwrtRqst;
488487
boolupdrqst;
489488
booldoPageWrites;
490489
boolisLogSwitch= (rmid==RM_XLOG_ID&&info==XLOG_SWITCH);
@@ -643,43 +642,6 @@ begin:;
643642

644643
START_CRIT_SECTION();
645644

646-
/* update LogwrtResult before doing cache fill check */
647-
{
648-
/* use volatile pointer to prevent code rearrangement */
649-
volatileXLogCtlData*xlogctl=XLogCtl;
650-
651-
SpinLockAcquire(&xlogctl->info_lck);
652-
LogwrtRqst=xlogctl->LogwrtRqst;
653-
LogwrtResult=xlogctl->LogwrtResult;
654-
SpinLockRelease(&xlogctl->info_lck);
655-
}
656-
657-
/*
658-
* If cache is half filled then try to acquire write lock and do
659-
* XLogWrite. Ignore any fractional blocks in performing this check.
660-
*/
661-
LogwrtRqst.Write.xrecoff-=LogwrtRqst.Write.xrecoff %XLOG_BLCKSZ;
662-
if (LogwrtRqst.Write.xlogid!=LogwrtResult.Write.xlogid||
663-
(LogwrtRqst.Write.xrecoff >=LogwrtResult.Write.xrecoff+
664-
XLogCtl->XLogCacheByte /2))
665-
{
666-
if (LWLockConditionalAcquire(WALWriteLock,LW_EXCLUSIVE))
667-
{
668-
/*
669-
* Since the amount of data we write here is completely optional
670-
* anyway, tell XLogWrite it can be "flexible" and stop at a
671-
* convenient boundary. This allows writes triggered by this
672-
* mechanism to synchronize with the cache boundaries, so that in
673-
* a long transaction we'll basically dump alternating halves of
674-
* the buffer array.
675-
*/
676-
LogwrtResult=XLogCtl->Write.LogwrtResult;
677-
if (XLByteLT(LogwrtResult.Write,LogwrtRqst.Write))
678-
XLogWrite(LogwrtRqst, true, false);
679-
LWLockRelease(WALWriteLock);
680-
}
681-
}
682-
683645
/* Now wait to get insert lock */
684646
LWLockAcquire(WALInsertLock,LW_EXCLUSIVE);
685647

@@ -1800,6 +1762,85 @@ XLogFlush(XLogRecPtr record)
18001762
LogwrtResult.Flush.xlogid,LogwrtResult.Flush.xrecoff);
18011763
}
18021764

1765+
/*
1766+
* Flush xlog, but without specifying exactly where to flush to.
1767+
*
1768+
* We normally flush only completed blocks; but if there is nothing to do on
1769+
* that basis, we check for unflushed async commits in the current incomplete
1770+
* block, and flush through the latest one of those. Thus, if async commits
1771+
* are not being used, we will flush complete blocks only. We can guarantee
1772+
* that async commits reach disk after at most three cycles; normally only
1773+
* one or two. (We allow XLogWrite to write "flexibly", meaning it can stop
1774+
* at the end of the buffer ring; this makes a difference only with very high
1775+
* load or long wal_writer_delay, but imposes one extra cycle for the worst
1776+
* case for async commits.)
1777+
*
1778+
* This routine is invoked periodically by the background walwriter process.
1779+
*/
1780+
void
1781+
XLogBackgroundFlush(void)
1782+
{
1783+
XLogRecPtrWriteRqstPtr;
1784+
boolflexible= true;
1785+
1786+
/* read LogwrtResult and update local state */
1787+
{
1788+
/* use volatile pointer to prevent code rearrangement */
1789+
volatileXLogCtlData*xlogctl=XLogCtl;
1790+
1791+
SpinLockAcquire(&xlogctl->info_lck);
1792+
LogwrtResult=xlogctl->LogwrtResult;
1793+
WriteRqstPtr=xlogctl->LogwrtRqst.Write;
1794+
SpinLockRelease(&xlogctl->info_lck);
1795+
}
1796+
1797+
/* back off to last completed page boundary */
1798+
WriteRqstPtr.xrecoff-=WriteRqstPtr.xrecoff %XLOG_BLCKSZ;
1799+
1800+
#ifdefNOT_YET/* async commit patch is still to come */
1801+
/* if we have already flushed that far, consider async commit records */
1802+
if (XLByteLE(WriteRqstPtr,LogwrtResult.Flush))
1803+
{
1804+
/* use volatile pointer to prevent code rearrangement */
1805+
volatileXLogCtlData*xlogctl=XLogCtl;
1806+
1807+
SpinLockAcquire(&xlogctl->async_commit_lck);
1808+
WriteRqstPtr=xlogctl->asyncCommitLSN;
1809+
SpinLockRelease(&xlogctl->async_commit_lck);
1810+
flexible= false;/* ensure it all gets written */
1811+
}
1812+
#endif
1813+
1814+
/* Done if already known flushed */
1815+
if (XLByteLE(WriteRqstPtr,LogwrtResult.Flush))
1816+
return;
1817+
1818+
#ifdefWAL_DEBUG
1819+
if (XLOG_DEBUG)
1820+
elog(LOG,"xlog bg flush request %X/%X; write %X/%X; flush %X/%X",
1821+
WriteRqstPtr.xlogid,WriteRqstPtr.xrecoff,
1822+
LogwrtResult.Write.xlogid,LogwrtResult.Write.xrecoff,
1823+
LogwrtResult.Flush.xlogid,LogwrtResult.Flush.xrecoff);
1824+
#endif
1825+
1826+
START_CRIT_SECTION();
1827+
1828+
/* now wait for the write lock */
1829+
LWLockAcquire(WALWriteLock,LW_EXCLUSIVE);
1830+
LogwrtResult=XLogCtl->Write.LogwrtResult;
1831+
if (!XLByteLE(WriteRqstPtr,LogwrtResult.Flush))
1832+
{
1833+
XLogwrtRqstWriteRqst;
1834+
1835+
WriteRqst.Write=WriteRqstPtr;
1836+
WriteRqst.Flush=WriteRqstPtr;
1837+
XLogWrite(WriteRqst,flexible, false);
1838+
}
1839+
LWLockRelease(WALWriteLock);
1840+
1841+
END_CRIT_SECTION();
1842+
}
1843+
18031844
/*
18041845
* Test whether XLOG data has been flushed up to (at least) the given position.
18051846
*

‎src/backend/bootstrap/bootstrap.c

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
* Portions Copyright (c) 1994, Regents of the University of California
99
*
1010
* IDENTIFICATION
11-
* $PostgreSQL: pgsql/src/backend/bootstrap/bootstrap.c,v 1.234 2007/06/28 00:02:37 tgl Exp $
11+
* $PostgreSQL: pgsql/src/backend/bootstrap/bootstrap.c,v 1.235 2007/07/24 04:54:09 tgl Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -30,6 +30,7 @@
3030
#include"miscadmin.h"
3131
#include"nodes/makefuncs.h"
3232
#include"postmaster/bgwriter.h"
33+
#include"postmaster/walwriter.h"
3334
#include"storage/freespace.h"
3435
#include"storage/ipc.h"
3536
#include"storage/proc.h"
@@ -195,7 +196,7 @@ static IndexList *ILHead = NULL;
195196
* AuxiliaryProcessMain
196197
*
197198
* The main entry point for auxiliary processes, such as the bgwriter,
198-
* bootstrapper and the shared memory checker code.
199+
*walwriter,bootstrapper and the shared memory checker code.
199200
*
200201
* This code is here just because of historical reasons.
201202
*/
@@ -331,6 +332,9 @@ AuxiliaryProcessMain(int argc, char *argv[])
331332
caseBgWriterProcess:
332333
statmsg="writer process";
333334
break;
335+
caseWalWriterProcess:
336+
statmsg="wal writer process";
337+
break;
334338
default:
335339
statmsg="??? process";
336340
break;
@@ -419,6 +423,12 @@ AuxiliaryProcessMain(int argc, char *argv[])
419423
InitXLOGAccess();
420424
BackgroundWriterMain();
421425
proc_exit(1);/* should never return */
426+
427+
caseWalWriterProcess:
428+
/* don't set signals, walwriter has its own agenda */
429+
InitXLOGAccess();
430+
WalWriterMain();
431+
proc_exit(1);/* should never return */
422432

423433
default:
424434
elog(PANIC,"unrecognized process type: %d",auxType);

‎src/backend/postmaster/Makefile

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,16 @@
44
# Makefile for src/backend/postmaster
55
#
66
# IDENTIFICATION
7-
# $PostgreSQL: pgsql/src/backend/postmaster/Makefile,v 1.22 2007/01/20 17:16:12 petere Exp $
7+
# $PostgreSQL: pgsql/src/backend/postmaster/Makefile,v 1.23 2007/07/24 04:54:09 tgl Exp $
88
#
99
#-------------------------------------------------------------------------
1010

1111
subdir = src/backend/postmaster
1212
top_builddir = ../../..
1313
include$(top_builddir)/src/Makefile.global
1414

15-
OBJS = bgwriter.oautovacuum.o pgarch.o pgstat.o postmaster.o syslogger.o\
16-
fork_process.o
15+
OBJS =autovacuum.obgwriter.ofork_process.o pgarch.o pgstat.o postmaster.o\
16+
syslogger.o walwriter.o
1717

1818
all: SUBSYS.o
1919

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp