diff --git a/src/backend/commands/extension.c b/src/backend/commands/extension.c
index 9b9bb7dc8f046c5e0972a7b8a80d454c7ffea60c..d591bf00f969bb5a3b1a17a7f35b7bd8d0925361 100644
--- a/src/backend/commands/extension.c
+++ b/src/backend/commands/extension.c
@@ -40,6 +40,7 @@
 #include "commands/alter.h"
 #include "commands/comment.h"
 #include "commands/extension.h"
+#include "commands/schemacmds.h"
 #include "commands/trigger.h"
 #include "executor/executor.h"
 #include "funcapi.h"
@@ -1370,9 +1371,18 @@ CreateExtension(CreateExtensionStmt *stmt)
 
 		if (schemaOid == InvalidOid)
 		{
-			schemaOid = NamespaceCreate(schemaName, extowner);
-			/* Advance cmd counter to make the namespace visible */
-			CommandCounterIncrement();
+			CreateSchemaStmt *csstmt = makeNode(CreateSchemaStmt);
+
+			csstmt->schemaname = schemaName;
+			csstmt->authid = NULL;		/* will be created by current user */
+			csstmt->schemaElts = NIL;
+			CreateSchemaCommand(csstmt, NULL);
+
+			/*
+			 * CreateSchemaCommand includes CommandCounterIncrement, so new
+			 * schema is now visible
+			 */
+			schemaOid = get_namespace_oid(schemaName, false);
 		}
 	}
 	else