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 1nF1le-00014G-BD for pgsql-hackers@arkaria.postgresql.org; Tue, 01 Feb 2022 22:36:54 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1nF1lc-00038F-0w for pgsql-hackers@arkaria.postgresql.org; Tue, 01 Feb 2022 22:36:52 +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 1nF1lb-000386-DD for pgsql-hackers@lists.postgresql.org; Tue, 01 Feb 2022 22:36:51 +0000 Received: from mail-pj1-x102c.google.com ([2607:f8b0:4864:20::102c]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1nF1lU-0003xQ-Ro for pgsql-hackers@lists.postgresql.org; Tue, 01 Feb 2022 22:36:50 +0000 Received: by mail-pj1-x102c.google.com with SMTP id z14-20020a17090ab10e00b001b6175d4040so4918554pjq.0 for ; Tue, 01 Feb 2022 14:36:44 -0800 (PST) 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=AQgnTFLH8+yC/0cyNQDg/ixuSx6xULzVavUIAZR29MQ=; b=Fi/dZODR2xmVqFNHjxhHfA/8rILY+KcwyYmqQbsi0+fMr+XBei9J0vQbyE61yaoMph FStvu0C660LCQ4P4vREDM/EWYxpAcBad0shQP7vlbzBtosYFVj8mSVGULqckCXbklwWB wWZ65NLKhSVFNneWObPdP2JFznLvao8rhu1qzkmlYFC15uOMuSLMH48MTm7gTJEhJlGB cQOrUetL+6TNSC/XXJ5929xYlvBckbI58vF4h91GdsRNfwg+Ushji6VBHeErn+9LTIud BNGxOS53vVPEDgfSBQjnEQV2/c0hVa9u70BNNwS60f2v8e8gJIRLsCQpP6oiQ72hWqdp 8fxg== 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=AQgnTFLH8+yC/0cyNQDg/ixuSx6xULzVavUIAZR29MQ=; b=FovtVDFMQbTV4n6tKwKEhZ58PP3+PRHBj49PR/SlllPWyPXonbp6BQyca2dgFFwXz9 DjqayhUhtuV4GGVSkj7jXBLR5W7BlbeFatKWBMFDwDdfOi1zYoV4ESocdFpa9fvn3VXR BO6DkPPc21RpKHJL0UGi6MSztW/5abXbqvd3/Hwxa8TeYDA7Nv57PYHHnkKSn/yqJ8G/ Z0/Z+4K46LLBsIyEb6lBX/EcoJ/qi4j3T0z34JoE4bh+7xDtrxF/8n8u9nKsUK9kL1lj MvQvCnRh6bH2cl3nCrIpAWW/4lB9ftTLD64Fdn2y08C8322Ou+H2prmt0pw53Sh/+P2R H59g== X-Gm-Message-State: AOAM533UX+ErWO+KPWeVe96LOyaIscHXSFqupEaVRQBMiKy20uIkYjox UYVn+cRWjwTcKZC56gnvEKk= X-Google-Smtp-Source: ABdhPJyy3AH/U1fv77oQWfnmsZDcFMVMCiFaG/Ezoqi3+hkpLHMs+T+3fM+UN8SLU1d2nInmc55Y1g== X-Received: by 2002:a17:903:230c:: with SMTP id d12mr28238394plh.74.1643755003587; Tue, 01 Feb 2022 14:36:43 -0800 (PST) Received: from nathanxps13 ([50.54.155.70]) by smtp.gmail.com with ESMTPSA id q1sm3710335pjd.48.2022.02.01.14.36.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 01 Feb 2022 14:36:42 -0800 (PST) Date: Tue, 1 Feb 2022 14:36:40 -0800 From: Nathan Bossart To: Robert Haas Cc: Michael Paquier , "Bossart, Nathan" , Fujii Masao , "wangsh.fnst@fujitsu.com" , Andres Freund , Bharath Rupireddy , Greg Sabino Mullane , Tom Lane , "pgsql-hackers@lists.postgresql.org" Subject: Re: make MaxBackends available in _PG_init Message-ID: <20220201223640.GA739804@nathanxps13> References: <01c32f6c-8101-1ce4-8295-534cf067df94@oss.nttdata.com> <7239E4F9-A46D-4A61-9200-8B1366D03ADB@amazon.com> <1E960D8B-24D7-43E0-9744-C5F8C52DDEB4@amazon.com> <20220127181815.GA551692@nathanxps13> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On Mon, Jan 31, 2022 at 09:32:21AM -0500, Robert Haas wrote: > The main reason why this doesn't work for MaxBackends is that > MaxBackends depends on the values of multiple GUCs. There is a further > wrinkle too, which is that none of those GUCs can change, and > therefore code does things with the resulting value on the assumption > that they won't change, like size shared-memory data structures. > Therefore, if you read the wrong value, you've got a big problem. So > the real issues here IMHO are about the difficulty of making sure that > (1) when a GUC changes, we update all of the things that depend on it > including things which may also depend on other GUCs and (2) making > sure that values which can't ever change are computed before they are > used. > > I don't know what the solution to problem #1 is, but the solution to > problem #2 is simple: make people call a function to get the value > rather than just reading a bare variable. GetConfigOption() is not a > good solution for people aiming to write C code that does useful > things, because it delivers the value as a string, and that is not > what you want. But an accessor function like GetMaxBackends() for a > quantity of this type is wonderful. Depending on the situation, you > might choose to have the accessor function [a] fail an assertion if > the value is not available yet or [b] compute the value if they value > has not yet been computed or [c] do the latter if possible, otherwise > the former. But the fact that you are making code call a function > rather than just read a variable gives you a very strong tool to make > sure that someone can't blindly read a 0 or whatever instead of the > real value. +1 I can work on a new patch if this is the direction we want to go. There were a couple of functions that called GetMaxBackends() repetitively that I should probably fix before the patch should be seriously considered. -- Nathan Bossart Amazon Web Services: https://aws.amazon.com