I added a result set to START_STREAMING command, but neglected walreceiver.
authorHeikki Linnakangas <[email protected]>
Thu, 17 Jan 2013 21:12:30 +0000 (23:12 +0200)
committerHeikki Linnakangas <[email protected]>
Thu, 17 Jan 2013 21:45:45 +0000 (23:45 +0200)
The patch to allow pg_receivexlog to switch timeline added a result set
after copy has ended in START_STREAMING command, to return the next
timeline's ID to the client. But walreceived didn't get the memo, and threw
an error on the unexpected result set. Fix.

src/backend/replication/libpqwalreceiver/libpqwalreceiver.c
src/backend/replication/walreceiver.c

index 7374489b4035e2115b49776b7a40770b61c376f7..84ab25b0e2a5666d310305128124b0bee0534148 100644 (file)
@@ -215,17 +215,27 @@ libpqrcv_endstreaming(void)
 
        while ((res = PQgetResult(streamConn)) != NULL)
        {
-               if (PQresultStatus(res) != PGRES_COMMAND_OK)
-                       ereport(ERROR,
-                                       (errmsg("error reading result of streaming command: %s",
-                                                       PQerrorMessage(streamConn))));
                /*
+                * After Copy, if the streaming ended because we reached end of the
+                * timeline, server sends one result set with the next timeline's ID.
+                * We don't need it, so just slurp and ignore it.
+                *
                 * If we had not yet received CopyDone from the backend, PGRES_COPY_IN
                 * is also possible. However, at the moment this function is only
                 * called after receiving CopyDone from the backend - the walreceiver
                 * never terminates replication on its own initiative.
                 */
-
+               switch (PQresultStatus(res))
+               {
+                       case PGRES_COMMAND_OK:
+                       case PGRES_TUPLES_OK:
+                               break;
+
+                       default:
+                               ereport(ERROR,
+                                               (errmsg("error reading result of streaming command: %s",
+                                                               PQerrorMessage(streamConn))));
+               }
                PQclear(res);
        }
 }
index 16cf9444a575719e0be179475ddadd1923d5ee29..444be9463bc7dd50297bcabc9944ef662993b855 100644 (file)
@@ -431,7 +431,9 @@ WalReceiverMain(void)
                                                {
                                                        ereport(LOG,
                                                                        (errmsg("replication terminated by primary server"),
-                                                                        errdetail("End of WAL reached on timeline %u", startpointTLI)));
+                                                                        errdetail("End of WAL reached on timeline %u at %X/%X",
+                                                                                          startpointTLI,
+                                                                                          (uint32) (LogstreamResult.Write >> 32), (uint32) LogstreamResult.Write)));
                                                        endofwal = true;
                                                        break;
                                                }