pgsql: Change shutdown sequence to terminate checkpointer last - Mailing list pgsql-committers

From Andres Freund
Subject pgsql: Change shutdown sequence to terminate checkpointer last
Date
Msg-id E1tbjGJ-003Tkb-Cq@gemulon.postgresql.org
Whole thread Raw
List pgsql-committers
Change shutdown sequence to terminate checkpointer last

The main motivation for this change is to have a process that can serialize
stats after all other processes have terminated. Serializing stats already
happens in checkpointer, even though walsenders can be active longer.

The only reason the current shutdown sequence does not actively cause problems
is that walsender currently does not generate any stats. However, there is an
upcoming patch changing that.

Another need for this change originates in the AIO patchset, where IO
workers (which, in some edge cases, can emit stats of their own) need to run
while the shutdown checkpoint is being written.

This commit changes the shutdown sequence so checkpointer is signalled (via
SIGINT) to trigger writing the shutdown checkpoint without also causing
checkpointer to exit.  Once checkpointer wrote the shutdown checkpoint it
notifies postmaster via PMSIGNAL_XLOG_IS_SHUTDOWN and waits for the
termination signal (SIGUSR2, as before).  Checkpointer now is terminated after
all children, other than dead-end children and logger, have been terminated,
tracked using the new PM_WAIT_CHECKPOINTER PMState.

Reviewed-by: Heikki Linnakangas <hlinnaka@iki.fi>
Reviewed-by: Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
Reviewed-by: Nazir Bilal Yavuz <byavuz81@gmail.com>
Discussion: https://postgr.es/m/kgng5nrvnlv335evmsuvpnh354rw7qyazl73kdysev2cr2v5zu@m3cfzxicm5kp

Branch
------
master

Details
-------
https://git.postgresql.org/pg/commitdiff/87a6690cc69530703b7da7e72769bae2ac5b2e77

Modified Files
--------------
src/backend/postmaster/checkpointer.c           | 127 ++++++++++++++++------
src/backend/postmaster/postmaster.c             | 139 ++++++++++++++++++------
src/backend/utils/activity/wait_event_names.txt |   1 +
src/include/storage/pmsignal.h                  |   3 +-
4 files changed, 201 insertions(+), 69 deletions(-)


pgsql-committers by date:

Previous
From: Tom Lane
Date:
Subject: pgsql: Tighten pg_restore's recognition of its -F (format) option value
Next
From: Tom Lane
Date:
Subject: pgsql: Doc: recommend "psql -X" for restoring pg_dump scripts.