On Thu, Oct  8, 2020 at 11:17:59PM -0400, Bruce Momjian wrote:
> Good point.  The reporter was assuming the data would come to the client
> in the bytea output format specified by the GUC, e.g. \x..., so that
> doesn't happen either.  As I said before, it is more raw bytes, but we
> don't have an SQL data type for that.

I did some more research on this.  It turns out timeline 'content' is
the only BYTEA listed in the protocol docs, even though it just passes C
strings to pq_sendbytes(), just like many other fields like the field
above it, the timeline history filename.  The proper fix is to change
the code to return the timeline history file contents as TEXT instead of
BYTEA.

Patch attached.  I would like to backpatch this to all supported
versions so we are consistent and people don't think different PG
versions use different return values for this.  Is that safe?  Looking
at the uses of this in our code, it seems so.  We aren't doing BYTEA
escaping or TEXT encoding conversion in any of these cases.

-- 
  Bruce Momjian  <br...@momjian.us>        https://momjian.us
  EnterpriseDB                             https://enterprisedb.com

  The usefulness of a cup is in its emptiness, Bruce Lee

diff --git a/doc/src/sgml/protocol.sgml b/doc/src/sgml/protocol.sgml
index f5e3318106..612c59e2c6 100644
--- a/doc/src/sgml/protocol.sgml
+++ b/doc/src/sgml/protocol.sgml
@@ -1877,7 +1877,7 @@ The commands accepted in replication mode are:
 
       <varlistentry>
       <term>
-       <literal>content</literal> (<type>bytea</type>)
+       <literal>content</literal> (<type>text</type>)
       </term>
       <listitem>
       <para>
diff --git a/src/backend/replication/walsender.c b/src/backend/replication/walsender.c
index 7c9d1b67df..7db8975065 100644
--- a/src/backend/replication/walsender.c
+++ b/src/backend/replication/walsender.c
@@ -496,7 +496,7 @@ SendTimeLineHistory(TimeLineHistoryCmd *cmd)
 	pq_sendstring(&buf, "content"); /* col name */
 	pq_sendint32(&buf, 0);		/* table oid */
 	pq_sendint16(&buf, 0);		/* attnum */
-	pq_sendint32(&buf, BYTEAOID);	/* type oid */
+	pq_sendint32(&buf, TEXTOID);	/* type oid */
 	pq_sendint16(&buf, -1);		/* typlen */
 	pq_sendint32(&buf, 0);		/* typmod */
 	pq_sendint16(&buf, 0);		/* format code */

Reply via email to