Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1hilhH-0000fQ-U8 for pgsql-general@arkaria.postgresql.org; Wed, 03 Jul 2019 20:17:44 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1hilhG-00011w-EG for pgsql-general@arkaria.postgresql.org; Wed, 03 Jul 2019 20:17:42 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1hilhF-0000rr-VD for pgsql-general@lists.postgresql.org; Wed, 03 Jul 2019 20:17:42 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1hilhD-00006f-O9 for pgsql-general@lists.postgresql.org; Wed, 03 Jul 2019 20:17:40 +0000 Received: from sss1.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.14.4/8.14.4) with ESMTP id x63KHbfO010003; Wed, 3 Jul 2019 16:17:37 -0400 From: Tom Lane To: Souvik Bhattacherjee cc: "pgsql-generallists.postgresql.org" Subject: Re: Allocating shared memory in Postgres In-reply-to: References: Comments: In-reply-to Souvik Bhattacherjee message dated "Wed, 03 Jul 2019 16:06:50 -0400" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <10001.1562185057.1@sss.pgh.pa.us> Date: Wed, 03 Jul 2019 16:17:37 -0400 Message-ID: <10002.1562185057@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk Souvik Bhattacherjee 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