Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Fix incorrect error message for IDENTIFY_SYSTEM
authorDaniel Gustafsson <dgustafsson@postgresql.org>
Tue, 5 Dec 2023 13:30:56 +0000 (14:30 +0100)
committerDaniel Gustafsson <dgustafsson@postgresql.org>
Tue, 5 Dec 2023 13:30:56 +0000 (14:30 +0100)
Commit 5a991ef8692e accidentally reversed the order of the tuples
and fields parameters, making the error message incorrectly refer
to 3 tuples with 1 field when IDENTIFY_SYSTEM returns 1 tuple and
3 or 4 fields. Fix by changing the order of the parameters.  This
also adds a comment describing why we check for < 3 when postgres
since 9.4 has been sending 4 fields.

Backpatch all the way since the bug is almost a decade old.

Author: Tomonari Katsumata <t.katsumata1122@gmail.com>
Reviewed-by: Tom Lane <tgl@sss.pgh.pa.us>
Bug: #18224
Backpatch-through: v12

src/backend/replication/libpqwalreceiver/libpqwalreceiver.c

index 0e64d5ce208dbf4d9c671e89833e55a4a5dd4794..4fc14126b55e64592851d1eb0fc2e79fad81f424 100644 (file)
@@ -356,6 +356,10 @@ libpqrcv_identify_system(WalReceiverConn *conn, TimeLineID *primary_tli)
                        "the primary server: %s",
                        pchomp(PQerrorMessage(conn->streamConn)))));
    }
+   /*
+    * IDENTIFY_SERVER returns 3 columns in 9.3 and earlier, and 4 columns in
+    * 9.4 and onwards.
+    */
    if (PQnfields(res) < 3 || PQntuples(res) != 1)
    {
        int         ntuples = PQntuples(res);
@@ -365,7 +369,7 @@ libpqrcv_identify_system(WalReceiverConn *conn, TimeLineID *primary_tli)
        ereport(ERROR,
                (errmsg("invalid response from primary server"),
                 errdetail("Could not identify system: got %d rows and %d fields, expected %d rows and %d or more fields.",
-                          ntuples, nfields, 3, 1)));
+                          ntuples, nfields, 1, 3)));
    }
    primary_sysid = pstrdup(PQgetvalue(res, 0, 0));
    *primary_tli = pg_strtoint32(PQgetvalue(res, 0, 1));