aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/backend/access/heap/heapam.c10
-rw-r--r--src/backend/storage/buffer/bufmgr.c21
-rw-r--r--src/include/storage/bufmgr.h1
3 files changed, 32 insertions, 0 deletions
diff --git a/src/backend/access/heap/heapam.c b/src/backend/access/heap/heapam.c
index 1273d1201ff..4f52f05c290 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -4395,6 +4395,16 @@ heap_xlog_newpage(XLogRecPtr lsn, XLogRecord *record)
}
MarkBufferDirty(buffer);
+
+ /*
+ * At the end of crash recovery the init forks of unlogged relations are
+ * copied, without going through shared buffers. So we need to force the
+ * on-disk state of init forks to always be in sync with the state in
+ * shared buffers.
+ */
+ if (xlrec->forknum == INIT_FORKNUM)
+ FlushOneBuffer(buffer);
+
UnlockReleaseBuffer(buffer);
}
diff --git a/src/backend/storage/buffer/bufmgr.c b/src/backend/storage/buffer/bufmgr.c
index 6ef8c247547..c06b51c9b41 100644
--- a/src/backend/storage/buffer/bufmgr.c
+++ b/src/backend/storage/buffer/bufmgr.c
@@ -2238,6 +2238,27 @@ FlushDatabaseBuffers(Oid dbid)
}
/*
+ * Flush a previously, shared or exclusively, locked and pinned buffer to the
+ * OS.
+ */
+void
+FlushOneBuffer(Buffer buffer)
+{
+ volatile BufferDesc *bufHdr;
+
+ /* currently not needed, but no fundamental reason not to support */
+ Assert(!BufferIsLocal(buffer));
+
+ Assert(BufferIsPinned(buffer));
+
+ bufHdr = &BufferDescriptors[buffer - 1];
+
+ LWLockHeldByMe(bufHdr->content_lock);
+
+ FlushBuffer(bufHdr, NULL);
+}
+
+/*
* ReleaseBuffer -- release the pin on a buffer
*/
void
diff --git a/src/include/storage/bufmgr.h b/src/include/storage/bufmgr.h
index eb85d6f208d..362daf471e8 100644
--- a/src/include/storage/bufmgr.h
+++ b/src/include/storage/bufmgr.h
@@ -186,6 +186,7 @@ extern void CheckPointBuffers(int flags);
extern BlockNumber BufferGetBlockNumber(Buffer buffer);
extern BlockNumber RelationGetNumberOfBlocksInFork(Relation relation,
ForkNumber forkNum);
+extern void FlushOneBuffer(Buffer buffer);
extern void FlushRelationBuffers(Relation rel);
extern void FlushDatabaseBuffers(Oid dbid);
extern void DropRelFileNodeBuffers(RelFileNodeBackend rnode,