From: Robert Haas Date: Fri, 14 Sep 2012 13:35:07 +0000 (-0400) Subject: Properly set relpersistence for fake relcache entries. X-Git-Tag: REL9_1_6~9 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=fef2c17807e095a04441e4f1fe05f75d5578ead2;p=thirdparty%2Fpostgresql.git 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. --- diff --git a/src/backend/access/transam/xlogutils.c b/src/backend/access/transam/xlogutils.c index cbb61bb899d..0932e600a77 100644 --- a/src/backend/access/transam/xlogutils.c +++ b/src/backend/access/transam/xlogutils.c @@ -371,6 +371,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; @@ -380,6 +382,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 5eff617ed7a..d7f78294207 100644 --- a/src/backend/storage/buffer/bufmgr.c +++ b/src/backend/storage/buffer/bufmgr.c @@ -269,6 +269,8 @@ ReadBufferWithoutRelcache(RelFileNode rnode, ForkNumber forkNum, SMgrRelation smgr = smgropen(rnode, InvalidBackendId); + Assert(InRecovery); + return ReadBuffer_common(smgr, RELPERSISTENCE_PERMANENT, forkNum, blockNum, mode, strategy, &hit); }