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 1mCPVx-0005oa-Up for pgsql-committers@arkaria.postgresql.org; Sat, 07 Aug 2021 16:49:38 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1mCPVP-0005Xv-Is for pgsql-committers@arkaria.postgresql.org; Sat, 07 Aug 2021 16:49:03 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1mCPVN-0005Xj-Qq for pgsql-committers@lists.postgresql.org; Sat, 07 Aug 2021 16:49:03 +0000 Received: from wout3-smtp.messagingengine.com ([64.147.123.19]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1mCPVH-00005l-MS for pgsql-committers@lists.postgresql.org; Sat, 07 Aug 2021 16:48:59 +0000 Received: from compute2.internal (compute2.nyi.internal [10.202.2.42]) by mailout.west.internal (Postfix) with ESMTP id 87771320076F; Sat, 7 Aug 2021 12:48:53 -0400 (EDT) Received: from mailfrontend2 ([10.202.2.163]) by compute2.internal (MEProxy); Sat, 07 Aug 2021 12:48:53 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=anarazel.de; h= date:from:to:cc:subject:message-id:references:mime-version :content-type:in-reply-to; s=fm2; bh=Hy0ukW+VKzpEmZSvuo7WrOEKzDm n4OuXG30bjYQzBjw=; b=Ru1vnLh62U0QYkoB/x3A/ftJfpsst3CbkQkw7mY0Bt0 ME6Uw1tTFPxumkbUJNOnZIt/SGfUjvX9aglEuFcHYvjC6ifeJi5BboZ0zgnLMe6X uURC8XwQYno/FzOkF7IxtUV4ZjiwJQ0AmvWZxSfw4HoDc4fjxhPMieRW/CM9O7Sh jeh0DElfzqBDNWmgb/ZcuaS/gwhdqIhyYSDDKXPEsXsqJRymEfUEcnbxRcbCR79M oIUB/Bfrm0lJGlwd/rowYrKQhHydDNVGh9Ure3kzxuto8nL7x2OMQryC8WsOPRvY VETdKiiEL4YKd64LRixtyjwp8xbK7Ej0L1P1y6bhEOQ== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-type:date:from:in-reply-to :message-id:mime-version:references:subject:to:x-me-proxy :x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s=fm3; bh=Hy0ukW +VKzpEmZSvuo7WrOEKzDmn4OuXG30bjYQzBjw=; b=Cned+oBLLtWvnmsI51fpCV YO92AD/MVsKvlMAldYE9BKnpqp2tcmka/Fw9CA3NWo4jIqEwTYSql6wwPc1zvSuv ST13n9ak2CZhG+qzR3UVgGXTKGg/id8uA5shQZGKer05p+Qd6z6OLNsFVeRpQAOa RCs3QfpPQmCboJG2LI8aCAaTJX2uIoN79DdKjc8IrSo8YMRgZura5r7HpCy+U6+o kVp42MIIRYA+oHu5iXZ3FDW3JFckrNNBGlNvg6aeKi84kLwrdl9zTujfS8cf2WsC 4GUUvhf6q/5WW2EQBiH1llKtvOZ861eJLArMt9M7X5/q0P+tnBceSOgd8B9rwPvw == X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvtddrjeefgddutdefucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucenucfjughrpeffhffvuffkfhggtggujgesthdtre dttddtvdenucfhrhhomheptehnughrvghsucfhrhgvuhhnugcuoegrnhgurhgvshesrghn rghrrgiivghlrdguvgeqnecuggftrfgrthhtvghrnhepteehheeigfdulefhvedvvddtje ehheekleetkeevgeegudeileeiudeugfeftdejnecuffhomhgrihhnpehpohhsthhgrhgv shhqlhdrohhrghenucevlhhushhtvghrufhiiigvpedtnecurfgrrhgrmhepmhgrihhlfh hrohhmpegrnhgurhgvshesrghnrghrrgiivghlrdguvg X-ME-Proxy: Received: by mail.messagingengine.com (Postfix) with ESMTPA; Sat, 7 Aug 2021 12:48:52 -0400 (EDT) Date: Sat, 7 Aug 2021 09:48:50 -0700 From: Andres Freund To: Tom Lane Cc: pgsql-committers@lists.postgresql.org Subject: Re: pgsql: pgstat: Bring up pgstat in BaseInit() to fix uninitialized use o Message-ID: <20210807164850.52atvo2qkmtfnzgt@alap3.anarazel.de> References: <2638683.1628304247@sss.pgh.pa.us> <20210807030652.qf5wsbhxk7dpsmtn@alap3.anarazel.de> <2640064.1628306008@sss.pgh.pa.us> <2640490.1628306556@sss.pgh.pa.us> <20210807044952.orwuf7hua2wytx4g@alap3.anarazel.de> <20210807051149.x2j3n64ejcu23hm4@alap3.anarazel.de> <2675112.1628350987@sss.pgh.pa.us> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <2675112.1628350987@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Hi, On 2021-08-07 11:43:07 -0400, Tom Lane wrote: > So if I have the lay of the land correctly: > > 1. Somebody decided it'd be a great idea for temp file cleanup to send > stats collector messages. > > 2. Temp file cleanup happens after shmem disconnection. > > 3. This accidentally worked, up to now, because stats transmission happens > via a separate socket not shared memory. > > 4. We can't keep both #1 and #2 if we'd like to switch to shmem-based > stats collection. Sounds accurate to me. > Intuitively it seems like temp file management should be a low-level, > backend-local function and therefore should be okay to run after > shmem disconnection. I do not have a warm feeling about reversing that > module layering --- what's to stop someone from breaking things by > trying to use a temp file in their on_proc_exit or on_shmem_exit hook? We could just add an assert preventing that from happening. It's hard to believe that there could be a good reason to use temp files in those hook points. I'm somewhat inclined to split InitFileAccess() into two by separating out InitTemporaryFileAccess() or such. InitFileAccess() would continue to happen early and register a proc exit hook that errors out when there's a temp file (as a backstop for non cassert builds). The new InitTemporaryFileAccess() would happen a bit later and schedule CleanupTempFiles() to happen via before_shmem_access(). And we add a Assert(!proc_exit_inprogress) to the routines for opening a temp file. > Maybe what needs to go overboard is point 1. Keeping stats of temp files seems useful enough that I'm a bit hesitant to go there. I guess we could just prevent pgstats_report_tempfile() from being called when CleanupTempFiles() is called during proc exit, but that doesn't seem great. > More generally, this points up the fact that we don't have a well-defined > module hierarchy that would help us understand what code can safely do which. > I'm not volunteering to design that, but maybe it needs to happen soon. I agree. Part of the reason for whacking around process startup (in both pushed and still pending commits) was that previously it wasn't just poorly defined, it differed significantly between platforms. And I'm quite unhappy with the vagueness in which we defined the meaning of the various shutdown callbacks ([1]). I suspect to even get to the point of doing a useful redesign of the module hierarchy, we'd need to unify more of the process initialization between EXEC_BACKEND and normal builds. I've bitten by all this often enough to be motivated to propose something. However I want to get the basics of the shared memory stats stuff in first - it's a pain to keep it upated, and we'll need to find and solve all of the issues it has anyway, even if we go for a redesign of module / startup / shutdown layering. Greetings, Andres Freund [1] https://www.postgresql.org/message-id/20210803023612.iziacxk5syn2r4ut%40alap3.anarazel.de