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

Commit4d22173

Browse files
committed
Move bgworker specific logic to bgworker.c
For clarity, we've been slowly moving functions that are not calledfrom the postmaster process out of postmaster.c.Author: Xing Guo <higuoxing@gmail.com>Discussion:https://www.postgresql.org/message-id/CACpMh%2BDBHVT4xPGimzvex%3DwMdMLQEu9PYhT%2BkwwD2x2nu9dU_Q%40mail.gmail.com
1 parent8213df9 commit4d22173

File tree

2 files changed

+83
-83
lines changed

2 files changed

+83
-83
lines changed

‎src/backend/postmaster/bgworker.c

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -851,6 +851,89 @@ BackgroundWorkerMain(char *startup_data, size_t startup_data_len)
851851
proc_exit(0);
852852
}
853853

854+
/*
855+
* Connect background worker to a database.
856+
*/
857+
void
858+
BackgroundWorkerInitializeConnection(constchar*dbname,constchar*username,uint32flags)
859+
{
860+
BackgroundWorker*worker=MyBgworkerEntry;
861+
bits32init_flags=0;/* never honor session_preload_libraries */
862+
863+
/* ignore datallowconn? */
864+
if (flags&BGWORKER_BYPASS_ALLOWCONN)
865+
init_flags |=INIT_PG_OVERRIDE_ALLOW_CONNS;
866+
/* ignore rolcanlogin? */
867+
if (flags&BGWORKER_BYPASS_ROLELOGINCHECK)
868+
init_flags |=INIT_PG_OVERRIDE_ROLE_LOGIN;
869+
870+
/* XXX is this the right errcode? */
871+
if (!(worker->bgw_flags&BGWORKER_BACKEND_DATABASE_CONNECTION))
872+
ereport(FATAL,
873+
(errcode(ERRCODE_PROGRAM_LIMIT_EXCEEDED),
874+
errmsg("database connection requirement not indicated during registration")));
875+
876+
InitPostgres(dbname,InvalidOid,/* database to connect to */
877+
username,InvalidOid,/* role to connect as */
878+
init_flags,
879+
NULL);/* no out_dbname */
880+
881+
/* it had better not gotten out of "init" mode yet */
882+
if (!IsInitProcessingMode())
883+
ereport(ERROR,
884+
(errmsg("invalid processing mode in background worker")));
885+
SetProcessingMode(NormalProcessing);
886+
}
887+
888+
/*
889+
* Connect background worker to a database using OIDs.
890+
*/
891+
void
892+
BackgroundWorkerInitializeConnectionByOid(Oiddboid,Oiduseroid,uint32flags)
893+
{
894+
BackgroundWorker*worker=MyBgworkerEntry;
895+
bits32init_flags=0;/* never honor session_preload_libraries */
896+
897+
/* ignore datallowconn? */
898+
if (flags&BGWORKER_BYPASS_ALLOWCONN)
899+
init_flags |=INIT_PG_OVERRIDE_ALLOW_CONNS;
900+
/* ignore rolcanlogin? */
901+
if (flags&BGWORKER_BYPASS_ROLELOGINCHECK)
902+
init_flags |=INIT_PG_OVERRIDE_ROLE_LOGIN;
903+
904+
/* XXX is this the right errcode? */
905+
if (!(worker->bgw_flags&BGWORKER_BACKEND_DATABASE_CONNECTION))
906+
ereport(FATAL,
907+
(errcode(ERRCODE_PROGRAM_LIMIT_EXCEEDED),
908+
errmsg("database connection requirement not indicated during registration")));
909+
910+
InitPostgres(NULL,dboid,/* database to connect to */
911+
NULL,useroid,/* role to connect as */
912+
init_flags,
913+
NULL);/* no out_dbname */
914+
915+
/* it had better not gotten out of "init" mode yet */
916+
if (!IsInitProcessingMode())
917+
ereport(ERROR,
918+
(errmsg("invalid processing mode in background worker")));
919+
SetProcessingMode(NormalProcessing);
920+
}
921+
922+
/*
923+
* Block/unblock signals in a background worker
924+
*/
925+
void
926+
BackgroundWorkerBlockSignals(void)
927+
{
928+
sigprocmask(SIG_SETMASK,&BlockSig,NULL);
929+
}
930+
931+
void
932+
BackgroundWorkerUnblockSignals(void)
933+
{
934+
sigprocmask(SIG_SETMASK,&UnBlockSig,NULL);
935+
}
936+
854937
/*
855938
* Register a new static background worker.
856939
*

‎src/backend/postmaster/postmaster.c

Lines changed: 0 additions & 83 deletions
Original file line numberDiff line numberDiff line change
@@ -4148,89 +4148,6 @@ MaxLivePostmasterChildren(void)
41484148
max_wal_senders+max_worker_processes);
41494149
}
41504150

4151-
/*
4152-
* Connect background worker to a database.
4153-
*/
4154-
void
4155-
BackgroundWorkerInitializeConnection(constchar*dbname,constchar*username,uint32flags)
4156-
{
4157-
BackgroundWorker*worker=MyBgworkerEntry;
4158-
bits32init_flags=0;/* never honor session_preload_libraries */
4159-
4160-
/* ignore datallowconn? */
4161-
if (flags&BGWORKER_BYPASS_ALLOWCONN)
4162-
init_flags |=INIT_PG_OVERRIDE_ALLOW_CONNS;
4163-
/* ignore rolcanlogin? */
4164-
if (flags&BGWORKER_BYPASS_ROLELOGINCHECK)
4165-
init_flags |=INIT_PG_OVERRIDE_ROLE_LOGIN;
4166-
4167-
/* XXX is this the right errcode? */
4168-
if (!(worker->bgw_flags&BGWORKER_BACKEND_DATABASE_CONNECTION))
4169-
ereport(FATAL,
4170-
(errcode(ERRCODE_PROGRAM_LIMIT_EXCEEDED),
4171-
errmsg("database connection requirement not indicated during registration")));
4172-
4173-
InitPostgres(dbname,InvalidOid,/* database to connect to */
4174-
username,InvalidOid,/* role to connect as */
4175-
init_flags,
4176-
NULL);/* no out_dbname */
4177-
4178-
/* it had better not gotten out of "init" mode yet */
4179-
if (!IsInitProcessingMode())
4180-
ereport(ERROR,
4181-
(errmsg("invalid processing mode in background worker")));
4182-
SetProcessingMode(NormalProcessing);
4183-
}
4184-
4185-
/*
4186-
* Connect background worker to a database using OIDs.
4187-
*/
4188-
void
4189-
BackgroundWorkerInitializeConnectionByOid(Oiddboid,Oiduseroid,uint32flags)
4190-
{
4191-
BackgroundWorker*worker=MyBgworkerEntry;
4192-
bits32init_flags=0;/* never honor session_preload_libraries */
4193-
4194-
/* ignore datallowconn? */
4195-
if (flags&BGWORKER_BYPASS_ALLOWCONN)
4196-
init_flags |=INIT_PG_OVERRIDE_ALLOW_CONNS;
4197-
/* ignore rolcanlogin? */
4198-
if (flags&BGWORKER_BYPASS_ROLELOGINCHECK)
4199-
init_flags |=INIT_PG_OVERRIDE_ROLE_LOGIN;
4200-
4201-
/* XXX is this the right errcode? */
4202-
if (!(worker->bgw_flags&BGWORKER_BACKEND_DATABASE_CONNECTION))
4203-
ereport(FATAL,
4204-
(errcode(ERRCODE_PROGRAM_LIMIT_EXCEEDED),
4205-
errmsg("database connection requirement not indicated during registration")));
4206-
4207-
InitPostgres(NULL,dboid,/* database to connect to */
4208-
NULL,useroid,/* role to connect as */
4209-
init_flags,
4210-
NULL);/* no out_dbname */
4211-
4212-
/* it had better not gotten out of "init" mode yet */
4213-
if (!IsInitProcessingMode())
4214-
ereport(ERROR,
4215-
(errmsg("invalid processing mode in background worker")));
4216-
SetProcessingMode(NormalProcessing);
4217-
}
4218-
4219-
/*
4220-
* Block/unblock signals in a background worker
4221-
*/
4222-
void
4223-
BackgroundWorkerBlockSignals(void)
4224-
{
4225-
sigprocmask(SIG_SETMASK,&BlockSig,NULL);
4226-
}
4227-
4228-
void
4229-
BackgroundWorkerUnblockSignals(void)
4230-
{
4231-
sigprocmask(SIG_SETMASK,&UnBlockSig,NULL);
4232-
}
4233-
42344151
/*
42354152
* Start a new bgworker.
42364153
* Starting time conditions must have been checked already.

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp