diff --git a/doc/src/sgml/bgworker.sgml b/doc/src/sgml/bgworker.sgml index 01ceb38..d6e37b5 100644 --- a/doc/src/sgml/bgworker.sgml +++ b/doc/src/sgml/bgworker.sgml @@ -113,17 +113,16 @@ typedef struct BackgroundWorker BGWORKER_EXIT_AT_DATABASE_CHANGE - Requests termination of the background worker when the database it is - connected to undergoes significant changes. The postmaster will send a - termination signal to the background worker when any of the following - commands are executed: DROP DATABASE, - ALTER DATABASE RENAME TO, or - ALTER DATABASE SET TABLESPACE. - When CREATE DATABASE TEMPLATE command is executed, - background workers which connected to target template database are terminated. - If BGWORKER_SHMEM_ACCESS and - BGWORKER_BACKEND_DATABASE_CONNECTION are not using, - nothing happens. + Requests termination of the background worker when its connected database + undergoes significant changes. The postmaster sends a termination signal + when any of these commands affect the worker's database: + DROP DATABASE, + ALTER DATABASE RENAME TO, + ALTER DATABASE SET TABLESPACE, or + CREATE DATABASE (when the worker is connected to the + template database). + This flag requires both BGWORKER_SHMEM_ACCESS and + BGWORKER_BACKEND_DATABASE_CONNECTION. diff --git a/src/backend/postmaster/bgworker.c b/src/backend/postmaster/bgworker.c index 7ab48c2..e0cfdbf 100644 --- a/src/backend/postmaster/bgworker.c +++ b/src/backend/postmaster/bgworker.c @@ -1400,7 +1400,8 @@ GetBackgroundWorkerTypeByPid(pid_t pid) /* - * Cancel background workers. + * Terminate all background workers connected to the given database, if they + * had requested it. */ void TerminateBackgroundWorkersByOid(Oid databaseId) @@ -1410,8 +1411,8 @@ TerminateBackgroundWorkersByOid(Oid databaseId) LWLockAcquire(BackgroundWorkerLock, LW_EXCLUSIVE); /* - * Iterate through slots, looking for workers - * who connects to the given database. + * Iterate through slots, looking for workers connected to the given + * database. */ for (int slotno = 0; slotno < BackgroundWorkerData->total_slots; ++slotno) { diff --git a/src/backend/storage/ipc/procarray.c b/src/backend/storage/ipc/procarray.c index f612e77..1ed641d 100644 --- a/src/backend/storage/ipc/procarray.c +++ b/src/backend/storage/ipc/procarray.c @@ -3771,7 +3771,7 @@ CountOtherDBBackends(Oid databaseId, int *nbackends, int *nprepared) /* * Terminate all background workers for this database, if - * they had requested it (BGWORKER_EXIT_AT_DATABASE_DROP) + * they had requested it (BGWORKER_EXIT_AT_DATABASE_CHANGE) */ TerminateBackgroundWorkersByOid(databaseId); diff --git a/src/include/postmaster/bgworker.h b/src/include/postmaster/bgworker.h index 57741d7..3a2fc35 100644 --- a/src/include/postmaster/bgworker.h +++ b/src/include/postmaster/bgworker.h @@ -134,6 +134,7 @@ extern const char *GetBackgroundWorkerTypeByPid(pid_t pid); /* Terminate a bgworker */ extern void TerminateBackgroundWorker(BackgroundWorkerHandle *handle); +extern void TerminateBackgroundWorkersByOid(Oid databaseId); /* This is valid in a running worker */ extern PGDLLIMPORT BackgroundWorker *MyBgworkerEntry; @@ -167,7 +168,4 @@ extern void BackgroundWorkerInitializeConnectionByOid(Oid dboid, Oid useroid, ui extern void BackgroundWorkerBlockSignals(void); extern void BackgroundWorkerUnblockSignals(void); -/* Cancel background workers. */ -extern void TerminateBackgroundWorkersByOid(Oid databaseId); - #endif /* BGWORKER_H */