*** a/src/backend/commands/indexcmds.c
--- b/src/backend/commands/indexcmds.c
*************** DefineIndex(Oid relationId,
*** 915,920 ****
--- 915,926 ----
  				int			maplen;
  
  				childrel = heap_open(childRelid, lockmode);
+ 				/* Foreign table doesn't need indexes */
+ 				if (childrel->rd_rel->relkind == RELKIND_FOREIGN_TABLE)
+ 				{
+ 					heap_close(childrel, NoLock);
+ 					continue;
+ 				}
  				childidxs = RelationGetIndexList(childrel);
  				attmap =
  					convert_tuples_by_name_map(RelationGetDescr(childrel),
*** a/src/backend/commands/tablecmds.c
--- b/src/backend/commands/tablecmds.c
*************** AttachPartitionEnsureIndexes(Relation re
*** 14352,14357 ****
--- 14352,14361 ----
  	MemoryContext cxt;
  	MemoryContext oldcxt;
  
+ 	/* Foreign table doesn't need indexes */
+ 	if (attachrel->rd_rel->relkind == RELKIND_FOREIGN_TABLE)
+ 		return;
+ 
  	cxt = AllocSetContextCreate(CurrentMemoryContext,
  								"AttachPartitionEnsureIndexes",
  								ALLOCSET_DEFAULT_SIZES);
