pgsql: Allow background workers to be started dynamically.

From: Robert Haas <rhaas(at)postgresql(dot)org>
To: pgsql-committers(at)postgresql(dot)org
Subject: pgsql: Allow background workers to be started dynamically.
Date: 2013-07-16 17:02:47
Message-ID: E1Uz8eF-0006OE-Bb@gemulon.postgresql.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-committers pgsql-hackers

Allow background workers to be started dynamically.

There is a new API, RegisterDynamicBackgroundWorker, which allows
an ordinary user backend to register a new background writer during
normal running. This means that it's no longer necessary for all
background workers to be registered during processing of
shared_preload_libraries, although the option of registering workers
at that time remains available.

When a background worker exits and will not be restarted, the
slot previously used by that background worker is automatically
released and becomes available for reuse. Slots used by background
workers that are configured for automatic restart can't (yet) be
released without shutting down the system.

This commit adds a new source file, bgworker.c, and moves some
of the existing control logic for background workers there.
Previously, there was little enough logic that it made sense to
keep everything in postmaster.c, but not any more.

This commit also makes the worker_spi contrib module into an
extension and adds a new function, worker_spi_launch, which can
be used to demonstrate the new facility.

Branch
------
master

Details
-------
http://git.postgresql.org/pg/commitdiff/7f7485a0cde92aa4ba235a1ffe4dda0ca0b6cc9a

Modified Files
--------------
contrib/worker_spi/Makefile | 3 +
contrib/worker_spi/worker_spi--1.0.sql | 9 +
contrib/worker_spi/worker_spi.c | 66 +++-
contrib/worker_spi/worker_spi.control | 5 +
doc/src/sgml/bgworker.sgml | 55 ++-
src/backend/postmaster/Makefile | 4 +-
src/backend/postmaster/bgworker.c | 483 +++++++++++++++++++++++++++
src/backend/postmaster/postmaster.c | 227 +++----------
src/backend/storage/ipc/ipci.c | 3 +
src/include/postmaster/bgworker.h | 14 +-
src/include/postmaster/bgworker_internals.h | 48 +++
src/include/storage/lwlock.h | 1 +
src/include/storage/pmsignal.h | 1 +
13 files changed, 710 insertions(+), 209 deletions(-)

Responses

Browse pgsql-committers by date

  From Date Subject
Next Message David Fetter 2013-07-16 17:41:44 Re: SSL renegotiation
Previous Message Robert Haas 2013-07-16 15:57:19 Re: SSL renegotiation

Browse pgsql-hackers by date

  From Date Subject
Next Message Robert Haas 2013-07-16 17:09:40 Re: dynamic background workers
Previous Message Greg Stark 2013-07-16 16:54:59 Re: Differences in WHERE clause of SELECT