[COMMITTERS] pgsql: Background worker processes

2012-12-06 Thread Alvaro Herrera
Background worker processes

Background workers are postmaster subprocesses that run arbitrary
user-specified code.  They can request shared memory access as well as
backend database connections; or they can just use plain libpq frontend
database connections.

Modules listed in shared_preload_libraries can register background
workers in their _PG_init() function; this is early enough that it's not
necessary to provide an extra GUC option, because the necessary extra
resources can be allocated early on.  Modules can install more than one
bgworker, if necessary.

Care is taken that these extra processes do not interfere with other
postmaster tasks: only one such process is started on each ServerLoop
iteration.  This means a large number of them could be waiting to be
started up and postmaster is still able to quickly service external
connection requests.  Also, shutdown sequence should not be impacted by
a worker process that's reasonably well behaved (i.e. promptly responds
to termination signals.)

The current implementation lets worker processes specify their start
time, i.e. at what point in the server startup process they are to be
started: right after postmaster start (in which case they mustn't ask
for shared memory access), when consistent state has been reached
(useful during recovery in a HOT standby server), or when recovery has
terminated (i.e. when normal backends are allowed).

In case of a bgworker crash, actions to take depend on registration
data: if shared memory was requested, then all other connections are
taken down (as well as other bgworkers), just like it were a regular
backend crashing.  The bgworker itself is restarted, too, within a
configurable timeframe (which can be configured to be never).

More features to add to this framework can be imagined without much
effort, and have been discussed, but this seems good enough as a useful
unit already.

An elementary sample module is supplied.

Author: Álvaro Herrera

This patch is loosely based on prior patches submitted by KaiGai Kohei,
and unsubmitted code by Simon Riggs.

Reviewed by: KaiGai Kohei, Markus Wanner, Andres Freund,
Heikki Linnakangas, Simon Riggs, Amit Kapila

Branch
--
master

Details
---
http://git.postgresql.org/pg/commitdiff/da07a1e856511dca59cbb1357616e26baa64428e

Modified Files
--
contrib/Makefile|3 +-
contrib/worker_spi/Makefile |   14 +
contrib/worker_spi/worker_spi.c |  263 
doc/src/sgml/bgworker.sgml  |  146 +
doc/src/sgml/filelist.sgml  |1 +
doc/src/sgml/postgres.sgml  |1 +
src/backend/postmaster/postmaster.c | 1165 --
src/backend/storage/lmgr/proc.c |   43 +-
src/backend/utils/init/globals.c|1 +
src/backend/utils/init/miscinit.c   |6 +-
src/backend/utils/init/postinit.c   |   13 +
src/backend/utils/misc/guc.c|   15 +-
src/include/miscadmin.h |1 +
src/include/postmaster/bgworker.h   |  104 
src/include/postmaster/postmaster.h |2 +
src/include/storage/proc.h  |2 +
16 files changed, 1690 insertions(+), 90 deletions(-)


-- 
Sent via pgsql-committers mailing list ([email protected])
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-committers


[COMMITTERS] pgsql: Improve pl/pgsql to support composite-type expressions in RETURN

2012-12-06 Thread Tom Lane
Improve pl/pgsql to support composite-type expressions in RETURN.

For some reason lost in the mists of prehistory, RETURN was only coded to
allow a simple reference to a composite variable when the function's return
type is composite.  Allow an expression instead, while preserving the
efficiency of the original code path in the case where the expression is
indeed just a composite variable's name.  Likewise for RETURN NEXT.

As is true in various other places, the supplied expression must yield
exactly the number and data types of the required columns.  There was some
discussion of relaxing that for pl/pgsql, but no consensus yet, so this
patch doesn't address that.

Asif Rehman, reviewed by Pavel Stehule

Branch
--
master

Details
---
http://git.postgresql.org/pg/commitdiff/31a891857a128828d47d93c63e041f3b69cbab70

Modified Files
--
doc/src/sgml/plpgsql.sgml |   24 +++-
src/pl/plpgsql/src/pl_exec.c  |  275 ++---
src/pl/plpgsql/src/pl_gram.y  |   82 +--
src/pl/plpgsql/src/pl_scanner.c   |   20 +++-
src/pl/plpgsql/src/plpgsql.h  |1 +
src/test/regress/expected/plpgsql.out |  132 
src/test/regress/sql/plpgsql.sql  |  112 +
7 files changed, 508 insertions(+), 138 deletions(-)


-- 
Sent via pgsql-committers mailing list ([email protected])
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-committers