From: Tom Lane <tgl@sss.pgh.pa.us>
To: Souvik Bhattacherjee <kivuosb@gmail.com>
Cc: pgsql-generallists.postgresql.org <pgsql-general@lists.postgresql.org>
Subject: Re: Allocating shared memory in Postgres
Date: Wed, 03 Jul 2019 16:17:37 -0400
Message-ID: <10002.1562185057@sss.pgh.pa.us> (raw)
In-Reply-To: <CAANrPScpwLXFs0FmEXMk5CZRpXUt5q2uL7Ac++oXBujEJ5xzfA@mail.gmail.com>
References: <CAANrPScpwLXFs0FmEXMk5CZRpXUt5q2uL7Ac++oXBujEJ5xzfA@mail.gmail.com>
Souvik Bhattacherjee <kivuosb@gmail.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
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-general@postgresql.org
Cc: tgl@sss.pgh.pa.us, kivuosb@gmail.com
Subject: Re: Allocating shared memory in Postgres
In-Reply-To: <10002.1562185057@sss.pgh.pa.us>
References: <CAANrPScpwLXFs0FmEXMk5CZRpXUt5q2uL7Ac++oXBujEJ5xzfA@mail.gmail.com> <10002.1562185057@sss.pgh.pa.us>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox