Skip to content

Commit 4605d1c

Browse files
committed
Allow loadable modules to create PGC_POSTMASTER GUC variables, but only
when loaded via shared_preload_libraries. Needed for support of pg_stat_statements, or pretty much anything else that wants a GUC to control size of a shared memory allocation.
1 parent dad75a6 commit 4605d1c

File tree

3 files changed

+29
-4
lines changed

3 files changed

+29
-4
lines changed

src/backend/utils/init/miscinit.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $PostgreSQL: pgsql/src/backend/utils/init/miscinit.c,v 1.170 2009/01/01 17:23:51 momjian Exp $
11+
* $PostgreSQL: pgsql/src/backend/utils/init/miscinit.c,v 1.171 2009/01/03 20:03:08 tgl Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -1131,6 +1131,9 @@ ValidatePgVersion(const char *path)
11311131
char *shared_preload_libraries_string = NULL;
11321132
char *local_preload_libraries_string = NULL;
11331133

1134+
/* Flag telling that we are loading shared_preload_libraries */
1135+
bool process_shared_preload_libraries_in_progress = false;
1136+
11341137
/*
11351138
* load the shared libraries listed in 'libraries'
11361139
*
@@ -1197,9 +1200,11 @@ load_libraries(const char *libraries, const char *gucname, bool restricted)
11971200
void
11981201
process_shared_preload_libraries(void)
11991202
{
1203+
process_shared_preload_libraries_in_progress = true;
12001204
load_libraries(shared_preload_libraries_string,
12011205
"shared_preload_libraries",
12021206
false);
1207+
process_shared_preload_libraries_in_progress = false;
12031208
}
12041209

12051210
/*

src/backend/utils/misc/guc.c

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
* Written by Peter Eisentraut <peter_e@gmx.net>.
1111
*
1212
* IDENTIFICATION
13-
* $PostgreSQL: pgsql/src/backend/utils/misc/guc.c,v 1.487 2009/01/02 10:33:20 mha Exp $
13+
* $PostgreSQL: pgsql/src/backend/utils/misc/guc.c,v 1.488 2009/01/03 20:03:08 tgl Exp $
1414
*
1515
*--------------------------------------------------------------------
1616
*/
@@ -5625,6 +5625,17 @@ init_custom_variable(const char *name,
56255625
{
56265626
struct config_generic *gen;
56275627

5628+
/*
5629+
* Only allow custom PGC_POSTMASTER variables to be created during
5630+
* shared library preload; any later than that, we can't ensure that
5631+
* the value doesn't change after startup. This is a fatal elog if it
5632+
* happens; just erroring out isn't safe because we don't know what
5633+
* the calling loadable module might already have hooked into.
5634+
*/
5635+
if (context == PGC_POSTMASTER &&
5636+
!process_shared_preload_libraries_in_progress)
5637+
elog(FATAL, "cannot create PGC_POSTMASTER variables after startup");
5638+
56285639
gen = (struct config_generic *) guc_malloc(ERROR, sz);
56295640
memset(gen, 0, sz);
56305641

@@ -5707,7 +5718,15 @@ define_custom_variable(struct config_generic * variable)
57075718
case PGC_S_ENV_VAR:
57085719
case PGC_S_FILE:
57095720
case PGC_S_ARGV:
5710-
phcontext = PGC_SIGHUP;
5721+
/*
5722+
* If we got past the check in init_custom_variable, we can
5723+
* safely assume that any existing value for a PGC_POSTMASTER
5724+
* variable was set in postmaster context.
5725+
*/
5726+
if (variable->context == PGC_POSTMASTER)
5727+
phcontext = PGC_POSTMASTER;
5728+
else
5729+
phcontext = PGC_SIGHUP;
57115730
break;
57125731
case PGC_S_DATABASE:
57135732
case PGC_S_USER:

src/include/miscadmin.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
* Portions Copyright (c) 1996-2009, PostgreSQL Global Development Group
1414
* Portions Copyright (c) 1994, Regents of the University of California
1515
*
16-
* $PostgreSQL: pgsql/src/include/miscadmin.h,v 1.207 2009/01/01 17:23:55 momjian Exp $
16+
* $PostgreSQL: pgsql/src/include/miscadmin.h,v 1.208 2009/01/03 20:03:08 tgl Exp $
1717
*
1818
* NOTES
1919
* some of the information in this file should be moved to other files.
@@ -328,6 +328,7 @@ extern void BaseInit(void);
328328

329329
/* in utils/init/miscinit.c */
330330
extern bool IgnoreSystemIndexes;
331+
extern PGDLLIMPORT bool process_shared_preload_libraries_in_progress;
331332
extern char *shared_preload_libraries_string;
332333
extern char *local_preload_libraries_string;
333334

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy