Re: Can a background worker exist without shared memory access for EXEC_BACKEND cases? - Mailing list pgsql-hackers

From Robert Haas
Subject Re: Can a background worker exist without shared memory access for EXEC_BACKEND cases?
Date
Msg-id CA+Tgmoa5gcVXcPxEZ+ne4rkPttKbJrpZSZAWEMRLBfHcCEW9Ew@mail.gmail.com
Whole thread Raw
In response to Re: Can a background worker exist without shared memory access for EXEC_BACKEND cases?  (Bharath Rupireddy <bharath.rupireddyforpostgres@gmail.com>)
List pgsql-hackers
On Wed, Aug 5, 2020 at 9:02 AM Bharath Rupireddy
<bharath.rupireddyforpostgres@gmail.com> wrote:
> Will the proposed patch(v2) having some info in bgworker.sgml and
> bgworker.h be ever useful to the users in some way?

Well, it says things that aren't true, so, no, it's not useful. Your
patch claims that "the worker fails to receive the backend parameters
from the postmaster," but that's not the case. SubPostmasterMain()
first calls read_backend_variables() which calls
restore_backend_variables(); then later it calls
StartBackgroundWorker() which does PGSharedMemoryDetach(). So the
values of the backend variables *are* available in the worker
processes. Your debugger output also shows this: if
restore_backend_variables() weren't running in the child processes,
those variables would all be NULL, but you show them all at different
addresses in the 0x7fd... range, which is presumably where the shared
memory segment was mapped.

The reason you can't print out the results of dereferencing the
variables with * is because the memory to which the variables point is
no longer mapped in the process, not because the variables haven't
been initialized. If you looked at a variable that wasn't a pointer to
shared memory, but rather, say, an integer, like max_safe_fds or
MyCancelKey, I think you'd find that the value was preserved just
fine. I think you're confusing the pointer with the data to which it
points.

-- 
Robert Haas
EnterpriseDB: http://www.enterprisedb.com
The Enterprise PostgreSQL Company



pgsql-hackers by date:

Previous
From: Bharath Rupireddy
Date:
Subject: Re: Can a background worker exist without shared memory access for EXEC_BACKEND cases?
Next
From: Alvaro Herrera
Date:
Subject: Re: [PATCH] - Provide robust alternatives for replace_string