mirror of
https://github.com/postgres/postgres.git
synced 2025-11-22 12:22:45 +03:00
Add new function BackgroundWorkerInitializeConnectionByOid.
Sometimes it's useful for a background worker to be able to initialize its database connection by OID rather than by name, so provide a way to do that.
This commit is contained in:
@@ -450,7 +450,7 @@ AutoVacLauncherMain(int argc, char *argv[])
|
||||
InitProcess();
|
||||
#endif
|
||||
|
||||
InitPostgres(NULL, InvalidOid, NULL, NULL);
|
||||
InitPostgres(NULL, InvalidOid, NULL, InvalidOid, NULL);
|
||||
|
||||
SetProcessingMode(NormalProcessing);
|
||||
|
||||
@@ -1620,7 +1620,7 @@ AutoVacWorkerMain(int argc, char *argv[])
|
||||
* Note: if we have selected a just-deleted database (due to using
|
||||
* stale stats info), we'll fail and exit here.
|
||||
*/
|
||||
InitPostgres(NULL, dbid, NULL, dbname);
|
||||
InitPostgres(NULL, dbid, NULL, InvalidOid, dbname);
|
||||
SetProcessingMode(NormalProcessing);
|
||||
set_ps_display(dbname, false);
|
||||
ereport(DEBUG1,
|
||||
|
||||
@@ -5313,7 +5313,30 @@ BackgroundWorkerInitializeConnection(char *dbname, char *username)
|
||||
(errcode(ERRCODE_PROGRAM_LIMIT_EXCEEDED),
|
||||
errmsg("database connection requirement not indicated during registration")));
|
||||
|
||||
InitPostgres(dbname, InvalidOid, username, NULL);
|
||||
InitPostgres(dbname, InvalidOid, username, InvalidOid, NULL);
|
||||
|
||||
/* it had better not gotten out of "init" mode yet */
|
||||
if (!IsInitProcessingMode())
|
||||
ereport(ERROR,
|
||||
(errmsg("invalid processing mode in background worker")));
|
||||
SetProcessingMode(NormalProcessing);
|
||||
}
|
||||
|
||||
/*
|
||||
* Connect background worker to a database using OIDs.
|
||||
*/
|
||||
void
|
||||
BackgroundWorkerInitializeConnectionByOid(Oid dboid, Oid useroid)
|
||||
{
|
||||
BackgroundWorker *worker = MyBgworkerEntry;
|
||||
|
||||
/* XXX is this the right errcode? */
|
||||
if (!(worker->bgw_flags & BGWORKER_BACKEND_DATABASE_CONNECTION))
|
||||
ereport(FATAL,
|
||||
(errcode(ERRCODE_PROGRAM_LIMIT_EXCEEDED),
|
||||
errmsg("database connection requirement not indicated during registration")));
|
||||
|
||||
InitPostgres(NULL, dboid, NULL, useroid, NULL);
|
||||
|
||||
/* it had better not gotten out of "init" mode yet */
|
||||
if (!IsInitProcessingMode())
|
||||
|
||||
Reference in New Issue
Block a user