On Mon, 23 Dec 2024, 18:32 Luca Ferrari, <fluca1978@gmail.com> wrote:
>
> Hi all,
> hope this is the right place to ask for, otherwise please point me in
> the right resource.
> I'm trying to develop a module that needs shared memory between
> background workers.
>
> The _PG_init calls a function to reserve the shared memory, which in
> turn calls RequestAddinShmemSpace, which seems to fail. In fact, I
> never got the debug line after the call to RequestAddinShmemSpaec and
> _PG_init does not conitnue.
>
> Here is my code skeleton:
>
> void
> _PG_init(void)
> {
[...]
> // set up the shared memory
> _create_shared_memory();
[...]
> void
> _create_shared_memory()
> {
> Size estimated_size = 10136:
[...]
> RequestAddinShmemSpace( estimated_size );
[...]
> What am I missing here?
Starting with PG15, shared memory should be allocated through a hook,
shmem_request_hook, and not through direct calls to
RequestAddinShmemSpace in _PG_init().
For specific info, see [0] and [1] which introduced
shmem_request_hook. PGPedia also has some info on how to deal with
older PG versions: [2]
I hope this helps.
Kind regards,
Matthias van de Meent
Neon (https://neon.tech)
[0] https://www.postgresql.org/docs/current/xfunc-c.html#XFUNC-SHARED-ADDIN
[1] https://git.postgresql.org/gitweb/?p=postgresql.git;a=commit;h=4f2400cb3f10aa79f99fba680c198237da28dd38
[2] https://pgpedia.info/s/shmem_request_hook.html