Re: BackendKeyData is mandatory?
Jelte Fennema-Nio <postgres@jeltef.nl>
From: Jelte Fennema-Nio <postgres@jeltef.nl>
To: Tatsuo Ishii <ishii@postgresql.org>
Cc: hlinnaka@iki.fi, peter@eisentraut.org, pgsql-hackers@postgresql.org
Date: 2025-06-19T12:12:23Z
Lists: pgsql-hackers
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 backend process is being started, and the frontend is just an interested bystander. It is still possible for the startup attempt to 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, and finally 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.
Commits
-
Revert unnecessary check for NULL
- 5a26a3e4eeb2 18.0 landed
- 807ee417e562 19 (unreleased) landed
-
libpq: Be strict about cancel key lengths
- e7ff96853ea7 18.0 landed
- e411a8d25a4b 19 (unreleased) landed
-
libpq: Handle OOM by disconnecting instead of hanging or skipping msgs
- 8aa287c9061b 18.0 landed
- f6f0542266f0 19 (unreleased) landed
-
libpq: Complain about missing BackendKeyData later with PGgetCancel()
- 42b1480eb2c6 18.0 landed
- a4801eb691ed 19 (unreleased) landed