diff --git a/src/bin/psql/copy.c b/src/bin/psql/copy.c
index dbbbdb8898..2b9c278ef7 100644
--- a/src/bin/psql/copy.c
+++ b/src/bin/psql/copy.c
@@ -505,7 +505,7 @@ handleCopyOut(PGconn *conn, FILE *copystream, PGresult **res)
  */
 
 /* read chunk size for COPY IN - size is not critical */
-#define COPYBUFSIZ 8192
+#define COPYBUFSIZ 32768
 
 bool
 handleCopyIn(PGconn *conn, FILE *copystream, bool isbinary, PGresult **res)
@@ -531,6 +531,8 @@ handleCopyIn(PGconn *conn, FILE *copystream, bool isbinary, PGresult **res)
 		goto copyin_cleanup;
 	}
 
+	(void) PQsetnonblocking(conn, 1);
+
 	/* Prompt if interactive input */
 	if (isatty(fileno(copystream)))
 	{
@@ -649,16 +651,17 @@ handleCopyIn(PGconn *conn, FILE *copystream, bool isbinary, PGresult **res)
 			}
 
 			/*
-			 * If the buffer is full, or we've reached the EOF, flush it.
-			 *
-			 * Make sure there's always space for four more bytes in the
-			 * buffer, plus a NUL terminator.  That way, an EOF marker is
-			 * never split across two fgets() calls, which simplifies the
-			 * logic.
+			 * Flush after every line for test purposes.
 			 */
-			if (buflen >= COPYBUFSIZ - 5 || (copydone && buflen > 0))
+			if (buflen > 0)
 			{
-				if (PQputCopyData(conn, buf, buflen) <= 0)
+				int pcdres;
+
+				while ((pcdres = PQputCopyData(conn, buf, buflen)) == 0)
+				{
+					/* busy-wait */
+				}
+				if (pcdres < 0)
 				{
 					OK = false;
 					break;
@@ -686,6 +689,8 @@ handleCopyIn(PGconn *conn, FILE *copystream, bool isbinary, PGresult **res)
 
 copyin_cleanup:
 
+	(void) PQsetnonblocking(conn, 0);
+
 	/*
 	 * Clear the EOF flag on the stream, in case copying ended due to an EOF
 	 * signal.  This allows an interactive TTY session to perform another COPY
diff --git a/src/test/kerberos/t/001_auth.pl b/src/test/kerberos/t/001_auth.pl
index 0deb9bffc8..711bbc1e29 100644
--- a/src/test/kerberos/t/001_auth.pl
+++ b/src/test/kerberos/t/001_auth.pl
@@ -419,6 +419,25 @@ test_query(
 	'gssencmode=require',
 	'sending 100K lines works');
 
+my $bigdata = '';
+for (my $rpt = 0; $rpt < 1000; $rpt++)
+{
+	$bigdata .= 'xyzzy' x (27*1024/5) . "\n";
+	$bigdata .= 'qwert' x (180/5) . "\n";
+}
+
+test_query(
+	$node,
+	'test1',
+	"CREATE TEMP TABLE mytab (f1 text);\n"
+	  . "COPY mytab FROM STDIN;\n"
+	  . $bigdata
+	  . "\\.\n"
+	  . "SELECT COUNT(*) FROM mytab;",
+	qr/^2000$/s,
+	'gssencmode=require',
+	'sending alternating-size lines works');
+
 # require_auth=gss succeeds if required.
 $node->connect_ok(
 	$node->connstr('postgres')
