Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commiteed1ce7

Browse files
committed
Allow background workers to bypass datallowconn
THis adds a "flags" field to the BackgroundWorkerInitializeConnection()and BackgroundWorkerInitializeConnectionByOid(). For now only one flag,BGWORKER_BYPASS_ALLOWCONN, is defined, which allows the worker to ignoredatallowconn.
1 parent1664ae1 commiteed1ce7

File tree

11 files changed

+25
-20
lines changed

11 files changed

+25
-20
lines changed

‎contrib/pg_prewarm/autoprewarm.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -445,7 +445,7 @@ autoprewarm_database_main(Datum main_arg)
445445
ereport(ERROR,
446446
(errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
447447
errmsg("could not map dynamic shared memory segment")));
448-
BackgroundWorkerInitializeConnectionByOid(apw_state->database,InvalidOid);
448+
BackgroundWorkerInitializeConnectionByOid(apw_state->database,InvalidOid,0);
449449
block_info= (BlockInfoRecord*)dsm_segment_address(seg);
450450
pos=apw_state->prewarm_start_idx;
451451

‎src/backend/access/transam/parallel.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1324,7 +1324,8 @@ ParallelWorkerMain(Datum main_arg)
13241324

13251325
/* Restore database connection. */
13261326
BackgroundWorkerInitializeConnectionByOid(fps->database_id,
1327-
fps->authenticated_user_id);
1327+
fps->authenticated_user_id,
1328+
0);
13281329

13291330
/*
13301331
* Set the client encoding to the database encoding, since that is what

‎src/backend/bootstrap/bootstrap.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -498,7 +498,7 @@ BootstrapModeMain(void)
498498
*/
499499
InitProcess();
500500

501-
InitPostgres(NULL,InvalidOid,NULL,InvalidOid,NULL);
501+
InitPostgres(NULL,InvalidOid,NULL,InvalidOid,NULL, false);
502502

503503
/* Initialize stuff for bootstrap-file processing */
504504
for (i=0;i<MAXATTR;i++)

‎src/backend/postmaster/autovacuum.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -477,7 +477,7 @@ AutoVacLauncherMain(int argc, char *argv[])
477477
InitProcess();
478478
#endif
479479

480-
InitPostgres(NULL,InvalidOid,NULL,InvalidOid,NULL);
480+
InitPostgres(NULL,InvalidOid,NULL,InvalidOid,NULL, false);
481481

482482
SetProcessingMode(NormalProcessing);
483483

@@ -1693,7 +1693,7 @@ AutoVacWorkerMain(int argc, char *argv[])
16931693
* Note: if we have selected a just-deleted database (due to using
16941694
* stale stats info), we'll fail and exit here.
16951695
*/
1696-
InitPostgres(NULL,dbid,NULL,InvalidOid,dbname);
1696+
InitPostgres(NULL,dbid,NULL,InvalidOid,dbname, false);
16971697
SetProcessingMode(NormalProcessing);
16981698
set_ps_display(dbname, false);
16991699
ereport(DEBUG1,

‎src/backend/postmaster/postmaster.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5582,7 +5582,7 @@ MaxLivePostmasterChildren(void)
55825582
* Connect background worker to a database.
55835583
*/
55845584
void
5585-
BackgroundWorkerInitializeConnection(constchar*dbname,constchar*username)
5585+
BackgroundWorkerInitializeConnection(constchar*dbname,constchar*username,uint32flags)
55865586
{
55875587
BackgroundWorker*worker=MyBgworkerEntry;
55885588

@@ -5592,7 +5592,7 @@ BackgroundWorkerInitializeConnection(const char *dbname, const char *username)
55925592
(errcode(ERRCODE_PROGRAM_LIMIT_EXCEEDED),
55935593
errmsg("database connection requirement not indicated during registration")));
55945594

5595-
InitPostgres(dbname,InvalidOid,username,InvalidOid,NULL);
5595+
InitPostgres(dbname,InvalidOid,username,InvalidOid,NULL, (flags&BGWORKER_BYPASS_ALLOWCONN)!=0);
55965596

55975597
/* it had better not gotten out of "init" mode yet */
55985598
if (!IsInitProcessingMode())
@@ -5605,7 +5605,7 @@ BackgroundWorkerInitializeConnection(const char *dbname, const char *username)
56055605
* Connect background worker to a database using OIDs.
56065606
*/
56075607
void
5608-
BackgroundWorkerInitializeConnectionByOid(Oiddboid,Oiduseroid)
5608+
BackgroundWorkerInitializeConnectionByOid(Oiddboid,Oiduseroid,uint32flags)
56095609
{
56105610
BackgroundWorker*worker=MyBgworkerEntry;
56115611

@@ -5615,7 +5615,7 @@ BackgroundWorkerInitializeConnectionByOid(Oid dboid, Oid useroid)
56155615
(errcode(ERRCODE_PROGRAM_LIMIT_EXCEEDED),
56165616
errmsg("database connection requirement not indicated during registration")));
56175617

5618-
InitPostgres(NULL,dboid,NULL,useroid,NULL);
5618+
InitPostgres(NULL,dboid,NULL,useroid,NULL, (flags&BGWORKER_BYPASS_ALLOWCONN)!=0);
56195619

56205620
/* it had better not gotten out of "init" mode yet */
56215621
if (!IsInitProcessingMode())

‎src/backend/replication/logical/launcher.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -901,7 +901,7 @@ ApplyLauncherMain(Datum main_arg)
901901
* Establish connection to nailed catalogs (we only ever access
902902
* pg_subscription).
903903
*/
904-
BackgroundWorkerInitializeConnection(NULL,NULL);
904+
BackgroundWorkerInitializeConnection(NULL,NULL,0);
905905

906906
/* Enter main loop */
907907
for (;;)

‎src/backend/replication/logical/worker.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1544,7 +1544,8 @@ ApplyWorkerMain(Datum main_arg)
15441544

15451545
/* Connect to our database. */
15461546
BackgroundWorkerInitializeConnectionByOid(MyLogicalRepWorker->dbid,
1547-
MyLogicalRepWorker->userid);
1547+
MyLogicalRepWorker->userid,
1548+
0);
15481549

15491550
/* Load the subscription into persistent memory context. */
15501551
ApplyContext=AllocSetContextCreate(TopMemoryContext,

‎src/backend/tcop/postgres.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3775,7 +3775,7 @@ PostgresMain(int argc, char *argv[],
37753775
* it inside InitPostgres() instead. In particular, anything that
37763776
* involves database access should be there, not here.
37773777
*/
3778-
InitPostgres(dbname,InvalidOid,username,InvalidOid,NULL);
3778+
InitPostgres(dbname,InvalidOid,username,InvalidOid,NULL, false);
37793779

37803780
/*
37813781
* If the PostmasterContext is still around, recycle the space; we don't

‎src/backend/utils/init/postinit.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@
6666
staticHeapTupleGetDatabaseTuple(constchar*dbname);
6767
staticHeapTupleGetDatabaseTupleByOid(Oiddboid);
6868
staticvoidPerformAuthentication(Port*port);
69-
staticvoidCheckMyDatabase(constchar*name,boolam_superuser);
69+
staticvoidCheckMyDatabase(constchar*name,boolam_superuser,booloverride_allow_connections);
7070
staticvoidInitCommunication(void);
7171
staticvoidShutdownPostgres(intcode,Datumarg);
7272
staticvoidStatementTimeoutHandler(void);
@@ -290,7 +290,7 @@ PerformAuthentication(Port *port)
290290
* CheckMyDatabase -- fetch information from the pg_database entry for our DB
291291
*/
292292
staticvoid
293-
CheckMyDatabase(constchar*name,boolam_superuser)
293+
CheckMyDatabase(constchar*name,boolam_superuser,booloverride_allow_connections)
294294
{
295295
HeapTupletup;
296296
Form_pg_databasedbform;
@@ -326,7 +326,7 @@ CheckMyDatabase(const char *name, bool am_superuser)
326326
/*
327327
* Check that the database is currently allowing connections.
328328
*/
329-
if (!dbform->datallowconn)
329+
if (!dbform->datallowconn&& !override_allow_connections)
330330
ereport(FATAL,
331331
(errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
332332
errmsg("database \"%s\" is not currently accepting connections",
@@ -563,7 +563,7 @@ BaseInit(void)
563563
*/
564564
void
565565
InitPostgres(constchar*in_dbname,Oiddboid,constchar*username,
566-
Oiduseroid,char*out_dbname)
566+
Oiduseroid,char*out_dbname,booloverride_allow_connections)
567567
{
568568
boolbootstrap=IsBootstrapProcessingMode();
569569
boolam_superuser;
@@ -1006,7 +1006,7 @@ InitPostgres(const char *in_dbname, Oid dboid, const char *username,
10061006
* user is a superuser, so the above stuff has to happen first.)
10071007
*/
10081008
if (!bootstrap)
1009-
CheckMyDatabase(dbname,am_superuser);
1009+
CheckMyDatabase(dbname,am_superuser,override_allow_connections);
10101010

10111011
/*
10121012
* Now process any command-line switches and any additional GUC variable

‎src/include/miscadmin.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -421,7 +421,7 @@ extern AuxProcType MyAuxProcType;
421421
externvoidpg_split_opts(char**argv,int*argcp,constchar*optstr);
422422
externvoidInitializeMaxBackends(void);
423423
externvoidInitPostgres(constchar*in_dbname,Oiddboid,constchar*username,
424-
Oiduseroid,char*out_dbname);
424+
Oiduseroid,char*out_dbname,booloverride_allow_connections);
425425
externvoidBaseInit(void);
426426

427427
/* in utils/init/miscinit.c */

‎src/include/postmaster/bgworker.h

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -140,10 +140,13 @@ extern PGDLLIMPORT BackgroundWorker *MyBgworkerEntry;
140140
* If dbname is NULL, connection is made to no specific database;
141141
* only shared catalogs can be accessed.
142142
*/
143-
externvoidBackgroundWorkerInitializeConnection(constchar*dbname,constchar*username);
143+
externvoidBackgroundWorkerInitializeConnection(constchar*dbname,constchar*username,uint32flags);
144144

145145
/* Just like the above, but specifying database and user by OID. */
146-
externvoidBackgroundWorkerInitializeConnectionByOid(Oiddboid,Oiduseroid);
146+
externvoidBackgroundWorkerInitializeConnectionByOid(Oiddboid,Oiduseroid,uint32flags);
147+
148+
/* Flags to BackgroundWorkerInitializeConnection et al */
149+
#defineBGWORKER_BYPASS_ALLOWCONN 1
147150

148151
/* Block/unblock signals in a background worker process */
149152
externvoidBackgroundWorkerBlockSignals(void);

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp