aboutsummaryrefslogtreecommitdiff
path: root/src/backend/utils/init/postinit.c
diff options
context:
space:
mode:
authorMichael Paquier <michael@paquier.xyz>2023-10-11 12:31:49 +0900
committerMichael Paquier <michael@paquier.xyz>2023-10-11 12:31:49 +0900
commit4800a5dfb4c46d22b5d05f16c615bea6ff24a2bb (patch)
tree14c19eaa27346ac68387dfe3197724330a9cea6f /src/backend/utils/init/postinit.c
parent28139037c06df7225aef189f95a8425d7990be26 (diff)
downloadpostgresql-4800a5dfb4c46d22b5d05f16c615bea6ff24a2bb.tar.gz
postgresql-4800a5dfb4c46d22b5d05f16c615bea6ff24a2bb.zip
Refactor InitPostgres() to use bitwise option flags
InitPostgres() has been using a set of boolean arguments to control its behavior, and a patch under discussion was aiming at expanding it with a third one. In preparation for expanding this area, this commit switches all the current boolean arguments of this routine to a single bits32 argument instead. Two values are currently supported for the flags: - INIT_PG_LOAD_SESSION_LIBS to load [session|local]_preload_libraries at startup. - INIT_PG_OVERRIDE_ALLOW_CONNS to allow connection to a database even if it has !datallowconn. This is used by bgworkers. Reviewed-by: Bertrand Drouvot Discussion: https://postgr.es/m/ZSTn66_BXRZCeaqS@paquier.xyz
Diffstat (limited to 'src/backend/utils/init/postinit.c')
-rw-r--r--src/backend/utils/init/postinit.c17
1 files changed, 9 insertions, 8 deletions
diff --git a/src/backend/utils/init/postinit.c b/src/backend/utils/init/postinit.c
index df4d15a50fb..449541e9422 100644
--- a/src/backend/utils/init/postinit.c
+++ b/src/backend/utils/init/postinit.c
@@ -681,8 +681,9 @@ BaseInit(void)
* Parameters:
* in_dbname, dboid: specify database to connect to, as described below
* username, useroid: specify role to connect as, as described below
- * load_session_libraries: TRUE to honor [session|local]_preload_libraries
- * override_allow_connections: TRUE to connect despite !datallowconn
+ * flags:
+ * - INIT_PG_LOAD_SESSION_LIBS to honor [session|local]_preload_libraries.
+ * - INIT_PG_OVERRIDE_ALLOW_CONNS to connect despite !datallowconn.
* out_dbname: optional output parameter, see below; pass NULL if not used
*
* The database can be specified by name, using the in_dbname parameter, or by
@@ -701,8 +702,8 @@ BaseInit(void)
* database but not a username; conversely, a physical walsender specifies
* username but not database.
*
- * By convention, load_session_libraries should be passed as true in
- * "interactive" sessions (including standalone backends), but false in
+ * By convention, INIT_PG_LOAD_SESSION_LIBS should be passed in "flags" in
+ * "interactive" sessions (including standalone backends), but not in
* background processes such as autovacuum. Note in particular that it
* shouldn't be true in parallel worker processes; those have another
* mechanism for replicating their leader's set of loaded libraries.
@@ -717,8 +718,7 @@ BaseInit(void)
void
InitPostgres(const char *in_dbname, Oid dboid,
const char *username, Oid useroid,
- bool load_session_libraries,
- bool override_allow_connections,
+ bits32 flags,
char *out_dbname)
{
bool bootstrap = IsBootstrapProcessingMode();
@@ -1189,7 +1189,8 @@ InitPostgres(const char *in_dbname, Oid dboid,
* user is a superuser, so the above stuff has to happen first.)
*/
if (!bootstrap)
- CheckMyDatabase(dbname, am_superuser, override_allow_connections);
+ CheckMyDatabase(dbname, am_superuser,
+ (flags & INIT_PG_OVERRIDE_ALLOW_CONNS) != 0);
/*
* Now process any command-line switches and any additional GUC variable
@@ -1227,7 +1228,7 @@ InitPostgres(const char *in_dbname, Oid dboid,
* during the initial transaction in case anything that requires database
* access needs to be done.
*/
- if (load_session_libraries)
+ if ((flags & INIT_PG_LOAD_SESSION_LIBS) != 0)
process_session_preload_libraries();
/* report this backend in the PgBackendStatus array */