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 1kKKNA-0002GP-09 for pgsql-hackers@arkaria.postgresql.org; Mon, 21 Sep 2020 11:52:44 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1kKKN6-0000rW-Vs for pgsql-hackers@arkaria.postgresql.org; Mon, 21 Sep 2020 11:52:40 +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 1kKKN6-0000rP-NN for pgsql-hackers@lists.postgresql.org; Mon, 21 Sep 2020 11:52:40 +0000 Received: from mail-ed1-x542.google.com ([2a00:1450:4864:20::542]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1kKKN4-0007mf-4L for pgsql-hackers@lists.postgresql.org; Mon, 21 Sep 2020 11:52:39 +0000 Received: by mail-ed1-x542.google.com with SMTP id ay8so12436905edb.8 for ; Mon, 21 Sep 2020 04:52:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=sghYs0yz3vEjIiFN9mdtSnGkFp4CQsKGlU0yXaPxAcI=; b=HkTJtpcH0vX/moJoE1uRGavCbi4YT1WO7Ia6Xy2smCdyOh1fkGlphqNGAhFLsAVnos jbA8onl17j3trSYINciv/Wg6YUwx1F9s63Ywr45A0ymJ3ONIFdPS12gumzgoB6HfR7TR /EkZtJLtzYXmU5Sjoo7TF3wKhqYNE7ADlihTb4TeWgVf0h+6f5YB6MkCqfRk61xx4KBP WKtRFByaVGQiZemMTNiIkN6dGab7Rl0FYwMthn94u31rjowbkUCbVHQJKQ5kDRphB3rR Xd59Pw75ZtSbyOxRqweBijamkRFBchUVHB+0NQcUB+vMNaajh1xQ9REuCGdgkVIojVyu 7GGQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=sghYs0yz3vEjIiFN9mdtSnGkFp4CQsKGlU0yXaPxAcI=; b=L6iyRWH1oHpUW8dEdrmzlfKim3X/uEFxTg0HDdrkE/ywaUowM0L8poSXfCJVQb7Ak/ UR9gJbA9h1yUANxeJSRnCvGiN1hK7Ut1DWnWd4069VEqK/tFuqqVikT0li241IqEH8pz pacxdUf0M/XJg5VaKVqcZcFCDU7MuzCsbBE3SvUIJajlXCeo2z+XvXdDOtAxlnpdUHp/ 1EyLksdjt3RpP3/pvOG+w5ZbJH+fyvyiXwu/ML+BmBrIdqLYS+sTvw+v7FOv/0T5psnQ xs69EOU8v1JvY4HcAID5BcPYR8QXh7h3RsAhi5kecx2P7U+F3XR9mPTy/BBzMTISij4+ bU4Q== X-Gm-Message-State: AOAM533XQMiROh6ECWA1u4Ls5pwe6gMcJwjK48RaCmyzY5aS4ot9OMh1 JDgu54uwJRjsjcA1NLyIG9SsBJKyJnNnHyBKNRqFK/nGmAM= X-Google-Smtp-Source: ABdhPJzZf9MXmEZkOwXjiwZEneo1EaeCqmamnXZ/ys8YEsmm5IK7Gm7LL+UwfCwhpro4DuS2FpYU5i3v+EST4ENnQjo= X-Received: by 2002:a50:fd87:: with SMTP id o7mr50999899edt.180.1600689156522; Mon, 21 Sep 2020 04:52:36 -0700 (PDT) MIME-Version: 1.0 References: <4f20d57b2aeb447b8eb1495319940c5f@G08CNEXMBPEKD06.g08.fujitsu.local> In-Reply-To: <4f20d57b2aeb447b8eb1495319940c5f@G08CNEXMBPEKD06.g08.fujitsu.local> From: Bharath Rupireddy Date: Mon, 21 Sep 2020 17:22:25 +0530 Message-ID: Subject: Re: make MaxBackends available in _PG_init To: "Wang, Shenhao" Cc: "pgsql-hackers@lists.postgresql.org" Content-Type: text/plain; charset="UTF-8" List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk On Mon, Sep 21, 2020 at 9:14 AM Wang, Shenhao wrote: > > In source, I find that the postmaster will first load library, and then calculate the value of MaxBackends. > > In the old version, the MaxBackends was calculated by: > MaxBackends = MaxConnections + autovacuum_max_workers + 1 + > GetNumShmemAttachedBgworkers(); > Because any extension can register workers which will affect the return value of GetNumShmemAttachedBgworkers. > InitializeMaxBackends must be called after shared_preload_libraries. This is also mentioned in comments. > > Now, function GetNumShmemAttachedBgworkers was deleted and replaced by guc max_worker_processes, > so if we changed the calling order like: > Step1: calling InitializeMaxBackends. > Step2: calling process_shared_preload_libraries > Yes, the GetNumShmemAttachedBgworkers() was removed by commit # dfbba2c86cc8f09cf3ffca3d305b4ce54a7fb49a. ASAICS, changing the order of InitializeMaxBackends() and process_shared_preload_libraries() has no problem, as InitializeMaxBackends() doesn't calculate the MaxBackends based on bgworker infra code, it does calculate based on GUCs. Having said that, I'm not quite sure whether any of the bgworker registration code, for that matter process_shared_preload_libraries() code path will somewhere use MaxBackends? > > In this order extension can get the correct value of MaxBackends in _PG_init. > Is there any specific use case that any of the _PG_init will use MaxBackends? I think the InitializeMaxBackends() function comments still say as shown below. * This must be called after modules have had the chance to register background * workers in shared_preload_libraries, and before shared memory size is * determined. What happens with your patch in EXEC_BACKEND cases? (On linux EXEC_BACKEND (include/pg_config_manual.h) can be enabled for testing purposes). With Regards, Bharath Rupireddy. EnterpriseDB: http://www.enterprisedb.com