diff --git a/src/backend/tcop/postgres.c b/src/backend/tcop/postgres.c
index 7a9ada2c71..daa6228535 100644
--- a/src/backend/tcop/postgres.c
+++ b/src/backend/tcop/postgres.c
@@ -1116,16 +1116,28 @@ exec_simple_query(const char *query_string)
 		 */
 		MemoryContextSwitchTo(oldcontext);
 
-		/*
-		 * Run the portal to completion, and then drop it (and the receiver).
-		 */
-		(void) PortalRun(portal,
-						 FETCH_ALL,
-						 true,	/* always top level */
-						 true,
-						 receiver,
-						 receiver,
-						 completionTag);
+		PG_TRY();
+		{
+			/*
+			 * Run the portal to completion, and then drop it (and the receiver).
+			 */
+			(void) PortalRun(portal,
+							 FETCH_ALL,
+							 true,	/* always top level */
+							 true,
+							 receiver,
+							 receiver,
+							 completionTag);
+		}
+		PG_CATCH();
+		{
+			receiver->rDestroy(receiver);
+
+			PortalDrop(portal, false);
+
+			PG_RE_THROW();
+		}
+		PG_END_TRY();
 
 		receiver->rDestroy(receiver);
