Clean up handling of client_encoding GUC in parallel workers.
authorTom Lane <tgl@sss.pgh.pa.us>
Tue, 6 Aug 2024 16:21:23 +0000 (12:21 -0400)
committerTom Lane <tgl@sss.pgh.pa.us>
Tue, 6 Aug 2024 16:21:53 +0000 (12:21 -0400)
commit0ae5b763ea0e9dcd85521ebdc9285bbdc7470331
tree7714d52c26a2cbc0c053defe87ab48aaa4a89e0a
parent8928817769de0d81758bc760333d3056c67b63c1
Clean up handling of client_encoding GUC in parallel workers.

The previous coding here threw an error from assign_client_encoding
if it was invoked in a parallel worker.  That's a very fundamental
violation of the GUC hook API: assign hooks must not throw errors.
The place to complain is in the check hook, so move the test to
there, and use the regular check-hook API (ie return false) to
report it.

The reason this coding is a problem is that it breaks GUC rollback,
which may occur after we leave InitializingParallelWorker state.
That case seems not actually reachable before now, but commit
f5f30c22e made it reachable, so we need to fix this before that
can be un-reverted.

In passing, improve the commentary in ParallelWorkerMain, and
add a check for failure of SetClientEncoding.  That's another
case that can't happen now but might become possible after
foreseeable code rearrangements (notably, if the shortcut of
skipping PrepareClientEncoding stops being OK).

Discussion: https://postgr.es/m/18545-feba138862f19aaa@postgresql.org
src/backend/access/transam/parallel.c
src/backend/commands/variable.c