From dad75a62bfb25e3228d1db73e4a06e2c6bd22dd2 Mon Sep 17 00:00:00 2001 From: Tom Lane Date: Sat, 3 Jan 2009 17:08:39 +0000 Subject: [PATCH] Create a "shmem_startup_hook" to be called at the end of shared memory initialization, to give loadable modules a reasonable place to perform creation of any shared memory areas they need. This is the logical conclusion of our previous creation of RequestAddinShmemSpace() and RequestAddinLWLocks(). We don't need an explicit shmem_shutdown_hook, because the existing on_shmem_exit and on_proc_exit mechanisms serve that need. Also, adjust SubPostmasterMain so that libraries that got loaded into the postmaster will be loaded into all child processes, not only regular backends. This improves consistency with the non-EXEC_BACKEND behavior, and might be necessary for functionality for some types of add-ons. --- src/backend/postmaster/postmaster.c | 22 ++++++++++++---------- src/backend/storage/ipc/ipci.c | 10 +++++++++- src/include/storage/ipc.h | 5 ++++- 3 files changed, 25 insertions(+), 12 deletions(-) diff --git a/src/backend/postmaster/postmaster.c b/src/backend/postmaster/postmaster.c index f27c69633a..22bc5b1f3f 100644 --- a/src/backend/postmaster/postmaster.c +++ b/src/backend/postmaster/postmaster.c @@ -37,7 +37,7 @@ * * * IDENTIFICATION - * $PostgreSQL: pgsql/src/backend/postmaster/postmaster.c,v 1.568 2009/01/01 17:23:46 momjian Exp $ + * $PostgreSQL: pgsql/src/backend/postmaster/postmaster.c,v 1.569 2009/01/03 17:08:38 tgl Exp $ * * NOTES * @@ -3668,6 +3668,14 @@ SubPostmasterMain(int argc, char *argv[]) /* Read in remaining GUC variables */ read_nondefault_variables(); + /* + * Reload any libraries that were preloaded by the postmaster. Since + * we exec'd this process, those libraries didn't come along with us; + * but we should load them into all child processes to be consistent + * with the non-EXEC_BACKEND behavior. + */ + process_shared_preload_libraries(); + /* Run backend or appropriate child */ if (strcmp(argv[1], "--forkbackend") == 0) { @@ -3680,21 +3688,15 @@ SubPostmasterMain(int argc, char *argv[]) * Need to reinitialize the SSL library in the backend, since the * context structures contain function pointers and cannot be passed * through the parameter file. + * + * XXX should we do this in all child processes? For the moment it's + * enough to do it in backend children. */ #ifdef USE_SSL if (EnableSSL) secure_initialize(); #endif - /* - * process any libraries that should be preloaded at postmaster start - * - * NOTE: we have to re-load the shared_preload_libraries here because - * this backend is not fork()ed so we can't inherit any shared - * libraries / DLL's from our parent (the postmaster). - */ - process_shared_preload_libraries(); - /* * Perform additional initialization and client authentication. * diff --git a/src/backend/storage/ipc/ipci.c b/src/backend/storage/ipc/ipci.c index 720f4cd284..f85f0a66df 100644 --- a/src/backend/storage/ipc/ipci.c +++ b/src/backend/storage/ipc/ipci.c @@ -8,7 +8,7 @@ * * * IDENTIFICATION - * $PostgreSQL: pgsql/src/backend/storage/ipc/ipci.c,v 1.98 2009/01/01 17:23:47 momjian Exp $ + * $PostgreSQL: pgsql/src/backend/storage/ipc/ipci.c,v 1.99 2009/01/03 17:08:39 tgl Exp $ * *------------------------------------------------------------------------- */ @@ -34,6 +34,8 @@ #include "storage/spin.h" +shmem_startup_hook_type shmem_startup_hook = NULL; + static Size total_addin_request = 0; static bool addin_request_allowed = true; @@ -222,4 +224,10 @@ CreateSharedMemoryAndSemaphores(bool makePrivate, int port) if (!IsUnderPostmaster) ShmemBackendArrayAllocation(); #endif + + /* + * Now give loadable modules a chance to set up their shmem allocations + */ + if (shmem_startup_hook) + shmem_startup_hook(); } diff --git a/src/include/storage/ipc.h b/src/include/storage/ipc.h index 8cf326d57c..bcab86d8aa 100644 --- a/src/include/storage/ipc.h +++ b/src/include/storage/ipc.h @@ -11,7 +11,7 @@ * Portions Copyright (c) 1996-2009, PostgreSQL Global Development Group * Portions Copyright (c) 1994, Regents of the University of California * - * $PostgreSQL: pgsql/src/include/storage/ipc.h,v 1.76 2009/01/01 17:24:01 momjian Exp $ + * $PostgreSQL: pgsql/src/include/storage/ipc.h,v 1.77 2009/01/03 17:08:39 tgl Exp $ * *------------------------------------------------------------------------- */ @@ -19,6 +19,7 @@ #define IPC_H typedef void (*pg_on_exit_callback) (int code, Datum arg); +typedef void (*shmem_startup_hook_type) (void); /*---------- * API for handling cleanup that must occur during either ereport(ERROR) @@ -71,6 +72,8 @@ extern void cancel_shmem_exit(pg_on_exit_callback function, Datum arg); extern void on_exit_reset(void); /* ipci.c */ +extern PGDLLIMPORT shmem_startup_hook_type shmem_startup_hook; + extern void CreateSharedMemoryAndSemaphores(bool makePrivate, int port); #endif /* IPC_H */