Commit beb850e1 authored by Robert Haas's avatar Robert Haas

Properly set relpersistence for fake relcache entries.

This can result in buffers failing to be properly flushed at
checkpoint time, leading to data loss.

Report, diagnosis, and patch by Jeff Davis.
parent 9afc6481
...@@ -394,6 +394,8 @@ CreateFakeRelcacheEntry(RelFileNode rnode) ...@@ -394,6 +394,8 @@ CreateFakeRelcacheEntry(RelFileNode rnode)
FakeRelCacheEntry fakeentry; FakeRelCacheEntry fakeentry;
Relation rel; Relation rel;
Assert(InRecovery);
/* Allocate the Relation struct and all related space in one block. */ /* Allocate the Relation struct and all related space in one block. */
fakeentry = palloc0(sizeof(FakeRelCacheEntryData)); fakeentry = palloc0(sizeof(FakeRelCacheEntryData));
rel = (Relation) fakeentry; rel = (Relation) fakeentry;
...@@ -403,6 +405,9 @@ CreateFakeRelcacheEntry(RelFileNode rnode) ...@@ -403,6 +405,9 @@ CreateFakeRelcacheEntry(RelFileNode rnode)
/* We will never be working with temp rels during recovery */ /* We will never be working with temp rels during recovery */
rel->rd_backend = InvalidBackendId; rel->rd_backend = InvalidBackendId;
/* It must be a permanent table if we're in recovery. */
rel->rd_rel->relpersistence = RELPERSISTENCE_PERMANENT;
/* We don't know the name of the relation; use relfilenode instead */ /* We don't know the name of the relation; use relfilenode instead */
sprintf(RelationGetRelationName(rel), "%u", rnode.relNode); sprintf(RelationGetRelationName(rel), "%u", rnode.relNode);
......
...@@ -271,6 +271,8 @@ ReadBufferWithoutRelcache(RelFileNode rnode, ForkNumber forkNum, ...@@ -271,6 +271,8 @@ ReadBufferWithoutRelcache(RelFileNode rnode, ForkNumber forkNum,
SMgrRelation smgr = smgropen(rnode, InvalidBackendId); SMgrRelation smgr = smgropen(rnode, InvalidBackendId);
Assert(InRecovery);
return ReadBuffer_common(smgr, RELPERSISTENCE_PERMANENT, forkNum, blockNum, return ReadBuffer_common(smgr, RELPERSISTENCE_PERMANENT, forkNum, blockNum,
mode, strategy, &hit); mode, strategy, &hit);
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment