commit fba38257e52564276bb106d55aef14d0de481169 Author: Aidan Van Dyk Date: Fri Oct 31 12:35:24 2008 -0400 WIP: Zero xlog tal on a forced switch If XLogWrite is called with xlog_switch, an XLog swithc has been force, either by a timeout based switch (archive_timeout), or an interactive force xlog switch (pg_switch_xlog/pg_stop_backup). In those cases, we assume we can afford a little extra IO bandwidth to make xlogs so much more compressable diff --git a/src/backend/access/transam/xlog.c b/src/backend/access/transam/xlog.c index 003098f..c6f9c79 100644 --- a/src/backend/access/transam/xlog.c +++ b/src/backend/access/transam/xlog.c @@ -1600,6 +1600,30 @@ XLogWrite(XLogwrtRqst WriteRqst, bool flexible, bool xlog_switch) */ if (finishing_seg || (xlog_switch && last_iteration)) { + /* + * If we've had an xlog switch forced, then we want to zero + * out the rest of the segment. We zero it out here because at the + * force switch time, IO bandwidth isn't a problem. + * -- AIDAN + */ + if (xlog_switch) + { + char buf[1024]; + uint32 left = (XLogSegSize - openLogOff); + ereport(LOG, + (errmsg("ZEROING xlog file %u segment %u from %u - %u [%u bytes]", + openLogId, openLogSeg, + openLogOff, XLogSegSize, left) + )); + memset(buf, 0, sizeof(buf)); + while (left > 0) + { + size_t len = (left > sizeof(buf)) ? sizeof(buf) : left; + write(openLogFile, buf, len); + left -= len; + } + } + issue_xlog_fsync(); LogwrtResult.Flush = LogwrtResult.Write; /* end of page */