diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index f97bee5..6322fa7 100644
*** a/src/backend/commands/tablecmds.c
--- b/src/backend/commands/tablecmds.c
*************** ATExecDropConstraint(Relation rel, const
*** 7723,7728 ****
--- 7723,7746 ----
  		is_no_inherit_constraint = con->connoinherit;
  
  		/*
+ 		 * If it's a foreign-key constraint, we'd better lock the referenced
+ 		 * table and check that that's not in use, just as we've already done
+ 		 * for the constrained table (else we might, eg, be dropping a trigger
+ 		 * that has unfired events).  But we can/must skip that in the
+ 		 * self-referential case.
+ 		 */
+ 		if (con->contype == CONSTRAINT_FOREIGN &&
+ 			con->confrelid != RelationGetRelid(rel))
+ 		{
+ 			Relation	frel;
+ 
+ 			/* Must match lock taken by RemoveTriggerById: */
+ 			frel = heap_open(con->confrelid, AccessExclusiveLock);
+ 			CheckTableNotInUse(frel, "ALTER TABLE");
+ 			heap_close(frel, NoLock);
+ 		}
+ 
+ 		/*
  		 * Perform the actual constraint deletion
  		 */
  		conobj.classId = ConstraintRelationId;
