Skip to content

Commit 0ef3c29

Browse files
committed
Improve documentation about binary/textual output mode for output plugins.
Also improve related error message as it contributed to the confusion. Discussion: CAB7nPqQrqFzjqCjxu4GZzTrD9kpj6HMn9G5aOOMwt1WZ8NfqeA@mail.gmail.com, CAB7nPqQXc_+g95zWnqaa=mVQ4d3BVRs6T41frcEYi2ocUrR3+A@mail.gmail.com Per discussion between Michael Paquier, Robert Haas and Andres Freund Backpatch to 9.4 where logical decoding was introduced.
1 parent ef88638 commit 0ef3c29

File tree

3 files changed

+24
-3
lines changed

3 files changed

+24
-3
lines changed

contrib/test_decoding/expected/binary.out

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ SELECT data FROM pg_logical_slot_get_changes('regression_slot', NULL, NULL, 'for
1414

1515
-- fails, binary plugin, textual consumer
1616
SELECT data FROM pg_logical_slot_get_changes('regression_slot', NULL, NULL, 'force-binary', '1');
17-
ERROR: output plugin cannot produce binary output
17+
ERROR: logical decoding output plugin "test_decoding" produces binary output, but "pg_logical_slot_get_changes(name,pg_lsn,integer,text[])" expects textual data
1818
-- succeeds, textual plugin, binary consumer
1919
SELECT data FROM pg_logical_slot_get_binary_changes('regression_slot', NULL, NULL, 'force-binary', '0');
2020
data

doc/src/sgml/logicaldecoding.sgml

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -355,6 +355,24 @@ CREATE TABLE another_catalog_table(data text) WITH (user_catalog_table = true);
355355
</para>
356356
</sect2>
357357

358+
<sect2 id="logicaldecoding-output-mode">
359+
<title>Output Modes</title>
360+
<para>
361+
Output plugin callbacks can pass data to the consumer in nearly arbitrary
362+
formats. For some use cases, like viewing the changes via SQL, returning
363+
data in a datatype that can contain arbitrary data (i.e. bytea) is
364+
cumbersome. If the output plugin only outputs textual data in the
365+
server's encoding it can declare that by
366+
setting <literal>OutputPluginOptions.output_mode</>
367+
to <literal>OUTPUT_PLUGIN_TEXTUAL_OUTPUT</> instead
368+
of <literal>OUTPUT_PLUGIN_BINARY_OUTPUT</> in
369+
the <link linkend="logicaldecoding-output-plugin-startup">startup
370+
callback</>. In that case all the data has to be in the server's encoding
371+
so a <type>text</> can contain it. This is checked in assertion enabled
372+
builds.
373+
</para>
374+
</sect2>
375+
358376
<sect2 id="logicaldecoding-output-plugin-callbacks">
359377
<title>Output Plugin Callbacks</title>
360378
<para>
@@ -405,7 +423,8 @@ typedef struct OutputPluginOptions
405423
</programlisting>
406424
<literal>output_type</literal> has to either be set to
407425
<literal>OUTPUT_PLUGIN_TEXTUAL_OUTPUT</literal>
408-
or <literal>OUTPUT_PLUGIN_BINARY_OUTPUT</literal>.
426+
or <literal>OUTPUT_PLUGIN_BINARY_OUTPUT</literal>. See also
427+
<xref linkend="logicaldecoding-output-mode"/>.
409428
</para>
410429
<para>
411430
The startup callback should validate the options present in

src/backend/replication/logical/logicalfuncs.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -401,7 +401,9 @@ pg_logical_slot_get_changes_guts(FunctionCallInfo fcinfo, bool confirm, bool bin
401401
ctx->options.output_type != OUTPUT_PLUGIN_TEXTUAL_OUTPUT)
402402
ereport(ERROR,
403403
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
404-
errmsg("output plugin cannot produce binary output")));
404+
errmsg("logical decoding output plugin \"%s\" produces binary output, but \"%s\" expects textual data",
405+
NameStr(MyReplicationSlot->data.plugin),
406+
format_procedure(fcinfo->flinfo->fn_oid))));
405407

406408
ctx->output_writer_private = p;
407409

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy