diff --git a/src/backend/storage/smgr/md.c b/src/backend/storage/smgr/md.c index 84cfd70..0a733dc 100644 --- a/src/backend/storage/smgr/md.c +++ b/src/backend/storage/smgr/md.c @@ -19,6 +19,7 @@ #include #include "catalog/catalog.h" +#include "commands/tablespace.h" #include "miscadmin.h" #include "postmaster/bgwriter.h" #include "storage/fd.h" @@ -253,6 +254,14 @@ mdcreate(SMgrRelation reln, ForkNumber forkNum, bool isRedo) Assert(reln->md_fd[forkNum] == NULL); + /* + * We may be using the target table space for the first time in this + * database, so create a per-database subdirectory if needed. + */ + TablespaceCreateDbspace(reln->smgr_rnode.node.spcNode, + reln->smgr_rnode.node.dbNode, + isRedo); + path = relpath(reln->smgr_rnode, forkNum); fd = PathNameOpenFile(path, O_RDWR | O_CREAT | O_EXCL | PG_BINARY, 0600); diff --git a/src/backend/storage/smgr/smgr.c b/src/backend/storage/smgr/smgr.c index b560625..f4319c4 100644 --- a/src/backend/storage/smgr/smgr.c +++ b/src/backend/storage/smgr/smgr.c @@ -19,7 +19,6 @@ #include "access/xlogutils.h" #include "catalog/catalog.h" -#include "commands/tablespace.h" #include "storage/bufmgr.h" #include "storage/ipc.h" #include "storage/smgr.h" @@ -290,25 +289,6 @@ smgrclosenode(RelFileNodeBackend rnode) void smgrcreate(SMgrRelation reln, ForkNumber forknum, bool isRedo) { - /* - * Exit quickly in WAL replay mode if we've already opened the file. If - * it's open, it surely must exist. - */ - if (isRedo && reln->md_fd[forknum] != NULL) - return; - - /* - * We may be using the target table space for the first time in this - * database, so create a per-database subdirectory if needed. - * - * XXX this is a fairly ugly violation of module layering, but this seems - * to be the best place to put the check. Maybe TablespaceCreateDbspace - * should be here and not in commands/tablespace.c? But that would imply - * importing a lot of stuff that smgr.c oughtn't know, either. - */ - TablespaceCreateDbspace(reln->smgr_rnode.node.spcNode, - reln->smgr_rnode.node.dbNode, - isRedo); (*(smgrsw[reln->smgr_which].smgr_create)) (reln, forknum, isRedo); }