Re: Allocating shared memory in Postgres

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Souvik Bhattacherjee <kivuosb(at)gmail(dot)com>
Cc: "pgsql-generallists(dot)postgresql(dot)org" <pgsql-general(at)lists(dot)postgresql(dot)org>
Subject: Re: Allocating shared memory in Postgres
Date: 2019-07-03 20:17:37
Message-ID: 10002.1562185057@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Souvik Bhattacherjee <kivuosb(at)gmail(dot)com> writes:
> I need to allocate shared memory in Postgres 11.0 outside the
> initialization phase. In order to achieve this I have done the following:
> - during a particular query, where I need to allocate shared memory (which
> is a function of the sizes of the tables in the query), I invoke
> ShmemInitStruct() in shmem.c

This seems like a pretty horrid idea. For starters, what happens if two
backends do this concurrently? Even with only one backend, if you do a
query that requires X space, and then you do another query that requires
X+1 space, what's going to happen?

Recent PG releases have a "DSM" mechanism for short-lived (query lifespan,
typically) shared memory that's separate from the core shmem pool. That
might suit your needs better. The system design is really not friendly
to demanding more core shmem after postmaster start.

regards, tom lane

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Tom Lane 2019-07-03 22:18:32 Re: postgres 11 issue?
Previous Message Souvik Bhattacherjee 2019-07-03 20:06:50 Allocating shared memory in Postgres