diff --git a/src/bin/psql/copy.c b/src/bin/psql/copy.c
index 9adbed1811c7038af498b73ed3c2d03461a1cefd..623ed36ae0b80b0ce5826e3ce528412012d4b30c 100644
--- a/src/bin/psql/copy.c
+++ b/src/bin/psql/copy.c
@@ -3,7 +3,7 @@
  *
  * Copyright (c) 2000-2006, PostgreSQL Global Development Group
  *
- * $PostgreSQL: pgsql/src/bin/psql/copy.c,v 1.70 2006/10/06 17:14:00 petere Exp $
+ * $PostgreSQL: pgsql/src/bin/psql/copy.c,v 1.71 2006/11/24 23:06:50 tgl Exp $
  */
 #include "postgres_fe.h"
 #include "copy.h"
@@ -598,6 +598,18 @@ do_copy(const char *args)
 
 	PQclear(result);
 
+	/*
+	 * Make sure we have pumped libpq dry of results; else it may still be
+	 * in ASYNC_BUSY state, leading to false readings in, eg, get_prompt().
+	 */
+	while ((result = PQgetResult(pset.db)) != NULL)
+	{
+		success = false;
+		psql_error("\\copy: unexpected response (%d)\n",
+				   PQresultStatus(result));
+		PQclear(result);
+	}
+
 	if (options->file != NULL)
 	{
 		if (fclose(copystream) != 0)