Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 303e46e

Browse files
committed
Tweak md.c logic to cope with the situation where WAL replay tries to
write into a high-numbered segment of a relation that was later deleted. We need to temporarily recreate missing segment files, instead of failing.
1 parent 09c6ac9 commit 303e46e

File tree

1 file changed

+11
-2
lines changed
  • src/backend/storage/smgr

1 file changed

+11
-2
lines changed

src/backend/storage/smgr/md.c

+11-2
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $PostgreSQL: pgsql/src/backend/storage/smgr/md.c,v 1.111 2004/08/30 02:54:39 momjian Exp $
11+
* $PostgreSQL: pgsql/src/backend/storage/smgr/md.c,v 1.112 2004/08/30 03:52:43 tgl Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -937,10 +937,19 @@ _mdfd_getseg(SMgrRelation reln, BlockNumber blkno, bool allowNotFound)
937937
* "target" block. We should never need to create more than
938938
* one new segment per call, so this restriction seems
939939
* reasonable.
940+
*
941+
* BUT: when doing WAL recovery, disable this logic and create
942+
* segments unconditionally. In this case it seems better
943+
* to assume the given blkno is good (it presumably came from
944+
* a CRC-checked WAL record); furthermore this lets us cope
945+
* in the case where we are replaying WAL data that has a write
946+
* into a high-numbered segment of a relation that was later
947+
* deleted. We want to go ahead and create the segments so
948+
* we can finish out the replay.
940949
*/
941950
v->mdfd_chain = _mdfd_openseg(reln,
942951
nextsegno,
943-
(segstogo == 1) ? O_CREAT : 0);
952+
(segstogo == 1 || InRecovery) ? O_CREAT : 0);
944953
if (v->mdfd_chain == NULL)
945954
{
946955
if (allowNotFound && errno == ENOENT)

0 commit comments

Comments
 (0)