On Thu, 19 Jun 2025 at 13:51, Tatsuo Ishii <ishii@postgresql.org> wrote:
> > FWIW my reading of the protocol docs is that BackendKeyData is
> > optional.
>
> If majority of developers think so, do we want to update the protocol
> docs? For me the docs is not clear enough.
I think the docs currently definitely suggests that BackendKeyData
will always be sent (emphasis mine):
> After having received AuthenticationOk, the frontend must wait for further messages from the server. In this phase a
backendprocess is being started, and the frontend is just an interested bystander. It is still possible for the startup
attemptto fail (ErrorResponse) or the server to decline support for the requested minor protocol version
(NegotiateProtocolVersion),*but in the normal case the backend will send some ParameterStatus messages, BackendKeyData,
andfinally ReadyForQuery.*
I'd be surprised if many clients handle it correctly if it is not
sent. Looking quickly at the code for pgbouncer and libpq for PG17
(and lower) they definitely don't. They won't throw an error, but
instead of doing nothing when the user tries to cancel a query they
will instead send a cancel message with all zeros to the server. Since
PG18 libpq handles a cancel call nicely as a no-op, when no cancel key
was received.
I agree that it would be good to explicitly call out that the server
not sending BackendKeyData is an option if we don't want the server to
require sending this message.