diff options
author | Tom Lane <tgl@sss.pgh.pa.us> | 2024-08-06 12:21:23 -0400 |
---|---|---|
committer | Tom Lane <tgl@sss.pgh.pa.us> | 2024-08-06 12:21:53 -0400 |
commit | 0ae5b763ea0e9dcd85521ebdc9285bbdc7470331 (patch) | |
tree | 7714d52c26a2cbc0c053defe87ab48aaa4a89e0a /src/backend/access/transam/parallel.c | |
parent | 8928817769de0d81758bc760333d3056c67b63c1 (diff) | |
download | postgresql-0ae5b763ea0e9dcd85521ebdc9285bbdc7470331.tar.gz postgresql-0ae5b763ea0e9dcd85521ebdc9285bbdc7470331.zip |
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
Diffstat (limited to 'src/backend/access/transam/parallel.c')
-rw-r--r-- | src/backend/access/transam/parallel.c | 8 |
1 files changed, 6 insertions, 2 deletions
diff --git a/src/backend/access/transam/parallel.c b/src/backend/access/transam/parallel.c index 8613fc6fb54..27551566ac4 100644 --- a/src/backend/access/transam/parallel.c +++ b/src/backend/access/transam/parallel.c @@ -1398,9 +1398,13 @@ ParallelWorkerMain(Datum main_arg) /* * Set the client encoding to the database encoding, since that is what - * the leader will expect. + * the leader will expect. (We're cheating a bit by not calling + * PrepareClientEncoding first. It's okay because this call will always + * result in installing a no-op conversion. No error should be possible, + * but check anyway.) */ - SetClientEncoding(GetDatabaseEncoding()); + if (SetClientEncoding(GetDatabaseEncoding()) < 0) + elog(ERROR, "SetClientEncoding(%d) failed", GetDatabaseEncoding()); /* * Load libraries that were loaded by original backend. We want to do |