pg.ddx.io  pgsql-hackers@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Masahiro Ikeda <ikedamsh@oss.nttdata.com>
To: pgsql-hackers@lists.postgresql.org
Subject: Support worker_spi to execute the function dynamically.
Date: Thu, 20 Jul 2023 11:15:51 +0900
Message-ID: <d30d3ea7d21cb7c9e1e3cc47e301f1b6@oss.nttdata.com> (raw)

Hi,

While I'm working on the thread[1], I found that the function of
worker_spi module fails if 'shared_preload_libraries' doesn't have
worker_spi.

The reason is that the database name is NULL because the database name
is initialized only when process_shared_preload_libraries_in_progress
is true.

```
psql=# SELECT worker_spi_launch(1) ;
2023-07-20 11:00:56.491 JST [1179891] LOG:  worker_spi worker 1 
initialized with schema1.counted
2023-07-20 11:00:56.491 JST [1179891] FATAL:  cannot read pg_class 
without having selected a database at character 22
2023-07-20 11:00:56.491 JST [1179891] QUERY:  select count(*) from 
pg_namespace where nspname = 'schema1'
2023-07-20 11:00:56.491 JST [1179891] STATEMENT:  select count(*) from 
pg_namespace where nspname = 'schema1'
2023-07-20 11:00:56.492 JST [1179095] LOG:  background worker 
"worker_spi" (PID 1179891) exited with exit code 1
```

In my understanding, the restriction is not required. So, I think it's
better to change the behavior.
(v1-0001-Support-worker_spi-to-execute-the-function-dynamical.patch)

What do you think?

[1] Support to define custom wait events for extensions
https://www.postgresql.org/message-id/flat/b9f5411acda0cf15c8fbb767702ff43e%40oss.nttdata.com

Regards,
-- 
Masahiro Ikeda
NTT DATA CORPORATION

Attachments:

v1-0001-Support-worker_spi-to-execute-the-function-dynamical.patch (text/x-diff, 1.7K) download From c6e60c66c4066b4a01981ffae5a168901e7283eb Mon Sep 17 00:00:00 2001 From: Masahiro Ikeda <masahiro.ikeda.us@hco.ntt.co.jp> Date: Thu, 20 Jul 2023 10:34:50 +0900 Subject: [PATCH] Support worker_spi to execute the function dynamically. Currently, the database name to connect is initialized only when process_shared_preload_libraries_in_progress is true. It means that worker_spi_launch() fails if shared_preload_libraries is empty because the database to connect is NULL. The patch changes that the database name is always initilized when called _PG_init(). We can call worker_spi_launch() and launch SPI workers dynamically. --- src/test/modules/worker_spi/worker_spi.c | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/src/test/modules/worker_spi/worker_spi.c b/src/test/modules/worker_spi/worker_spi.c index 7227cfaa45..ccc38a36d3 100644 --- a/src/test/modules/worker_spi/worker_spi.c +++ b/src/test/modules/worker_spi/worker_spi.c @@ -296,6 +296,15 @@ _PG_init(void) NULL, NULL); + DefineCustomStringVariable("worker_spi.database", + "Database to connect to.", + NULL, + &worker_spi_database, + "postgres", + PGC_SIGHUP, + 0, + NULL, NULL, NULL); + if (!process_shared_preload_libraries_in_progress) return; @@ -312,15 +321,6 @@ _PG_init(void) NULL, NULL); - DefineCustomStringVariable("worker_spi.database", - "Database to connect to.", - NULL, - &worker_spi_database, - "postgres", - PGC_POSTMASTER, - 0, - NULL, NULL, NULL); - MarkGUCPrefixReserved("worker_spi"); /* set up common data for all our workers */ -- 2.25.1

view thread (34+ messages)  latest in thread

Message-ID: <d30d3ea7d21cb7c9e1e3cc47e301f1b6@oss.nttdata.com>
Permalink:  ../d30d3ea7d21cb7c9e1e3cc47e301f1b6@oss.nttdata.com/
Also on:    postgresql.org/message-id/d30d3ea7d21cb7c9e1e3cc47e301f1b6@oss.nttdata.com

 ·  · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-hackers@postgresql.org
  Cc: ikedamsh@oss.nttdata.com, pgsql-hackers@lists.postgresql.org
  Subject: Re: Support worker_spi to execute the function dynamically.
  In-Reply-To: <d30d3ea7d21cb7c9e1e3cc47e301f1b6@oss.nttdata.com>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox