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 1nXTx5-0003OM-F5 for pgsql-hackers@arkaria.postgresql.org; Thu, 24 Mar 2022 20:20:59 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1nXTx4-0007z3-2l for pgsql-hackers@arkaria.postgresql.org; Thu, 24 Mar 2022 20:20:58 +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 1nXTx3-0007yu-OH for pgsql-hackers@lists.postgresql.org; Thu, 24 Mar 2022 20:20:57 +0000 Received: from mail-oi1-x230.google.com ([2607:f8b0:4864:20::230]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1nXTx0-00062s-Sl for pgsql-hackers@lists.postgresql.org; Thu, 24 Mar 2022 20:20:57 +0000 Received: by mail-oi1-x230.google.com with SMTP id q129so6080572oif.4 for ; Thu, 24 Mar 2022 13:20:54 -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:content-transfer-encoding:in-reply-to; bh=Y2VtH/Rn5HeQ0ksewQx0jhMymb8SHMJr89OeXhT6gsk=; b=Qjzy0XiQHEtUZe0OQWdqWIRwqswtrm8CG0sj2VC9B12KhSq+xnB72Mp/Q0rQsf1tsO t2mGsq4LUwZF0ZEC2DkUf9v3tNpTd+dXbQKLFTFmFOeIUQwreVZla7zRWhX7/+LDlfNR cjdwF2iBF9C7T9FltpBBRXeAupKSj9v9N19KKbyJk9/NBhdbwEBuJzyYAbQUCTzMAY/H ssLsMEDJn1m7PMyIMLkYtnX3rxu5uKHWQMA8NQxjBv/3Vn1raBCDYDcEKE0Lru9isQqF u+MWlFaFwznZQvxIihjEGgcSxcvpuHefsrWiHGfE1Dul/Kw69Ah0yuHUqSijMEf07Gax vmOw== 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:content-transfer-encoding :in-reply-to; bh=Y2VtH/Rn5HeQ0ksewQx0jhMymb8SHMJr89OeXhT6gsk=; b=zxKfDrTXul/Y7wNuJ3InsgAdXVtDWl9mZM5zfVxe4AU6W8p0ua8qSdeqvO5OPu8QsO j4nAJ4Upz/RetalFVR9Ej6hwQqoSKx1HaEbRF0isNbq8MhrKzcFqH9TLNKCMolOEGAuU Rzf1Wv+wSCpRYnaFXE4+9RwahzV25P6LT8F7k6sMtUY/TJ6H1SyUQRwcIhmgsOlFgjpt k3cvRpPGIm84kQznz+qx/bTCBRyLsK6CETSBozPEjmCo52FhmQLCK8QeU5kJHGxIZ1Np uStLaXVECrry4sn9z1zfE032POTA7fWQU1gdeVkUdURFr2hgJkLalYe5rGRrA1SJPcID gsig== X-Gm-Message-State: AOAM531dQGi8YS5z873JQv/8wOJt0UdwaD7dexfsy12kTY1QAKvvIWWA My5sd5jhcowSurHZIJ6zdXE= X-Google-Smtp-Source: ABdhPJx42JwvJTRgWvlt++NFglLbG1uRQSJiKJH/bUYZbNq1ftaEid5QtDZP39Z2gPHSq5VViarVNg== X-Received: by 2002:aca:f185:0:b0:2ef:1fa6:3dca with SMTP id p127-20020acaf185000000b002ef1fa63dcamr3503863oih.140.1648153253188; Thu, 24 Mar 2022 13:20:53 -0700 (PDT) Received: from nathanxps13 ([2600:1700:48f8:340f:3a43:f7c5:e278:8a55]) by smtp.gmail.com with ESMTPSA id fw15-20020a056870080f00b000ddc3ec2533sm1704903oab.9.2022.03.24.13.20.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 24 Mar 2022 13:20:52 -0700 (PDT) Date: Thu, 24 Mar 2022 13:20:50 -0700 From: Nathan Bossart To: Julien Rouhaud Cc: Robert Haas , 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: <20220324202050.GA1855897@nathanxps13> References: <20220209175338.GB1627503@nathanxps13> <20220210192612.GA1684442@nathanxps13> <20220323045229.i23skfscdbvrsuxa@jrouhaud> <20220323130318.hazuzotfcb6zadcc@jrouhaud> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <20220323130318.hazuzotfcb6zadcc@jrouhaud> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On Wed, Mar 23, 2022 at 09:03:18PM +0800, Julien Rouhaud wrote: > On Wed, Mar 23, 2022 at 08:32:39AM -0400, Robert Haas wrote: >> Well, the conclusion upthread was that extensions might change the >> values of those GUCs from _PG_init(). If that's a real thing, then >> what you're asking for here is impossible, because the final value is >> indeterminate until all such extensions have finished twiddling those >> the GUCs. On the other hand, it's definitely intended that extensions >> should RequestAddinShmemSpace() from _PG_init(), and wanting to size >> that memory based on MaxBackends is totally reasonable. Do we need to >> add another function, alongside _PG_init(), that gets called after >> MaxBackends is determined and before it's too late to >> RequestAddinShmemSpace()? > > Yes, I don't see how we can support such extensions without an additional hook, > probably called right after InitializeMaxBackends() since at least > InitializeShmemGUCs() will need to know about those extra memory needs. Another possibility could be to add a hook that is called _before_ _PG_init() where libraries are permitted to adjust GUCs. After the library is loaded, we first call this _PG_change_GUCs() function, then we initialize MaxBackends, and then we finally call _PG_init(). This way, extensions would have access to MaxBackends within _PG_init(), and if an extension really needed to alter GUCs, іt could define this new function. > I'm not sure how to prevent third party code from messing with the gucs in it, > but a clear indication in the hook comment should probably be enough. It's not > like it's hard for third-party code author to break something anyway. ERROR-ing in SetConfigOption() might be another way to dissuade folks from messing with GUCs. This is obviously not a perfect solution. -- Nathan Bossart Amazon Web Services: https://aws.amazon.com