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 1lHwFO-00035X-Cu for pgsql-bugs@arkaria.postgresql.org; Thu, 04 Mar 2021 22:15:06 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1lHwFM-00019s-0N for pgsql-bugs@arkaria.postgresql.org; Thu, 04 Mar 2021 22:15:04 +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 1lHwFL-00019l-QM for pgsql-bugs@lists.postgresql.org; Thu, 04 Mar 2021 22:15:03 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1lHwFJ-0008MQ-EZ for pgsql-bugs@lists.postgresql.org; Thu, 04 Mar 2021 22:15:02 +0000 Received: from sss1.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.15.2/8.15.2) with ESMTP id 124MEvtq1418362; Thu, 4 Mar 2021 17:14:57 -0500 From: Tom Lane To: Alvaro Herrera cc: Michael Paquier , r.zharkov@postgrespro.ru, pgsql-bugs@lists.postgresql.org Subject: Re: BUG #16914: Regression test of the worker_spi fails if USE_MODULE_DB environment variable is set. In-reply-to: <20210304211356.GA21621@alvherre.pgsql> References: <20210304211356.GA21621@alvherre.pgsql> Comments: In-reply-to Alvaro Herrera message dated "Thu, 04 Mar 2021 18:13:56 -0300" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <1418360.1614896097.1@sss.pgh.pa.us> Date: Thu, 04 Mar 2021 17:14:57 -0500 Message-ID: <1418361.1614896097@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Alvaro Herrera writes: > On 2021-Mar-04, Michael Paquier wrote: >> One problem with this solution is that this is not portable. Instead >> of generating dynamically the configuration file, here is funkier >> solution as we know that worker_spi would restart if the database it >> should connect to does not exist: let's use a completely different >> database name, not expected by any other modules. Then, this database >> gets created in worker_spi.sql, with a reconnection to it. > It's not that I *like* this solution, but let's say that I dislike it > less than the other one. If there are no other ideas, I +1 this one. The real problem here is that worker_spi illustrates a fundamentally useless way to define which database a worker ought to connect to. It's basically impossible for it to use anything except the hard-wired default for the worker_spi.database GUC. You could wish that we could fix it like CREATE EXTENSION worker_spi; +SELECT set_config('worker_spi.database', current_database(), false); SELECT worker_spi_launch(4) IS NOT NULL; -- wait until the worker completes its initialization but that doesn't work because the session-local setting of the GUC won't be seen over in the worker process. Since the alleged point of this module is to be a prototype for useful background workers, I think we should think of another way. Maybe we need to work a bit harder on passing values from worker_spi_launch to the worker, so that the DB name could be a parameter to worker_spi_launch. regards, tom lane