Try to defend against the possibility that libpq is still in COPY_IN state
authorTom Lane <[email protected]>
Fri, 7 Aug 2009 20:16:49 +0000 (20:16 +0000)
committerTom Lane <[email protected]>
Fri, 7 Aug 2009 20:16:49 +0000 (20:16 +0000)
when we reach the post-COPY "pump it dry" error recovery code that was added
2006-11-24.  Per a report from Neil Best, there is at least one code path
in which this occurs, leading to an infinite loop in code that's supposed
to be making it more robust not less so.  A reasonable response seems to be
to call PQputCopyEnd() again, so let's try that.

Back-patch to all versions that contain the cleanup loop.

src/bin/psql/copy.c

index 925940e84d49e3e45c0af9926eaaa79bdb64db2e..6742987ae5d90310c7713e66d56a5ddbf9a2be21 100644 (file)
@@ -3,7 +3,7 @@
  *
  * Copyright (c) 2000-2003, PostgreSQL Global Development Group
  *
- * $Header: /cvsroot/pgsql/src/bin/psql/copy.c,v 1.33.4.2 2006/11/24 23:07:07 tgl Exp $
+ * $Header: /cvsroot/pgsql/src/bin/psql/copy.c,v 1.33.4.3 2009/08/07 20:16:49 tgl Exp $
  */
 #include "postgres_fe.h"
 #include "copy.h"
@@ -425,6 +425,9 @@ do_copy(const char *args)
                success = false;
                psql_error("\\copy: unexpected response (%d)\n",
                                   PQresultStatus(result));
+               /* if still in COPY IN state, try to get out of it */
+               if (PQresultStatus(result) == PGRES_COPY_IN)
+                       PQputCopyEnd(pset.db, gettext("trying to exit copy mode"));
                PQclear(result);
        }