diff options
| author | Heikki Linnakangas | 2010-02-19 10:51:04 +0000 |
|---|---|---|
| committer | Heikki Linnakangas | 2010-02-19 10:51:04 +0000 |
| commit | ad458cfe81bcefd6d8bd17ff2e42c6599d441bd6 (patch) | |
| tree | a4e6d3c89e74fbd65b03103d7a4a575f96f3a6fa /src/backend/replication | |
| parent | 94f610b16342d7727774f6bb9245341cfa6f895c (diff) | |
Don't use O_DIRECT when writing WAL files if archiving or streaming is
enabled. Bypassing the kernel cache is counter-productive in that case,
because the archiver/walsender process will read from the WAL file
soon after it's written, and if it's not cached the read will cause
a physical read, eating I/O bandwidth available on the WAL drive.
Also, walreceiver process does unaligned writes, so disable O_DIRECT
in walreceiver process for that reason too.
Diffstat (limited to 'src/backend/replication')
| -rw-r--r-- | src/backend/replication/walreceiver.c | 22 |
1 files changed, 14 insertions, 8 deletions
diff --git a/src/backend/replication/walreceiver.c b/src/backend/replication/walreceiver.c index 0e57611da42..3f82693dcea 100644 --- a/src/backend/replication/walreceiver.c +++ b/src/backend/replication/walreceiver.c @@ -29,7 +29,7 @@ * * * IDENTIFICATION - * $PostgreSQL: pgsql/src/backend/replication/walreceiver.c,v 1.4 2010/02/17 04:19:39 tgl Exp $ + * $PostgreSQL: pgsql/src/backend/replication/walreceiver.c,v 1.5 2010/02/19 10:51:04 heikki Exp $ * *------------------------------------------------------------------------- */ @@ -50,6 +50,9 @@ #include "utils/ps_status.h" #include "utils/resowner.h" +/* Global variable to indicate if this process is a walreceiver process */ +bool am_walreceiver; + /* libpqreceiver hooks to these when loaded */ walrcv_connect_type walrcv_connect = NULL; walrcv_receive_type walrcv_receive = NULL; @@ -158,6 +161,8 @@ WalReceiverMain(void) /* use volatile pointer to prevent code rearrangement */ volatile WalRcvData *walrcv = WalRcv; + am_walreceiver = true; + /* * WalRcv should be set up already (if we are a backend, we inherit * this by fork() or EXEC_BACKEND mechanism from the postmaster). @@ -424,16 +429,18 @@ XLogWalRcvWrite(char *buf, Size nbytes, XLogRecPtr recptr) bool use_existent; /* - * XLOG segment files will be re-read in recovery operation soon, - * so we don't need to advise the OS to release any cache page. + * fsync() and close current file before we switch to next one. + * We would otherwise have to reopen this file to fsync it later */ if (recvFile >= 0) { + XLogWalRcvFlush(); + /* - * fsync() before we switch to next file. We would otherwise - * have to reopen this file to fsync it later + * XLOG segment files will be re-read by recovery in startup + * process soon, so we don't advise the OS to release cache + * pages associated with the file like XLogFileClose() does. */ - XLogWalRcvFlush(); if (close(recvFile) != 0) ereport(PANIC, (errcode_for_file_access(), @@ -445,8 +452,7 @@ XLogWalRcvWrite(char *buf, Size nbytes, XLogRecPtr recptr) /* Create/use new log file */ XLByteToSeg(recptr, recvId, recvSeg); use_existent = true; - recvFile = XLogFileInit(recvId, recvSeg, - &use_existent, true); + recvFile = XLogFileInit(recvId, recvSeg, &use_existent, true); recvOff = 0; } |
