Skip to content

Commit f4ab856

Browse files
committed
Doc: improve protocol spec for logical replication Type messages.
protocol.sgml documented the layout for Type messages, but completely dropped the ball otherwise, failing to explain what they are, when they are sent, or what they're good for. While at it, do a little copy-editing on the description of Relation messages. In passing, adjust the comment for apply_handle_type() to make it clearer that we choose not to do anything when receiving a Type message, not that we think it has no use whatsoever. Per question from Stefen Hillman. Discussion: https://postgr.es/m/CAPgW8pMknK5pup6=T4a_UG=Cz80Rgp=KONqJmTdHfaZb0RvnFg@mail.gmail.com
1 parent 4dc2cb7 commit f4ab856

File tree

2 files changed

+23
-8
lines changed

2 files changed

+23
-8
lines changed

doc/src/sgml/protocol.sgml

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2756,13 +2756,25 @@ The commands accepted in replication mode are:
27562756
</para>
27572757

27582758
<para>
2759-
Every DML message contains an arbitrary relation ID, which can be mapped to
2760-
an ID in the Relation messages. The Relation messages describe the schema of the
2761-
given relation. The Relation message is sent for a given relation either
2762-
because it is the first time we send a DML message for given relation in the
2763-
current session or because the relation definition has changed since the
2764-
last Relation message was sent for it. The protocol assumes that the client
2765-
is capable of caching the metadata for as many relations as needed.
2759+
Every DML message contains a relation OID, identifying the publisher's
2760+
relation that was acted on. Before the first DML message for a given
2761+
relation OID, a Relation message will be sent, describing the schema of
2762+
that relation. Subsequently, a new Relation message will be sent if
2763+
the relation's definition has changed since the last Relation message
2764+
was sent for it. (The protocol assumes that the client is capable of
2765+
remembering this metadata for as many relations as needed.)
2766+
</para>
2767+
2768+
<para>
2769+
Relation messages identify column types by their OIDs. In the case
2770+
of a built-in type, it is assumed that the client can look up that
2771+
type OID locally, so no additional data is needed. For a non-built-in
2772+
type OID, a Type message will be sent before the Relation message,
2773+
to provide the type name associated with that OID. Thus, a client that
2774+
needs to specifically identify the types of relation columns should
2775+
cache the contents of Type messages, and first consult that cache to
2776+
see if the type OID is defined there. If not, look up the type OID
2777+
locally.
27662778
</para>
27672779
</sect2>
27682780
</sect1>

src/backend/replication/logical/worker.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -578,7 +578,10 @@ apply_handle_relation(StringInfo s)
578578
/*
579579
* Handle TYPE message.
580580
*
581-
* This is now vestigial; we read the info and discard it.
581+
* This implementation pays no attention to TYPE messages; we expect the user
582+
* to have set things up so that the incoming data is acceptable to the input
583+
* functions for the locally subscribed tables. Hence, we just read and
584+
* discard the message.
582585
*/
583586
static void
584587
apply_handle_type(StringInfo s)

0 commit comments

Comments
 (0)