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 1nYKL2-0004B3-45 for pgsql-hackers@arkaria.postgresql.org; Sun, 27 Mar 2022 04:17:12 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1nYKK2-0003iZ-0I for pgsql-hackers@arkaria.postgresql.org; Sun, 27 Mar 2022 04:16:10 +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 1nYKK1-0003iP-L8 for pgsql-hackers@lists.postgresql.org; Sun, 27 Mar 2022 04:16:09 +0000 Received: from mail-pf1-x431.google.com ([2607:f8b0:4864:20::431]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1nYKJv-0007Ot-22 for pgsql-hackers@lists.postgresql.org; Sun, 27 Mar 2022 04:16:08 +0000 Received: by mail-pf1-x431.google.com with SMTP id t2so9738781pfj.10 for ; Sat, 26 Mar 2022 21:16:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=20R7vfIXrJStSMryohZmas1Y3lVeultTH70U8vUqIm8=; b=kKTqX/DmZi1AxZ7H/eXK0/yxBzGsp93L2wYnxSMgRG88tP9ORMCQCW9CiQPVP+d14e Kmn4OYC/x+ER8GuDOBNCc7WzFqQZqTLsJH/pCM09n9wD7Z0bgsP9nO60ZZwZvv6fdYDq 0JVsqk2nH0VawPIsLRCknmsejM+zcn17QbHRRHHhTIJz4xnwvaGBXOSWUYWFACITnqdG /P4z3PruujiuP+aYHqxGcNoT4EgUyBatF3ofev1zPN5azSynMK8DR0ur0xTeLHm59jhc Uhla35u1G4bk5HK//hkQBV13M4JRXvIjBF5kHuEQzTx08ARNfojSHhKGqwO2ItWMXoTA LDmw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=20R7vfIXrJStSMryohZmas1Y3lVeultTH70U8vUqIm8=; b=q+FixcgKDFV1y+prstU+mE+BvE6SSsp2qDYw2kl9oX2cIUQQnCUo/9AqzHlkwKkSLP 0m6tREgEJ7aW4nyv84t2Ifkz0Vx6hUX+Y2vUPjr7wcLKIxHrIjd8DD7FdVEpkamGoLn+ zvwLsVxDRUp2FHwi4NAsZbWrARRgl6srSiCLdfPgv2GznVWxYy5At57AXKwUTtEMZgHI m4iarnL/6jJ/h511pMa29QhkF+FNFBDKZ5oBF/z8Rj4OjBkpWFVIUmze5pAxLkxPttTh Mv1N7DthMtblE4OcjyoMmo0X3hfo/OgmGE2Lk6liBxqq+sdVGDJmKK+haeA54PHPj/DR L98Q== X-Gm-Message-State: AOAM5339faojzDR7waMn3Hd3GVW/cQyEpdIdv+Rf2/d+zCzkB3avxzQV o8zCC6zty5dcqd1j3mBiOUU= X-Google-Smtp-Source: ABdhPJxmd2kHLQjBz3vpl552wxPV8fz15albn5En0wqzYhoeaEKuCOo5C1G6mGuYQM+7OV8mW3MY7g== X-Received: by 2002:a65:6c10:0:b0:380:437a:c154 with SMTP id y16-20020a656c10000000b00380437ac154mr5437681pgu.549.1648354560260; Sat, 26 Mar 2022 21:16:00 -0700 (PDT) Received: from jrouhaud (1-171-176-243.dynamic-ip.hinet.net. [1.171.176.243]) by smtp.gmail.com with ESMTPSA id q22-20020a056a00085600b004fb249e5be4sm4732394pfk.181.2022.03.26.21.15.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 26 Mar 2022 21:15:59 -0700 (PDT) Date: Sun, 27 Mar 2022 12:15:25 +0800 From: Julien Rouhaud To: Andres Freund Cc: Michael Paquier , Robert Haas , Nathan Bossart , "Bossart, Nathan" , Fujii Masao , "wangsh.fnst@fujitsu.com" , Bharath Rupireddy , Greg Sabino Mullane , Tom Lane , "pgsql-hackers@lists.postgresql.org" Subject: Re: make MaxBackends available in _PG_init Message-ID: <20220327041525.nmpansfuez5wpocw@jrouhaud> References: <20220323130318.hazuzotfcb6zadcc@jrouhaud> <20220324202050.GA1855897@nathanxps13> <20220325023951.purgu4gb5jyrtc7w@jrouhaud> <20220325031146.cd23gaak5qlzdy6l@jrouhaud> <20220325063542.n6die7fmawluqkfp@jrouhaud> <20220325222317.dftrmzuyrb3iv62o@alap3.anarazel.de> <20220326072203.asge6bua7dxczf7m@jrouhaud> <20220326172316.obspcdmjqerislri@alap3.anarazel.de> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20220326172316.obspcdmjqerislri@alap3.anarazel.de> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On Sat, Mar 26, 2022 at 10:23:16AM -0700, Andres Freund wrote: > > On 2022-03-26 15:22:03 +0800, Julien Rouhaud wrote: > > On Fri, Mar 25, 2022 at 03:23:17PM -0700, Andres Freund wrote: > > > > > > I don't really understand. The issue that started this thread was bugs in > > > extensions due to accessing MaxBackends before it is initialized - which the > > > patch prevents. > > > > Well, the patch prevents accessing a 0-valued MaxBackends but doesn't do > > anything to solve the original complaint. It's not like extensions won't need > > to access that information during _PG_init anymore. > > It resolves the pretty common bug that an extension breaks once it's used via > s_p_l instead of loaded on-demand because MaxBackends isn't initialized in the > s_p_l case. I can hear the argument. However I don't know any extension that relies on MaxBackends and doesn't need to be in s_p_l, and unless I'm missing something no one provided such an example, only people needing the value for RequestAddinShmemSpace(). > > And indeed, any third party code that previously needed to access what > > MaxBackends is supposed to store should already be using that formula, and > > the new GetMaxBackends() doesn't do anything about it. > > It couldn't rely on MaxBackends before. It can't rely on GetMaxBackends() > now. You can see why I think that what you want is unrelated to the > introduction of GetMaxBackends(). Sure, but code also couldn't really rely on MaxConnections or any other similar GUCs and yet nothing is done for that, and the chosen approach doesn't help for that. The only difference is that those GUCs are less broken, as in the value is likely to be valid more often, and closer to the final value when it's not. But still broken. I think GetMaxBackends() is more likely to force authors to rely on computing the value using the underlying GUCs, since there's nothing else that can be done. And if that's an acceptable answer, why aren't we computing MaxBackends before and after processing s_p_l? > If we introduce a separate hook that allows to influence things like > max_connections or whatnot we'd *even more* need a way to verify whether it's > legal to access MaxBackends in that moment. Again, I'm not opposed to validating that MaxBackends is valid when third-party code is accessing it, quite the opposite. I'm opposed to do so *only* for MaxBackends, and without providing a way for third-party code to access that value when they need it, which is for all the cases I know (after more digging that's now 5 extensions) for RequestAddinShmemSpace().