diff --git a/src/backend/access/common/relation.c b/src/backend/access/common/relation.c
index d8a313a2c9..d5b41b3887 100644
--- a/src/backend/access/common/relation.c
+++ b/src/backend/access/common/relation.c
@@ -35,7 +35,7 @@
  *		If lockmode is not "NoLock", the specified kind of lock is
  *		obtained on the relation.  (Generally, NoLock should only be
  *		used if the caller knows it has some appropriate lock on the
- *		relation already.)
+ *		relation already or the relation is only visible to the caller.)
  *
  *		An error is raised if the relation does not exist.
  *
@@ -61,12 +61,14 @@ relation_open(Oid relationId, LOCKMODE lockmode)
 		elog(ERROR, "could not open relation with OID %u", relationId);
 
 	/*
-	 * If we didn't get the lock ourselves, assert that caller holds one,
-	 * except in bootstrap mode where no locks are used.
+	 * If we didn't get the lock ourselves, assert that caller holds one or
+	 * this relation is created in current trasaction except in bootstrap
+	 * mode where no locks are used.
 	 */
 	Assert(lockmode != NoLock ||
 		   IsBootstrapProcessingMode() ||
-		   CheckRelationLockedByMe(r, AccessShareLock, true));
+		   CheckRelationLockedByMe(r, AccessShareLock, true) ||
+		   OidIsValid(r->rd_createSubid));
 
 	/* Make note that we've accessed a temporary relation */
 	if (RelationUsesLocalBuffers(r))
diff --git a/src/backend/catalog/toasting.c b/src/backend/catalog/toasting.c
index 738bc46ae8..37f73e98bb 100644
--- a/src/backend/catalog/toasting.c
+++ b/src/backend/catalog/toasting.c
@@ -269,8 +269,11 @@ create_toast_table(Relation rel, Oid toastOid, Oid toastIndexOid,
 	/* make the toast relation visible, else table_open will fail */
 	CommandCounterIncrement();
 
-	/* ShareLock is not really needed here, but take it anyway */
-	toast_rel = table_open(toast_relid, ShareLock);
+	/*
+	 * ShareLock is not really needed here, since this is the only transaction
+	 * the relation is visible to.
+	 */
+	toast_rel = table_open(toast_relid, NoLock);
 
 	/*
 	 * Create unique index on chunk_id, chunk_seq.
