diff --git a/lib/modules/Sql.pmod/pgsql_util.pmod b/lib/modules/Sql.pmod/pgsql_util.pmod
index 3e17ddc331c411e4b00bf62b2c01efbd12be8533..e2bc80339b0f12c7caa0633285da03774a43b0ab 100644
--- a/lib/modules/Sql.pmod/pgsql_util.pmod
+++ b/lib/modules/Sql.pmod/pgsql_util.pmod
@@ -2468,11 +2468,11 @@ class proxy {
   final void close() {
     throwdelayederror(this);
     {
-      Thread.MutexKey lock = shortmux->lock();
-      portalsinflight->wait_till_drained(lock);	// Drain portal queue to completion
-      lock = 0;
+      Thread.MutexKey lock;
       if (unnamedstatement)
         termlock = unnamedstatement->lock(1);
+      foreach (c->runningportals; Result result; )
+        catch(result->status_command_complete());
       if (c)				// Prevent trivial backtraces
         c->close();
       if (unnamedstatement)