Commits

Andrew Dunstan committed 3765d80

Do test after lock is acquired to avoid race condition.

Comments (0)

Files changed (1)

src/backend/catalog/pg_enum.c

 				 errdetail("Labels must be %d characters or less.",
 						   NAMEDATALEN - 1)));
 
+	/*
+	 * Acquire a lock on the enum type, which we won't release until commit.
+	 * This ensures that two backends aren't concurrently modifying the same
+	 * enum type.  Without that, we couldn't be sure to get a consistent view
+	 * of the enum members via the syscache.  Note that this does not block
+	 * other backends from inspecting the type; see comments for
+	 * RenumberEnumType.
+	 */
+	LockDatabaseObject(TypeRelationId, enumTypeOid, 0, ExclusiveLock);
+
 	/* Do the "IF NOT EXISTS" test if specified */
 	if (skipIfExists)
 	{
 		}
 	}
 
-	/*
-	 * Acquire a lock on the enum type, which we won't release until commit.
-	 * This ensures that two backends aren't concurrently modifying the same
-	 * enum type.  Without that, we couldn't be sure to get a consistent view
-	 * of the enum members via the syscache.  Note that this does not block
-	 * other backends from inspecting the type; see comments for
-	 * RenumberEnumType.
-	 */
-	LockDatabaseObject(TypeRelationId, enumTypeOid, 0, ExclusiveLock);
-
 	pg_enum = heap_open(EnumRelationId, RowExclusiveLock);
 
 	/* If we have to renumber the existing members, we restart from here */