From a16a6ba270e5b1faf3b8ea43bd75a66b31a811c4 Mon Sep 17 00:00:00 2001
From: Andres Freund <andres@anarazel.de>
Date: Sun, 22 Feb 2015 22:30:56 +0100
Subject: [PATCH 1/3] Reduce strength of assert in mdcreate() to work correctly
 during bootstrap.

---
 src/backend/storage/smgr/md.c | 15 ++++++++-------
 1 file changed, 8 insertions(+), 7 deletions(-)

diff --git a/src/backend/storage/smgr/md.c b/src/backend/storage/smgr/md.c
index b754d3b..dbfa0ce 100644
--- a/src/backend/storage/smgr/md.c
+++ b/src/backend/storage/smgr/md.c
@@ -290,7 +290,13 @@ mdcreate(SMgrRelation reln, ForkNumber forkNum, bool isRedo)
 	char	   *path;
 	File		fd;
 
-	if (isRedo && reln->md_fd[forkNum] != NULL)
+	/*
+	 * During bootstrap, there are cases where a system relation will be
+	 * accessed (by internal backend processes) before the bootstrap
+	 * script nominally creates it.  Therefore, allow the file to exist
+	 * already, even if isRedo is not set.  (See also mdopen)
+	 */
+	if ((IsBootstrapProcessingMode() || isRedo) && reln->md_fd[forkNum] != NULL)
 		return;					/* created and opened already... */
 
 	Assert(reln->md_fd[forkNum] == NULL);
@@ -303,12 +309,7 @@ mdcreate(SMgrRelation reln, ForkNumber forkNum, bool isRedo)
 	{
 		int			save_errno = errno;
 
-		/*
-		 * During bootstrap, there are cases where a system relation will be
-		 * accessed (by internal backend processes) before the bootstrap
-		 * script nominally creates it.  Therefore, allow the file to exist
-		 * already, even if isRedo is not set.  (See also mdopen)
-		 */
+		/* see comment above */
 		if (isRedo || IsBootstrapProcessingMode())
 			fd = PathNameOpenFile(path, O_RDWR | PG_BINARY, 0600);
 		if (fd < 0)
-- 
2.10.2

