pgsql: Clean up handling of client_encoding GUC in parallel workers.

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: pgsql-committers(at)lists(dot)postgresql(dot)org
Subject: pgsql: Clean up handling of client_encoding GUC in parallel workers.
Date: 2024-08-06 16:22:01
Message-ID: E1sbMwj-002zGD-2I@gemulon.postgresql.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-committers

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

Branch
------
master

Details
-------
https://git.postgresql.org/pg/commitdiff/0ae5b763ea0e9dcd85521ebdc9285bbdc7470331

Modified Files
--------------
src/backend/access/transam/parallel.c | 8 ++++--
src/backend/commands/variable.c | 47 +++++++++++++++++++----------------
2 files changed, 32 insertions(+), 23 deletions(-)

Browse pgsql-committers by date

  From Date Subject
Next Message Tom Lane 2024-08-06 16:37:19 pgsql: Allow parallel workers to cope with a newly-created session user
Previous Message Nathan Bossart 2024-08-06 15:57:54 pgsql: Remove volatile qualifiers from pg_stat_statements.c.