Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1kyHsM-0007ET-Qy for pgsql-general@arkaria.postgresql.org; Sat, 09 Jan 2021 17:18:06 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1kyHsL-0001hm-Pv for pgsql-general@arkaria.postgresql.org; Sat, 09 Jan 2021 17:18:05 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1kyHsL-0001h6-HY for pgsql-general@lists.postgresql.org; Sat, 09 Jan 2021 17:18:05 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1kyHsJ-0004eC-4l for pgsql-general@postgresql.org; Sat, 09 Jan 2021 17:18:05 +0000 Received: from sss1.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.15.2/8.15.2) with ESMTP id 109HHxLx400233; Sat, 9 Jan 2021 12:18:00 -0500 From: Tom Lane To: Jack Orenstein cc: pgsql-general@postgresql.org Subject: Re: Static memory, shared memory In-reply-to: References: Comments: In-reply-to Jack Orenstein message dated "Sat, 09 Jan 2021 10:50:24 -0500" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <400231.1610212679.1@sss.pgh.pa.us> Date: Sat, 09 Jan 2021 12:17:59 -0500 Message-ID: <400232.1610212679@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk Jack Orenstein writes: > I am writing a Postgres extension, and thought that I had memory > corruption, (thanks for the --enable-cassert lead). I might, but It now > looks like I need to understand the use of shared memory and locking in > Postgres. So I have two questions. > 1) I am now guessing that my original problem is caused by relying on > static memory in my extension (i.e., in the source declaring > PG_MODULE_MAGIC). This static memory is almost but not quite constant -- it > is initialized from _PG_init, and then never modified. I suspect that this > cannot work in general (since Postgres is multi-process), but I thought it > would be adequate for early development. However, I am seeing this static > memory get corrupted even when there is only a single process executing the > extension code (verified by examining getpid()). Define what you mean by "corrupted". It seems highly unlikely that any code but your own is touching this memory. Really the big-picture question here is what are you hoping to accomplish and why do you think this memory might need to be shared? regards, tom lane