diff --git a/src/backend/access/heap/rewriteheap.c b/src/backend/access/heap/rewriteheap.c index 871d9e43d77..66c4ea0c3e2 100644 --- a/src/backend/access/heap/rewriteheap.c +++ b/src/backend/access/heap/rewriteheap.c @@ -1172,6 +1172,7 @@ heap_xlog_logical_rewrite(XLogRecPtr lsn, XLogRecord *r) len = xlrec->num_mappings * sizeof(LogicalRewriteMappingData); /* write out tail end of mapping file (again) */ + errno = 0; if (write(fd, data, len) != len) { /* if write didn't set errno, assume problem is no disk space */ diff --git a/src/backend/access/transam/twophase.c b/src/backend/access/transam/twophase.c index c04baf34039..c93ef1d5d23 100644 --- a/src/backend/access/transam/twophase.c +++ b/src/backend/access/transam/twophase.c @@ -1566,6 +1566,7 @@ RecreateTwoPhaseFile(TransactionId xid, void *content, int len) path))); /* Write content and CRC */ + errno = 0; if (write(fd, content, len) != len) { int save_errno = errno; diff --git a/src/backend/replication/logical/reorderbuffer.c b/src/backend/replication/logical/reorderbuffer.c index 7a8b706f221..94fb5b9deb2 100644 --- a/src/backend/replication/logical/reorderbuffer.c +++ b/src/backend/replication/logical/reorderbuffer.c @@ -2296,6 +2296,7 @@ ReorderBufferSerializeChange(ReorderBuffer *rb, ReorderBufferTXN *txn, ondisk->size = sz; + errno = 0; if (write(fd, rb->outbuf, ondisk->size) != ondisk->size) { int save_errno = errno; diff --git a/src/backend/replication/logical/snapbuild.c b/src/backend/replication/logical/snapbuild.c index 71cc06d4636..37a3d77a4c9 100644 --- a/src/backend/replication/logical/snapbuild.c +++ b/src/backend/replication/logical/snapbuild.c @@ -1571,6 +1571,7 @@ SnapBuildSerialize(SnapBuild *builder, XLogRecPtr lsn) ereport(ERROR, (errmsg("could not open file \"%s\": %m", path))); + errno = 0; if ((write(fd, ondisk, needed_length)) != needed_length) { int save_errno = errno; diff --git a/src/backend/replication/slot.c b/src/backend/replication/slot.c index 661415b9a20..af47cdab0eb 100644 --- a/src/backend/replication/slot.c +++ b/src/backend/replication/slot.c @@ -1026,6 +1026,7 @@ SaveSlotToPath(ReplicationSlot *slot, const char *dir, int elevel) SnapBuildOnDiskChecksummedSize); FIN_CRC32(cp.checksum); + errno = 0; if ((write(fd, &cp, sizeof(cp))) != sizeof(cp)) { int save_errno = errno; diff --git a/src/bin/pg_basebackup/receivelog.c b/src/bin/pg_basebackup/receivelog.c index da76d9befda..5e1f3d40496 100644 --- a/src/bin/pg_basebackup/receivelog.c +++ b/src/bin/pg_basebackup/receivelog.c @@ -137,6 +137,7 @@ open_walfile(XLogRecPtr startpoint, uint32 timeline, char *basedir, zerobuf = pg_malloc0(XLOG_BLCKSZ); for (bytes = 0; bytes < XLogSegSize; bytes += XLOG_BLCKSZ) { + errno = 0; if (write(f, zerobuf, XLOG_BLCKSZ) != XLOG_BLCKSZ) { /* if write didn't set errno, assume problem is no disk space */ @@ -1094,6 +1095,7 @@ HandleCopyStream(PGconn *conn, XLogRecPtr startpos, uint32 timeline, } } + errno = 0; if (write(walfile, copybuf + hdr_len + bytes_written, bytes_to_write) != bytes_to_write)