summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRobert Haas <rhaas@postgresql.org>2012-09-14 09:35:07 -0400
committerRobert Haas <rhaas@postgresql.org>2012-09-14 09:36:46 -0400
commiteb6e9b5ea4a5e733da705c053906f3aff47c9bf5 (patch)
tree9050c9bafc66cee43d8f444c848005df7d3da6b9
parent269dbaf7076c96b3301abb7571fde42e183bf363 (diff)
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.
-rw-r--r--src/backend/access/transam/xlogutils.c5
-rw-r--r--src/backend/storage/buffer/bufmgr.c2
2 files changed, 7 insertions, 0 deletions
diff --git a/src/backend/access/transam/xlogutils.c b/src/backend/access/transam/xlogutils.c
index 6ddcc59b37a..5676120a863 100644
--- a/src/backend/access/transam/xlogutils.c
+++ b/src/backend/access/transam/xlogutils.c
@@ -394,6 +394,8 @@ CreateFakeRelcacheEntry(RelFileNode rnode)
FakeRelCacheEntry fakeentry;
Relation rel;
+ Assert(InRecovery);
+
/* Allocate the Relation struct and all related space in one block. */
fakeentry = palloc0(sizeof(FakeRelCacheEntryData));
rel = (Relation) fakeentry;
@@ -403,6 +405,9 @@ CreateFakeRelcacheEntry(RelFileNode rnode)
/* We will never be working with temp rels during recovery */
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 */
sprintf(RelationGetRelationName(rel), "%u", rnode.relNode);
diff --git a/src/backend/storage/buffer/bufmgr.c b/src/backend/storage/buffer/bufmgr.c
index a3bf9a4d44e..f1c29e9d4a8 100644
--- a/src/backend/storage/buffer/bufmgr.c
+++ b/src/backend/storage/buffer/bufmgr.c
@@ -271,6 +271,8 @@ ReadBufferWithoutRelcache(RelFileNode rnode, ForkNumber forkNum,
SMgrRelation smgr = smgropen(rnode, InvalidBackendId);
+ Assert(InRecovery);
+
return ReadBuffer_common(smgr, RELPERSISTENCE_PERMANENT, forkNum, blockNum,
mode, strategy, &hit);
}