mirror of
https://github.com/postgres/postgres.git
synced 2025-09-03 15:22:11 +03:00
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.
This commit is contained in:
@@ -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)
|
||||
{
|
||||
/*
|
||||
* fsync() before we switch to next file. We would otherwise
|
||||
* have to reopen this file to fsync it later
|
||||
*/
|
||||
XLogWalRcvFlush();
|
||||
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
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;
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user