Skip to content

Commit 97ff8dd

Browse files
committed
Fix worker_spi when launching workers without shared_preload_libraries
Currently, the database name to connect is initialized only when the module is loaded with shared_preload_libraries, causing any call of worker_spi_launch() to fail if the library is not loaded for a dynamic bgworker launch. Rather than making the GUC defining the database to connect to a PGC_POSTMASTER, this commit switches worker_spi.database to PGC_SIGHUP, loaded even if the module's library is loaded dynamically for a worker. We have been discussing about the integration of more advanced tests in this module, with and without shared_preload_libraries set, so this eases a bit the work planned in this area. No backpatch is done as, while this is a bug, it changes the definition of worker_spi.database. Author: Masahiro Ikeda Reviewed-by: Bharath Rupireddy Discussion: https://postgr.es/m/d30d3ea7d21cb7c9e1e3cc47e301f1b6@oss.nttdata.com
1 parent 9089287 commit 97ff8dd

File tree

1 file changed

+14
-9
lines changed

1 file changed

+14
-9
lines changed

src/test/modules/worker_spi/worker_spi.c

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -283,6 +283,11 @@ _PG_init(void)
283283
BackgroundWorker worker;
284284

285285
/* get the configuration */
286+
287+
/*
288+
* These GUCs are defined even if this library is not loaded with
289+
* shared_preload_libraries, for worker_spi_launch().
290+
*/
286291
DefineCustomIntVariable("worker_spi.naptime",
287292
"Duration between each check (in seconds).",
288293
NULL,
@@ -296,6 +301,15 @@ _PG_init(void)
296301
NULL,
297302
NULL);
298303

304+
DefineCustomStringVariable("worker_spi.database",
305+
"Database to connect to.",
306+
NULL,
307+
&worker_spi_database,
308+
"postgres",
309+
PGC_SIGHUP,
310+
0,
311+
NULL, NULL, NULL);
312+
299313
if (!process_shared_preload_libraries_in_progress)
300314
return;
301315

@@ -312,15 +326,6 @@ _PG_init(void)
312326
NULL,
313327
NULL);
314328

315-
DefineCustomStringVariable("worker_spi.database",
316-
"Database to connect to.",
317-
NULL,
318-
&worker_spi_database,
319-
"postgres",
320-
PGC_POSTMASTER,
321-
0,
322-
NULL, NULL, NULL);
323-
324329
MarkGUCPrefixReserved("worker_spi");
325330

326331
/* set up common data for all our workers */

0 commit comments

Comments
 (0)