aboutsummaryrefslogtreecommitdiff
path: root/src/backend/commands/tablespace.c
diff options
context:
space:
mode:
authorTom Lane <tgl@sss.pgh.pa.us>2004-07-11 19:52:52 +0000
committerTom Lane <tgl@sss.pgh.pa.us>2004-07-11 19:52:52 +0000
commit8801110b20c6bffe4724e7b27de1c5e519af1b04 (patch)
tree387b7b294734422a531f1e759ee013d6996778c2 /src/backend/commands/tablespace.c
parent94d4d240bb5c75124a270d1b5fecab1822cd4728 (diff)
downloadpostgresql-8801110b20c6bffe4724e7b27de1c5e519af1b04.tar.gz
postgresql-8801110b20c6bffe4724e7b27de1c5e519af1b04.zip
Move TablespaceCreateDbspace() call into smgrcreate(), which is where it
probably should have been to begin with; this is to cover cases like needing to recreate the per-db directory during WAL replay. Also, fix heap_create to force pg_class.reltablespace to be zero instead of the database's default tablespace; this makes the world safe for CREATE DATABASE to handle all tables in the default tablespace alike, as per previous discussion. And force pg_class.reltablespace to zero when creating a relation without physical storage (eg, a view); this avoids possibly having dangling references in this column after a subsequent DROP TABLESPACE.
Diffstat (limited to 'src/backend/commands/tablespace.c')
-rw-r--r--src/backend/commands/tablespace.c16
1 files changed, 12 insertions, 4 deletions
diff --git a/src/backend/commands/tablespace.c b/src/backend/commands/tablespace.c
index 875fb1cae8a..a08c12305a7 100644
--- a/src/backend/commands/tablespace.c
+++ b/src/backend/commands/tablespace.c
@@ -45,7 +45,7 @@
*
*
* IDENTIFICATION
- * $PostgreSQL: pgsql/src/backend/commands/tablespace.c,v 1.5 2004/07/02 18:59:22 joe Exp $
+ * $PostgreSQL: pgsql/src/backend/commands/tablespace.c,v 1.6 2004/07/11 19:52:49 tgl Exp $
*
*-------------------------------------------------------------------------
*/
@@ -85,9 +85,13 @@ static bool directory_is_empty(const char *path);
*
* If tablespaces are not supported, this is just a no-op; CREATE DATABASE
* is expected to create the default subdirectory for the database.
+ *
+ * isRedo indicates that we are creating an object during WAL replay;
+ * we can skip doing locking in that case (and should do so to avoid
+ * any possible problems with pg_tablespace not being valid).
*/
void
-TablespaceCreateDbspace(Oid spcNode, Oid dbNode)
+TablespaceCreateDbspace(Oid spcNode, Oid dbNode, bool isRedo)
{
#ifdef HAVE_SYMLINK
struct stat st;
@@ -116,7 +120,10 @@ TablespaceCreateDbspace(Oid spcNode, Oid dbNode)
*/
Relation rel;
- rel = heap_openr(TableSpaceRelationName, ExclusiveLock);
+ if (!isRedo)
+ rel = heap_openr(TableSpaceRelationName, ExclusiveLock);
+ else
+ rel = NULL;
/*
* Recheck to see if someone created the directory while
@@ -137,7 +144,8 @@ TablespaceCreateDbspace(Oid spcNode, Oid dbNode)
}
/* OK to drop the exclusive lock */
- heap_close(rel, ExclusiveLock);
+ if (!isRedo)
+ heap_close(rel, ExclusiveLock);
}
else
{