diff --git a/src/backend/catalog/pg_operator.c b/src/backend/catalog/pg_operator.c index 6dde75ed25..acca443fb5 100644 --- a/src/backend/catalog/pg_operator.c +++ b/src/backend/catalog/pg_operator.c @@ -30,6 +30,7 @@ #include "catalog/pg_type.h" #include "miscadmin.h" #include "parser/parse_oper.h" +#include "storage/lmgr.h" #include "utils/acl.h" #include "utils/builtins.h" #include "utils/lsyscache.h" @@ -502,6 +503,9 @@ OperatorCreate(const char *operatorName, values[Anum_pg_operator_oprrest - 1] = ObjectIdGetDatum(restrictionId); values[Anum_pg_operator_oprjoin - 1] = ObjectIdGetDatum(joinId); + /* Lock the creation namespace to protect against concurrent namespace drop */ + LockDatabaseObject(NamespaceRelationId, operatorNamespace, 0, AccessShareLock); + pg_operator_desc = heap_open(OperatorRelationId, RowExclusiveLock); /* diff --git a/src/backend/catalog/pg_proc.c b/src/backend/catalog/pg_proc.c index 0c817047cd..fca9099f1b 100644 --- a/src/backend/catalog/pg_proc.c +++ b/src/backend/catalog/pg_proc.c @@ -31,6 +31,7 @@ #include "miscadmin.h" #include "nodes/nodeFuncs.h" #include "parser/parse_type.h" +#include "storage/lmgr.h" #include "tcop/pquery.h" #include "tcop/tcopprot.h" #include "utils/acl.h" @@ -360,6 +361,9 @@ ProcedureCreate(const char *procedureName, nulls[Anum_pg_proc_proconfig - 1] = true; /* proacl will be determined later */ + /* Lock the creation namespace to protect against concurrent namespace drop */ + LockDatabaseObject(NamespaceRelationId, procNamespace, 0, AccessShareLock); + rel = heap_open(ProcedureRelationId, RowExclusiveLock); tupDesc = RelationGetDescr(rel); diff --git a/src/backend/catalog/pg_type.c b/src/backend/catalog/pg_type.c index 2ddd46d48e..301e93df1a 100644 --- a/src/backend/catalog/pg_type.c +++ b/src/backend/catalog/pg_type.c @@ -28,6 +28,7 @@ #include "commands/typecmds.h" #include "miscadmin.h" #include "parser/scansup.h" +#include "storage/lmgr.h" #include "utils/acl.h" #include "utils/builtins.h" #include "utils/fmgroids.h" @@ -66,6 +67,9 @@ TypeShellMake(const char *typeName, Oid typeNamespace, Oid ownerId) Assert(PointerIsValid(typeName)); + /* Lock the creation namespace to protect against concurrent namespace drop */ + LockDatabaseObject(NamespaceRelationId, typeNamespace, 0, AccessShareLock); + /* * open pg_type */ @@ -386,6 +390,9 @@ TypeCreate(Oid newTypeOid, else nulls[Anum_pg_type_typacl - 1] = true; + /* Lock the creation namespace to protect against concurrent namespace drop */ + LockDatabaseObject(NamespaceRelationId, typeNamespace, 0, AccessShareLock); + /* * open pg_type and prepare to insert or update a row. * diff --git a/src/backend/commands/opclasscmds.c b/src/backend/commands/opclasscmds.c index 3b5c90e3f4..97d7153f61 100644 --- a/src/backend/commands/opclasscmds.c +++ b/src/backend/commands/opclasscmds.c @@ -43,6 +43,7 @@ #include "parser/parse_func.h" #include "parser/parse_oper.h" #include "parser/parse_type.h" +#include "storage/lmgr.h" #include "utils/builtins.h" #include "utils/fmgroids.h" #include "utils/lsyscache.h" @@ -250,6 +251,9 @@ CreateOpFamily(const char *amname, const char *opfname, Oid namespaceoid, Oid am ObjectAddress myself, referenced; + /* Lock the creation namespace to protect against concurrent namespace drop */ + LockDatabaseObject(NamespaceRelationId, namespaceoid, 0, AccessShareLock); + rel = heap_open(OperatorFamilyRelationId, RowExclusiveLock); /* @@ -577,6 +581,9 @@ DefineOpClass(CreateOpClassStmt *stmt) stmt->amname))); } + /* Lock the creation namespace to protect against concurrent namespace drop */ + LockDatabaseObject(NamespaceRelationId, namespaceoid, 0, AccessShareLock); + rel = heap_open(OperatorClassRelationId, RowExclusiveLock); /*