2004-07-19 04:47:16 +02:00
|
|
|
/*-------------------------------------------------------------------------
|
|
|
|
*
|
|
|
|
* pgarch.c
|
|
|
|
*
|
|
|
|
* PostgreSQL WAL archiver
|
|
|
|
*
|
|
|
|
* All functions relating to archiver are included here
|
|
|
|
*
|
|
|
|
* - All functions executed by archiver process
|
|
|
|
*
|
|
|
|
* - archiver is forked from postmaster, and the two
|
|
|
|
* processes then communicate using signals. All functions
|
|
|
|
* executed by postmaster are included in this file.
|
|
|
|
*
|
|
|
|
* Initial author: Simon Riggs simon@2ndquadrant.com
|
|
|
|
*
|
2024-01-04 02:49:05 +01:00
|
|
|
* Portions Copyright (c) 1996-2024, PostgreSQL Global Development Group
|
2004-07-19 04:47:16 +02:00
|
|
|
* Portions Copyright (c) 1994, Regents of the University of California
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* IDENTIFICATION
|
2010-09-20 22:08:53 +02:00
|
|
|
* src/backend/postmaster/pgarch.c
|
2004-07-19 04:47:16 +02:00
|
|
|
*
|
|
|
|
*-------------------------------------------------------------------------
|
|
|
|
*/
|
|
|
|
#include "postgres.h"
|
|
|
|
|
|
|
|
#include <time.h>
|
Ensure cleanup of orphan archive status files
When a WAL segment is recycled, its ".ready" and ".done" status files
get also automatically removed, however this is not done in a durable
manner. Hence, in a subsequent crash, it could be possible that a
".ready" status file is still around with its corresponding segment
already gone.
If the backend reaches such a state, the archive command would most
likely complain about a segment non-existing and would keep retrying,
causing WAL segments to bloat pg_wal/, potentially making Postgres crash
hard when running out of space.
As status files are removed after each individual segment, using
durable_unlink() does not completely close the window either, as a crash
could happen between the moment the WAL segment is recycled and the
moment its status files are removed. This has also some performance
impact with the additional fsync() calls needed to make the removal in a
durable manner. Doing the cleanup at recovery is not cost-free either
as this makes crash recovery potentially take longer than necessary.
So, instead, as per an idea of Stephen Frost, make the archiver aware of
orphan status files and remove them on-the-fly if the corresponding
segment goes missing. Removal failures follow a model close to what
happens for WAL segments, where multiple attempts are done before giving
up temporarily, and where a successful orphan removal makes the archiver
move immediately to the next WAL segment thought as ready to be
archived.
Author: Michael Paquier
Reviewed-by: Nathan Bossart, Andres Freund, Stephen Frost, Kyotaro
Horiguchi
Discussion: https://postgr.es/m/20180928032827.GF1500@paquier.xyz
2018-12-10 07:00:59 +01:00
|
|
|
#include <sys/stat.h>
|
2004-07-19 04:47:16 +02:00
|
|
|
#include <unistd.h>
|
|
|
|
|
2012-12-13 13:59:13 +01:00
|
|
|
#include "access/xlog.h"
|
2004-07-22 00:31:26 +02:00
|
|
|
#include "access/xlog_internal.h"
|
Redesign archive modules
A new callback named startup_cb, called shortly after a module is
loaded, is added. This makes possible the initialization of any
additional state data required by a module. This initial state data can
be saved in a ArchiveModuleState, that is now passed down to all the
callbacks that can be defined in a module. With this design, it is
possible to have a per-module state, aimed at opening the door to the
support of more than one archive module.
The initialization of the callbacks is changed so as
_PG_archive_module_init() does not anymore give in input a
ArchiveModuleCallbacks that a module has to fill in with callback
definitions. Instead, a module now needs to return a const
ArchiveModuleCallbacks.
All the structure and callback definitions of archive modules are moved
into their own header, named archive_module.h, from pgarch.h.
Command-based archiving follows the same line, with a new set of files
named shell_archive.{c,h}.
There are a few more items that are under discussion to improve the
design of archive modules, like the fact that basic_archive calls
sigsetjmp() by itself to define its own error handling flow. These will
be adjusted later, the changes done here cover already a good portion
of what has been discussed.
Any modules created for v15 will need to be adjusted to this new
design.
Author: Nathan Bossart
Reviewed-by: Andres Freund
Discussion: https://postgr.es/m/20230130194810.6fztfgbn32e7qarj@awork3.anarazel.de
2023-02-17 06:26:42 +01:00
|
|
|
#include "archive/archive_module.h"
|
|
|
|
#include "archive/shell_archive.h"
|
2021-11-11 21:02:53 +01:00
|
|
|
#include "lib/binaryheap.h"
|
2004-07-19 04:47:16 +02:00
|
|
|
#include "libpq/pqsignal.h"
|
2014-01-28 18:58:22 +01:00
|
|
|
#include "pgstat.h"
|
2024-03-18 10:35:08 +01:00
|
|
|
#include "postmaster/auxprocess.h"
|
2019-12-17 19:14:28 +01:00
|
|
|
#include "postmaster/interrupt.h"
|
2004-07-22 00:31:26 +02:00
|
|
|
#include "postmaster/pgarch.h"
|
2004-07-19 04:47:16 +02:00
|
|
|
#include "storage/fd.h"
|
|
|
|
#include "storage/ipc.h"
|
Introduce a pipe between postmaster and each backend, which can be used to
detect postmaster death. Postmaster keeps the write-end of the pipe open,
so when it dies, children get EOF in the read-end. That can conveniently
be waited for in select(), which allows eliminating some of the polling
loops that check for postmaster death. This patch doesn't yet change all
the loops to use the new mechanism, expect a follow-on patch to do that.
This changes the interface to WaitLatch, so that it takes as argument a
bitmask of events that it waits for. Possible events are latch set, timeout,
postmaster death, and socket becoming readable or writeable.
The pipe method behaves slightly differently from the kill() method
previously used in PostmasterIsAlive() in the case that postmaster has died,
but its parent has not yet read its exit code with waitpid(). The pipe
returns EOF as soon as the process dies, but kill() continues to return
true until waitpid() has been called (IOW while the process is a zombie).
Because of that, change PostmasterIsAlive() to use the pipe too, otherwise
WaitLatch() would return immediately with WL_POSTMASTER_DEATH, while
PostmasterIsAlive() would claim it's still alive. That could easily lead to
busy-waiting while postmaster is in zombie state.
Peter Geoghegan with further changes by me, reviewed by Fujii Masao and
Florian Pflug.
2011-07-08 17:27:49 +02:00
|
|
|
#include "storage/latch.h"
|
2004-07-19 04:47:16 +02:00
|
|
|
#include "storage/pmsignal.h"
|
2021-04-03 05:01:14 +02:00
|
|
|
#include "storage/proc.h"
|
Make archiver process an auxiliary process.
This commit changes WAL archiver process so that it's treated as
an auxiliary process and can use shared memory. This is an infrastructure
patch required for upcoming shared-memory based stats collector patch
series. These patch series basically need any processes including archiver
that can report the statistics to access to shared memory. Since this patch
itself is useful to simplify the code and when users monitor the status of
archiver, it's committed separately in advance.
This commit simplifies the code for WAL archiving. For example, previously
backends need to signal to archiver via postmaster when they notify
archiver that there are some WAL files to archive. On the other hand,
this commit removes that signal to postmaster and enables backends to
notify archier directly using shared latch.
Also, as the side of this change, the information about archiver process
becomes viewable at pg_stat_activity view.
Author: Kyotaro Horiguchi
Reviewed-by: Andres Freund, Álvaro Herrera, Julien Rouhaud, Tomas Vondra, Arthur Zakirov, Fujii Masao
Discussion: https://postgr.es/m/20180629.173418.190173462.horiguchi.kyotaro@lab.ntt.co.jp
2021-03-15 05:13:14 +01:00
|
|
|
#include "storage/procsignal.h"
|
2021-04-03 05:01:14 +02:00
|
|
|
#include "storage/shmem.h"
|
2004-07-19 04:47:16 +02:00
|
|
|
#include "utils/guc.h"
|
2022-01-11 15:19:59 +01:00
|
|
|
#include "utils/memutils.h"
|
2004-07-19 04:47:16 +02:00
|
|
|
#include "utils/ps_status.h"
|
|
|
|
|
|
|
|
|
|
|
|
/* ----------
|
|
|
|
* Timer definitions.
|
|
|
|
* ----------
|
|
|
|
*/
|
|
|
|
#define PGARCH_AUTOWAKE_INTERVAL 60 /* How often to force a poll of the
|
|
|
|
* archive status directory; in seconds. */
|
2004-12-02 23:40:18 +01:00
|
|
|
#define PGARCH_RESTART_INTERVAL 10 /* How often to attempt to restart a
|
2004-07-19 04:47:16 +02:00
|
|
|
* failed archiver; in seconds. */
|
|
|
|
|
Ensure cleanup of orphan archive status files
When a WAL segment is recycled, its ".ready" and ".done" status files
get also automatically removed, however this is not done in a durable
manner. Hence, in a subsequent crash, it could be possible that a
".ready" status file is still around with its corresponding segment
already gone.
If the backend reaches such a state, the archive command would most
likely complain about a segment non-existing and would keep retrying,
causing WAL segments to bloat pg_wal/, potentially making Postgres crash
hard when running out of space.
As status files are removed after each individual segment, using
durable_unlink() does not completely close the window either, as a crash
could happen between the moment the WAL segment is recycled and the
moment its status files are removed. This has also some performance
impact with the additional fsync() calls needed to make the removal in a
durable manner. Doing the cleanup at recovery is not cost-free either
as this makes crash recovery potentially take longer than necessary.
So, instead, as per an idea of Stephen Frost, make the archiver aware of
orphan status files and remove them on-the-fly if the corresponding
segment goes missing. Removal failures follow a model close to what
happens for WAL segments, where multiple attempts are done before giving
up temporarily, and where a successful orphan removal makes the archiver
move immediately to the next WAL segment thought as ready to be
archived.
Author: Michael Paquier
Reviewed-by: Nathan Bossart, Andres Freund, Stephen Frost, Kyotaro
Horiguchi
Discussion: https://postgr.es/m/20180928032827.GF1500@paquier.xyz
2018-12-10 07:00:59 +01:00
|
|
|
/*
|
|
|
|
* Maximum number of retries allowed when attempting to archive a WAL
|
|
|
|
* file.
|
|
|
|
*/
|
2004-07-19 04:47:16 +02:00
|
|
|
#define NUM_ARCHIVE_RETRIES 3
|
|
|
|
|
Ensure cleanup of orphan archive status files
When a WAL segment is recycled, its ".ready" and ".done" status files
get also automatically removed, however this is not done in a durable
manner. Hence, in a subsequent crash, it could be possible that a
".ready" status file is still around with its corresponding segment
already gone.
If the backend reaches such a state, the archive command would most
likely complain about a segment non-existing and would keep retrying,
causing WAL segments to bloat pg_wal/, potentially making Postgres crash
hard when running out of space.
As status files are removed after each individual segment, using
durable_unlink() does not completely close the window either, as a crash
could happen between the moment the WAL segment is recycled and the
moment its status files are removed. This has also some performance
impact with the additional fsync() calls needed to make the removal in a
durable manner. Doing the cleanup at recovery is not cost-free either
as this makes crash recovery potentially take longer than necessary.
So, instead, as per an idea of Stephen Frost, make the archiver aware of
orphan status files and remove them on-the-fly if the corresponding
segment goes missing. Removal failures follow a model close to what
happens for WAL segments, where multiple attempts are done before giving
up temporarily, and where a successful orphan removal makes the archiver
move immediately to the next WAL segment thought as ready to be
archived.
Author: Michael Paquier
Reviewed-by: Nathan Bossart, Andres Freund, Stephen Frost, Kyotaro
Horiguchi
Discussion: https://postgr.es/m/20180928032827.GF1500@paquier.xyz
2018-12-10 07:00:59 +01:00
|
|
|
/*
|
|
|
|
* Maximum number of retries allowed when attempting to remove an
|
|
|
|
* orphan archive status file.
|
|
|
|
*/
|
|
|
|
#define NUM_ORPHAN_CLEANUP_RETRIES 3
|
|
|
|
|
2021-11-11 21:02:53 +01:00
|
|
|
/*
|
|
|
|
* Maximum number of .ready files to gather per directory scan.
|
|
|
|
*/
|
|
|
|
#define NUM_FILES_PER_DIRECTORY_SCAN 64
|
|
|
|
|
Make archiver process an auxiliary process.
This commit changes WAL archiver process so that it's treated as
an auxiliary process and can use shared memory. This is an infrastructure
patch required for upcoming shared-memory based stats collector patch
series. These patch series basically need any processes including archiver
that can report the statistics to access to shared memory. Since this patch
itself is useful to simplify the code and when users monitor the status of
archiver, it's committed separately in advance.
This commit simplifies the code for WAL archiving. For example, previously
backends need to signal to archiver via postmaster when they notify
archiver that there are some WAL files to archive. On the other hand,
this commit removes that signal to postmaster and enables backends to
notify archier directly using shared latch.
Also, as the side of this change, the information about archiver process
becomes viewable at pg_stat_activity view.
Author: Kyotaro Horiguchi
Reviewed-by: Andres Freund, Álvaro Herrera, Julien Rouhaud, Tomas Vondra, Arthur Zakirov, Fujii Masao
Discussion: https://postgr.es/m/20180629.173418.190173462.horiguchi.kyotaro@lab.ntt.co.jp
2021-03-15 05:13:14 +01:00
|
|
|
/* Shared memory area for archiver process */
|
|
|
|
typedef struct PgArchData
|
|
|
|
{
|
2024-03-03 18:38:22 +01:00
|
|
|
int pgprocno; /* proc number of archiver process */
|
2021-11-11 21:02:53 +01:00
|
|
|
|
|
|
|
/*
|
2024-02-29 17:17:55 +01:00
|
|
|
* Forces a directory scan in pgarch_readyXlog().
|
2021-11-11 21:02:53 +01:00
|
|
|
*/
|
2024-02-29 17:17:55 +01:00
|
|
|
pg_atomic_uint32 force_dir_scan;
|
Make archiver process an auxiliary process.
This commit changes WAL archiver process so that it's treated as
an auxiliary process and can use shared memory. This is an infrastructure
patch required for upcoming shared-memory based stats collector patch
series. These patch series basically need any processes including archiver
that can report the statistics to access to shared memory. Since this patch
itself is useful to simplify the code and when users monitor the status of
archiver, it's committed separately in advance.
This commit simplifies the code for WAL archiving. For example, previously
backends need to signal to archiver via postmaster when they notify
archiver that there are some WAL files to archive. On the other hand,
this commit removes that signal to postmaster and enables backends to
notify archier directly using shared latch.
Also, as the side of this change, the information about archiver process
becomes viewable at pg_stat_activity view.
Author: Kyotaro Horiguchi
Reviewed-by: Andres Freund, Álvaro Herrera, Julien Rouhaud, Tomas Vondra, Arthur Zakirov, Fujii Masao
Discussion: https://postgr.es/m/20180629.173418.190173462.horiguchi.kyotaro@lab.ntt.co.jp
2021-03-15 05:13:14 +01:00
|
|
|
} PgArchData;
|
|
|
|
|
2022-02-03 19:57:27 +01:00
|
|
|
char *XLogArchiveLibrary = "";
|
2024-03-04 22:41:42 +01:00
|
|
|
char *arch_module_check_errdetail_string;
|
2022-02-03 19:57:27 +01:00
|
|
|
|
2004-07-19 04:47:16 +02:00
|
|
|
|
|
|
|
/* ----------
|
|
|
|
* Local data
|
|
|
|
* ----------
|
|
|
|
*/
|
2008-01-11 01:54:09 +01:00
|
|
|
static time_t last_sigterm_time = 0;
|
Make archiver process an auxiliary process.
This commit changes WAL archiver process so that it's treated as
an auxiliary process and can use shared memory. This is an infrastructure
patch required for upcoming shared-memory based stats collector patch
series. These patch series basically need any processes including archiver
that can report the statistics to access to shared memory. Since this patch
itself is useful to simplify the code and when users monitor the status of
archiver, it's committed separately in advance.
This commit simplifies the code for WAL archiving. For example, previously
backends need to signal to archiver via postmaster when they notify
archiver that there are some WAL files to archive. On the other hand,
this commit removes that signal to postmaster and enables backends to
notify archier directly using shared latch.
Also, as the side of this change, the information about archiver process
becomes viewable at pg_stat_activity view.
Author: Kyotaro Horiguchi
Reviewed-by: Andres Freund, Álvaro Herrera, Julien Rouhaud, Tomas Vondra, Arthur Zakirov, Fujii Masao
Discussion: https://postgr.es/m/20180629.173418.190173462.horiguchi.kyotaro@lab.ntt.co.jp
2021-03-15 05:13:14 +01:00
|
|
|
static PgArchData *PgArch = NULL;
|
Redesign archive modules
A new callback named startup_cb, called shortly after a module is
loaded, is added. This makes possible the initialization of any
additional state data required by a module. This initial state data can
be saved in a ArchiveModuleState, that is now passed down to all the
callbacks that can be defined in a module. With this design, it is
possible to have a per-module state, aimed at opening the door to the
support of more than one archive module.
The initialization of the callbacks is changed so as
_PG_archive_module_init() does not anymore give in input a
ArchiveModuleCallbacks that a module has to fill in with callback
definitions. Instead, a module now needs to return a const
ArchiveModuleCallbacks.
All the structure and callback definitions of archive modules are moved
into their own header, named archive_module.h, from pgarch.h.
Command-based archiving follows the same line, with a new set of files
named shell_archive.{c,h}.
There are a few more items that are under discussion to improve the
design of archive modules, like the fact that basic_archive calls
sigsetjmp() by itself to define its own error handling flow. These will
be adjusted later, the changes done here cover already a good portion
of what has been discussed.
Any modules created for v15 will need to be adjusted to this new
design.
Author: Nathan Bossart
Reviewed-by: Andres Freund
Discussion: https://postgr.es/m/20230130194810.6fztfgbn32e7qarj@awork3.anarazel.de
2023-02-17 06:26:42 +01:00
|
|
|
static const ArchiveModuleCallbacks *ArchiveCallbacks;
|
|
|
|
static ArchiveModuleState *archive_module_state;
|
2022-02-03 19:57:27 +01:00
|
|
|
|
2004-07-19 04:47:16 +02:00
|
|
|
|
2021-11-11 21:02:53 +01:00
|
|
|
/*
|
|
|
|
* Stuff for tracking multiple files to archive from each scan of
|
|
|
|
* archive_status. Minimizing the number of directory scans when there are
|
|
|
|
* many files to archive can significantly improve archival rate.
|
|
|
|
*
|
|
|
|
* arch_heap is a max-heap that is used during the directory scan to track
|
|
|
|
* the highest-priority files to archive. After the directory scan
|
|
|
|
* completes, the file names are stored in ascending order of priority in
|
|
|
|
* arch_files. pgarch_readyXlog() returns files from arch_files until it
|
|
|
|
* is empty, at which point another directory scan must be performed.
|
2021-12-29 23:02:50 +01:00
|
|
|
*
|
|
|
|
* We only need this data in the archiver process, so make it a palloc'd
|
|
|
|
* struct rather than a bunch of static arrays.
|
2021-11-11 21:02:53 +01:00
|
|
|
*/
|
2021-12-29 23:02:50 +01:00
|
|
|
struct arch_files_state
|
|
|
|
{
|
|
|
|
binaryheap *arch_heap;
|
|
|
|
int arch_files_size; /* number of live entries in arch_files[] */
|
|
|
|
char *arch_files[NUM_FILES_PER_DIRECTORY_SCAN];
|
|
|
|
/* buffers underlying heap, and later arch_files[], entries: */
|
|
|
|
char arch_filenames[NUM_FILES_PER_DIRECTORY_SCAN][MAX_XFN_CHARS + 1];
|
|
|
|
};
|
|
|
|
|
|
|
|
static struct arch_files_state *arch_files = NULL;
|
2021-11-11 21:02:53 +01:00
|
|
|
|
2004-07-19 04:47:16 +02:00
|
|
|
/*
|
|
|
|
* Flags set by interrupt handlers for later service in the main loop.
|
|
|
|
*/
|
2008-01-11 01:54:09 +01:00
|
|
|
static volatile sig_atomic_t ready_to_stop = false;
|
2004-07-19 04:47:16 +02:00
|
|
|
|
|
|
|
/* ----------
|
|
|
|
* Local function forward declarations
|
|
|
|
* ----------
|
|
|
|
*/
|
2008-01-11 01:54:09 +01:00
|
|
|
static void pgarch_waken_stop(SIGNAL_ARGS);
|
2004-07-19 04:47:16 +02:00
|
|
|
static void pgarch_MainLoop(void);
|
|
|
|
static void pgarch_ArchiverCopyLoop(void);
|
|
|
|
static bool pgarch_archiveXlog(char *xlog);
|
|
|
|
static bool pgarch_readyXlog(char *xlog);
|
|
|
|
static void pgarch_archiveDone(char *xlog);
|
Make archiver process an auxiliary process.
This commit changes WAL archiver process so that it's treated as
an auxiliary process and can use shared memory. This is an infrastructure
patch required for upcoming shared-memory based stats collector patch
series. These patch series basically need any processes including archiver
that can report the statistics to access to shared memory. Since this patch
itself is useful to simplify the code and when users monitor the status of
archiver, it's committed separately in advance.
This commit simplifies the code for WAL archiving. For example, previously
backends need to signal to archiver via postmaster when they notify
archiver that there are some WAL files to archive. On the other hand,
this commit removes that signal to postmaster and enables backends to
notify archier directly using shared latch.
Also, as the side of this change, the information about archiver process
becomes viewable at pg_stat_activity view.
Author: Kyotaro Horiguchi
Reviewed-by: Andres Freund, Álvaro Herrera, Julien Rouhaud, Tomas Vondra, Arthur Zakirov, Fujii Masao
Discussion: https://postgr.es/m/20180629.173418.190173462.horiguchi.kyotaro@lab.ntt.co.jp
2021-03-15 05:13:14 +01:00
|
|
|
static void pgarch_die(int code, Datum arg);
|
2021-06-18 10:57:09 +02:00
|
|
|
static void HandlePgArchInterrupts(void);
|
2021-11-11 21:02:53 +01:00
|
|
|
static int ready_file_comparator(Datum a, Datum b, void *arg);
|
2022-02-03 19:57:27 +01:00
|
|
|
static void LoadArchiveLibrary(void);
|
Rework shutdown callback of archiver modules
As currently designed, with a callback registered in a ERROR_CLEANUP
block, the shutdown callback would get called twice when updating
archive_library on SIGHUP, which is something that we want to avoid to
ease the life of extension writers.
Anyway, an ERROR in the archiver process is treated as a FATAL, stopping
it immediately, hence there is no need for a ERROR_CLEANUP block.
Instead of that, the shutdown callback is not called upon
before_shmem_exit(), giving to the modules the opportunity to do any
cleanup actions before the server shuts down its subsystems.
While on it, this commit adds some testing coverage for the shutdown
callback. Neither shell_archive nor basic_archive have been using it,
and one is added to shell_archive, whose trigger is checked in a TAP
test through a shutdown sequence.
Author: Nathan Bossart, Bharath Rupireddy
Reviewed-by: Kyotaro Horiguchi, Michael Paquier
Discussion: https://postgr.es/m/20221015221328.GB1821022@nathanxps13
Backpatch-through: 15
2022-10-19 07:06:56 +02:00
|
|
|
static void pgarch_call_module_shutdown_cb(int code, Datum arg);
|
2004-07-19 04:47:16 +02:00
|
|
|
|
Make archiver process an auxiliary process.
This commit changes WAL archiver process so that it's treated as
an auxiliary process and can use shared memory. This is an infrastructure
patch required for upcoming shared-memory based stats collector patch
series. These patch series basically need any processes including archiver
that can report the statistics to access to shared memory. Since this patch
itself is useful to simplify the code and when users monitor the status of
archiver, it's committed separately in advance.
This commit simplifies the code for WAL archiving. For example, previously
backends need to signal to archiver via postmaster when they notify
archiver that there are some WAL files to archive. On the other hand,
this commit removes that signal to postmaster and enables backends to
notify archier directly using shared latch.
Also, as the side of this change, the information about archiver process
becomes viewable at pg_stat_activity view.
Author: Kyotaro Horiguchi
Reviewed-by: Andres Freund, Álvaro Herrera, Julien Rouhaud, Tomas Vondra, Arthur Zakirov, Fujii Masao
Discussion: https://postgr.es/m/20180629.173418.190173462.horiguchi.kyotaro@lab.ntt.co.jp
2021-03-15 05:13:14 +01:00
|
|
|
/* Report shared memory space needed by PgArchShmemInit */
|
|
|
|
Size
|
|
|
|
PgArchShmemSize(void)
|
2004-07-19 04:47:16 +02:00
|
|
|
{
|
Make archiver process an auxiliary process.
This commit changes WAL archiver process so that it's treated as
an auxiliary process and can use shared memory. This is an infrastructure
patch required for upcoming shared-memory based stats collector patch
series. These patch series basically need any processes including archiver
that can report the statistics to access to shared memory. Since this patch
itself is useful to simplify the code and when users monitor the status of
archiver, it's committed separately in advance.
This commit simplifies the code for WAL archiving. For example, previously
backends need to signal to archiver via postmaster when they notify
archiver that there are some WAL files to archive. On the other hand,
this commit removes that signal to postmaster and enables backends to
notify archier directly using shared latch.
Also, as the side of this change, the information about archiver process
becomes viewable at pg_stat_activity view.
Author: Kyotaro Horiguchi
Reviewed-by: Andres Freund, Álvaro Herrera, Julien Rouhaud, Tomas Vondra, Arthur Zakirov, Fujii Masao
Discussion: https://postgr.es/m/20180629.173418.190173462.horiguchi.kyotaro@lab.ntt.co.jp
2021-03-15 05:13:14 +01:00
|
|
|
Size size = 0;
|
2004-07-19 04:47:16 +02:00
|
|
|
|
Make archiver process an auxiliary process.
This commit changes WAL archiver process so that it's treated as
an auxiliary process and can use shared memory. This is an infrastructure
patch required for upcoming shared-memory based stats collector patch
series. These patch series basically need any processes including archiver
that can report the statistics to access to shared memory. Since this patch
itself is useful to simplify the code and when users monitor the status of
archiver, it's committed separately in advance.
This commit simplifies the code for WAL archiving. For example, previously
backends need to signal to archiver via postmaster when they notify
archiver that there are some WAL files to archive. On the other hand,
this commit removes that signal to postmaster and enables backends to
notify archier directly using shared latch.
Also, as the side of this change, the information about archiver process
becomes viewable at pg_stat_activity view.
Author: Kyotaro Horiguchi
Reviewed-by: Andres Freund, Álvaro Herrera, Julien Rouhaud, Tomas Vondra, Arthur Zakirov, Fujii Masao
Discussion: https://postgr.es/m/20180629.173418.190173462.horiguchi.kyotaro@lab.ntt.co.jp
2021-03-15 05:13:14 +01:00
|
|
|
size = add_size(size, sizeof(PgArchData));
|
2004-07-19 04:47:16 +02:00
|
|
|
|
Make archiver process an auxiliary process.
This commit changes WAL archiver process so that it's treated as
an auxiliary process and can use shared memory. This is an infrastructure
patch required for upcoming shared-memory based stats collector patch
series. These patch series basically need any processes including archiver
that can report the statistics to access to shared memory. Since this patch
itself is useful to simplify the code and when users monitor the status of
archiver, it's committed separately in advance.
This commit simplifies the code for WAL archiving. For example, previously
backends need to signal to archiver via postmaster when they notify
archiver that there are some WAL files to archive. On the other hand,
this commit removes that signal to postmaster and enables backends to
notify archier directly using shared latch.
Also, as the side of this change, the information about archiver process
becomes viewable at pg_stat_activity view.
Author: Kyotaro Horiguchi
Reviewed-by: Andres Freund, Álvaro Herrera, Julien Rouhaud, Tomas Vondra, Arthur Zakirov, Fujii Masao
Discussion: https://postgr.es/m/20180629.173418.190173462.horiguchi.kyotaro@lab.ntt.co.jp
2021-03-15 05:13:14 +01:00
|
|
|
return size;
|
|
|
|
}
|
2004-07-19 04:47:16 +02:00
|
|
|
|
Make archiver process an auxiliary process.
This commit changes WAL archiver process so that it's treated as
an auxiliary process and can use shared memory. This is an infrastructure
patch required for upcoming shared-memory based stats collector patch
series. These patch series basically need any processes including archiver
that can report the statistics to access to shared memory. Since this patch
itself is useful to simplify the code and when users monitor the status of
archiver, it's committed separately in advance.
This commit simplifies the code for WAL archiving. For example, previously
backends need to signal to archiver via postmaster when they notify
archiver that there are some WAL files to archive. On the other hand,
this commit removes that signal to postmaster and enables backends to
notify archier directly using shared latch.
Also, as the side of this change, the information about archiver process
becomes viewable at pg_stat_activity view.
Author: Kyotaro Horiguchi
Reviewed-by: Andres Freund, Álvaro Herrera, Julien Rouhaud, Tomas Vondra, Arthur Zakirov, Fujii Masao
Discussion: https://postgr.es/m/20180629.173418.190173462.horiguchi.kyotaro@lab.ntt.co.jp
2021-03-15 05:13:14 +01:00
|
|
|
/* Allocate and initialize archiver-related shared memory */
|
|
|
|
void
|
|
|
|
PgArchShmemInit(void)
|
|
|
|
{
|
|
|
|
bool found;
|
2004-07-19 04:47:16 +02:00
|
|
|
|
Make archiver process an auxiliary process.
This commit changes WAL archiver process so that it's treated as
an auxiliary process and can use shared memory. This is an infrastructure
patch required for upcoming shared-memory based stats collector patch
series. These patch series basically need any processes including archiver
that can report the statistics to access to shared memory. Since this patch
itself is useful to simplify the code and when users monitor the status of
archiver, it's committed separately in advance.
This commit simplifies the code for WAL archiving. For example, previously
backends need to signal to archiver via postmaster when they notify
archiver that there are some WAL files to archive. On the other hand,
this commit removes that signal to postmaster and enables backends to
notify archier directly using shared latch.
Also, as the side of this change, the information about archiver process
becomes viewable at pg_stat_activity view.
Author: Kyotaro Horiguchi
Reviewed-by: Andres Freund, Álvaro Herrera, Julien Rouhaud, Tomas Vondra, Arthur Zakirov, Fujii Masao
Discussion: https://postgr.es/m/20180629.173418.190173462.horiguchi.kyotaro@lab.ntt.co.jp
2021-03-15 05:13:14 +01:00
|
|
|
PgArch = (PgArchData *)
|
|
|
|
ShmemInitStruct("Archiver Data", PgArchShmemSize(), &found);
|
2004-07-19 04:47:16 +02:00
|
|
|
|
Make archiver process an auxiliary process.
This commit changes WAL archiver process so that it's treated as
an auxiliary process and can use shared memory. This is an infrastructure
patch required for upcoming shared-memory based stats collector patch
series. These patch series basically need any processes including archiver
that can report the statistics to access to shared memory. Since this patch
itself is useful to simplify the code and when users monitor the status of
archiver, it's committed separately in advance.
This commit simplifies the code for WAL archiving. For example, previously
backends need to signal to archiver via postmaster when they notify
archiver that there are some WAL files to archive. On the other hand,
this commit removes that signal to postmaster and enables backends to
notify archier directly using shared latch.
Also, as the side of this change, the information about archiver process
becomes viewable at pg_stat_activity view.
Author: Kyotaro Horiguchi
Reviewed-by: Andres Freund, Álvaro Herrera, Julien Rouhaud, Tomas Vondra, Arthur Zakirov, Fujii Masao
Discussion: https://postgr.es/m/20180629.173418.190173462.horiguchi.kyotaro@lab.ntt.co.jp
2021-03-15 05:13:14 +01:00
|
|
|
if (!found)
|
|
|
|
{
|
|
|
|
/* First time through, so initialize */
|
|
|
|
MemSet(PgArch, 0, PgArchShmemSize());
|
2024-03-03 18:38:22 +01:00
|
|
|
PgArch->pgprocno = INVALID_PROC_NUMBER;
|
2024-02-29 17:17:55 +01:00
|
|
|
pg_atomic_init_u32(&PgArch->force_dir_scan, 0);
|
2004-07-19 04:47:16 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
Make archiver process an auxiliary process.
This commit changes WAL archiver process so that it's treated as
an auxiliary process and can use shared memory. This is an infrastructure
patch required for upcoming shared-memory based stats collector patch
series. These patch series basically need any processes including archiver
that can report the statistics to access to shared memory. Since this patch
itself is useful to simplify the code and when users monitor the status of
archiver, it's committed separately in advance.
This commit simplifies the code for WAL archiving. For example, previously
backends need to signal to archiver via postmaster when they notify
archiver that there are some WAL files to archive. On the other hand,
this commit removes that signal to postmaster and enables backends to
notify archier directly using shared latch.
Also, as the side of this change, the information about archiver process
becomes viewable at pg_stat_activity view.
Author: Kyotaro Horiguchi
Reviewed-by: Andres Freund, Álvaro Herrera, Julien Rouhaud, Tomas Vondra, Arthur Zakirov, Fujii Masao
Discussion: https://postgr.es/m/20180629.173418.190173462.horiguchi.kyotaro@lab.ntt.co.jp
2021-03-15 05:13:14 +01:00
|
|
|
* PgArchCanRestart
|
|
|
|
*
|
|
|
|
* Return true and archiver is allowed to restart if enough time has
|
|
|
|
* passed since it was launched last to reach PGARCH_RESTART_INTERVAL.
|
|
|
|
* Otherwise return false.
|
2004-07-19 04:47:16 +02:00
|
|
|
*
|
Make archiver process an auxiliary process.
This commit changes WAL archiver process so that it's treated as
an auxiliary process and can use shared memory. This is an infrastructure
patch required for upcoming shared-memory based stats collector patch
series. These patch series basically need any processes including archiver
that can report the statistics to access to shared memory. Since this patch
itself is useful to simplify the code and when users monitor the status of
archiver, it's committed separately in advance.
This commit simplifies the code for WAL archiving. For example, previously
backends need to signal to archiver via postmaster when they notify
archiver that there are some WAL files to archive. On the other hand,
this commit removes that signal to postmaster and enables backends to
notify archier directly using shared latch.
Also, as the side of this change, the information about archiver process
becomes viewable at pg_stat_activity view.
Author: Kyotaro Horiguchi
Reviewed-by: Andres Freund, Álvaro Herrera, Julien Rouhaud, Tomas Vondra, Arthur Zakirov, Fujii Masao
Discussion: https://postgr.es/m/20180629.173418.190173462.horiguchi.kyotaro@lab.ntt.co.jp
2021-03-15 05:13:14 +01:00
|
|
|
* This is a safety valve to protect against continuous respawn attempts if the
|
|
|
|
* archiver is dying immediately at launch. Note that since we will retry to
|
|
|
|
* launch the archiver from the postmaster main loop, we will get another
|
|
|
|
* chance later.
|
2004-07-19 04:47:16 +02:00
|
|
|
*/
|
Make archiver process an auxiliary process.
This commit changes WAL archiver process so that it's treated as
an auxiliary process and can use shared memory. This is an infrastructure
patch required for upcoming shared-memory based stats collector patch
series. These patch series basically need any processes including archiver
that can report the statistics to access to shared memory. Since this patch
itself is useful to simplify the code and when users monitor the status of
archiver, it's committed separately in advance.
This commit simplifies the code for WAL archiving. For example, previously
backends need to signal to archiver via postmaster when they notify
archiver that there are some WAL files to archive. On the other hand,
this commit removes that signal to postmaster and enables backends to
notify archier directly using shared latch.
Also, as the side of this change, the information about archiver process
becomes viewable at pg_stat_activity view.
Author: Kyotaro Horiguchi
Reviewed-by: Andres Freund, Álvaro Herrera, Julien Rouhaud, Tomas Vondra, Arthur Zakirov, Fujii Masao
Discussion: https://postgr.es/m/20180629.173418.190173462.horiguchi.kyotaro@lab.ntt.co.jp
2021-03-15 05:13:14 +01:00
|
|
|
bool
|
|
|
|
PgArchCanRestart(void)
|
2004-07-19 04:47:16 +02:00
|
|
|
{
|
Make archiver process an auxiliary process.
This commit changes WAL archiver process so that it's treated as
an auxiliary process and can use shared memory. This is an infrastructure
patch required for upcoming shared-memory based stats collector patch
series. These patch series basically need any processes including archiver
that can report the statistics to access to shared memory. Since this patch
itself is useful to simplify the code and when users monitor the status of
archiver, it's committed separately in advance.
This commit simplifies the code for WAL archiving. For example, previously
backends need to signal to archiver via postmaster when they notify
archiver that there are some WAL files to archive. On the other hand,
this commit removes that signal to postmaster and enables backends to
notify archier directly using shared latch.
Also, as the side of this change, the information about archiver process
becomes viewable at pg_stat_activity view.
Author: Kyotaro Horiguchi
Reviewed-by: Andres Freund, Álvaro Herrera, Julien Rouhaud, Tomas Vondra, Arthur Zakirov, Fujii Masao
Discussion: https://postgr.es/m/20180629.173418.190173462.horiguchi.kyotaro@lab.ntt.co.jp
2021-03-15 05:13:14 +01:00
|
|
|
static time_t last_pgarch_start_time = 0;
|
|
|
|
time_t curtime = time(NULL);
|
2004-07-19 04:47:16 +02:00
|
|
|
|
Make archiver process an auxiliary process.
This commit changes WAL archiver process so that it's treated as
an auxiliary process and can use shared memory. This is an infrastructure
patch required for upcoming shared-memory based stats collector patch
series. These patch series basically need any processes including archiver
that can report the statistics to access to shared memory. Since this patch
itself is useful to simplify the code and when users monitor the status of
archiver, it's committed separately in advance.
This commit simplifies the code for WAL archiving. For example, previously
backends need to signal to archiver via postmaster when they notify
archiver that there are some WAL files to archive. On the other hand,
this commit removes that signal to postmaster and enables backends to
notify archier directly using shared latch.
Also, as the side of this change, the information about archiver process
becomes viewable at pg_stat_activity view.
Author: Kyotaro Horiguchi
Reviewed-by: Andres Freund, Álvaro Herrera, Julien Rouhaud, Tomas Vondra, Arthur Zakirov, Fujii Masao
Discussion: https://postgr.es/m/20180629.173418.190173462.horiguchi.kyotaro@lab.ntt.co.jp
2021-03-15 05:13:14 +01:00
|
|
|
/*
|
|
|
|
* Return false and don't restart archiver if too soon since last archiver
|
|
|
|
* start.
|
|
|
|
*/
|
|
|
|
if ((unsigned int) (curtime - last_pgarch_start_time) <
|
|
|
|
(unsigned int) PGARCH_RESTART_INTERVAL)
|
|
|
|
return false;
|
2004-07-19 04:47:16 +02:00
|
|
|
|
Make archiver process an auxiliary process.
This commit changes WAL archiver process so that it's treated as
an auxiliary process and can use shared memory. This is an infrastructure
patch required for upcoming shared-memory based stats collector patch
series. These patch series basically need any processes including archiver
that can report the statistics to access to shared memory. Since this patch
itself is useful to simplify the code and when users monitor the status of
archiver, it's committed separately in advance.
This commit simplifies the code for WAL archiving. For example, previously
backends need to signal to archiver via postmaster when they notify
archiver that there are some WAL files to archive. On the other hand,
this commit removes that signal to postmaster and enables backends to
notify archier directly using shared latch.
Also, as the side of this change, the information about archiver process
becomes viewable at pg_stat_activity view.
Author: Kyotaro Horiguchi
Reviewed-by: Andres Freund, Álvaro Herrera, Julien Rouhaud, Tomas Vondra, Arthur Zakirov, Fujii Masao
Discussion: https://postgr.es/m/20180629.173418.190173462.horiguchi.kyotaro@lab.ntt.co.jp
2021-03-15 05:13:14 +01:00
|
|
|
last_pgarch_start_time = curtime;
|
|
|
|
return true;
|
2004-07-19 04:47:16 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
Make archiver process an auxiliary process.
This commit changes WAL archiver process so that it's treated as
an auxiliary process and can use shared memory. This is an infrastructure
patch required for upcoming shared-memory based stats collector patch
series. These patch series basically need any processes including archiver
that can report the statistics to access to shared memory. Since this patch
itself is useful to simplify the code and when users monitor the status of
archiver, it's committed separately in advance.
This commit simplifies the code for WAL archiving. For example, previously
backends need to signal to archiver via postmaster when they notify
archiver that there are some WAL files to archive. On the other hand,
this commit removes that signal to postmaster and enables backends to
notify archier directly using shared latch.
Also, as the side of this change, the information about archiver process
becomes viewable at pg_stat_activity view.
Author: Kyotaro Horiguchi
Reviewed-by: Andres Freund, Álvaro Herrera, Julien Rouhaud, Tomas Vondra, Arthur Zakirov, Fujii Masao
Discussion: https://postgr.es/m/20180629.173418.190173462.horiguchi.kyotaro@lab.ntt.co.jp
2021-03-15 05:13:14 +01:00
|
|
|
/* Main entry point for archiver process */
|
|
|
|
void
|
2024-03-18 10:35:08 +01:00
|
|
|
PgArchiverMain(char *startup_data, size_t startup_data_len)
|
2004-07-19 04:47:16 +02:00
|
|
|
{
|
2024-03-18 10:35:08 +01:00
|
|
|
Assert(startup_data_len == 0);
|
|
|
|
|
|
|
|
MyBackendType = B_ARCHIVER;
|
|
|
|
AuxiliaryProcessMainCommon();
|
|
|
|
|
2004-07-19 04:47:16 +02:00
|
|
|
/*
|
|
|
|
* Ignore all signals usually bound to some action in the postmaster,
|
2008-01-11 01:54:09 +01:00
|
|
|
* except for SIGHUP, SIGTERM, SIGUSR1, SIGUSR2, and SIGQUIT.
|
2004-07-19 04:47:16 +02:00
|
|
|
*/
|
2019-12-17 19:14:28 +01:00
|
|
|
pqsignal(SIGHUP, SignalHandlerForConfigReload);
|
2004-07-19 04:47:16 +02:00
|
|
|
pqsignal(SIGINT, SIG_IGN);
|
2019-12-17 19:14:28 +01:00
|
|
|
pqsignal(SIGTERM, SignalHandlerForShutdownRequest);
|
Centralize setup of SIGQUIT handling for postmaster child processes.
We decided that the policy established in commit 7634bd4f6 for
the bgwriter, checkpointer, walwriter, and walreceiver processes,
namely that they should accept SIGQUIT at all times, really ought
to apply uniformly to all postmaster children. Therefore, get
rid of the duplicative and inconsistent per-process code for
establishing that signal handler and removing SIGQUIT from BlockSig.
Instead, make InitPostmasterChild do it.
The handler set up by InitPostmasterChild is SignalHandlerForCrashExit,
which just summarily does _exit(2). In interactive backends, we
almost immediately replace that with quickdie, since we would prefer
to try to tell the client that we're dying. However, this patch is
changing the behavior of autovacuum (both launcher and workers), as
well as walsenders. Those processes formerly also used quickdie,
but AFAICS that was just mindless copy-and-paste: they don't have
any interactive client that's likely to benefit from being told this.
The stats collector continues to be an outlier, in that it thinks
SIGQUIT means normal exit. That should probably be changed for
consistency, but there's another patch set where that's being
dealt with, so I didn't do so here.
Discussion: https://postgr.es/m/644875.1599933441@sss.pgh.pa.us
2020-09-16 22:04:36 +02:00
|
|
|
/* SIGQUIT handler was already set up by InitPostmasterChild */
|
2004-07-19 04:47:16 +02:00
|
|
|
pqsignal(SIGALRM, SIG_IGN);
|
|
|
|
pqsignal(SIGPIPE, SIG_IGN);
|
Make archiver process an auxiliary process.
This commit changes WAL archiver process so that it's treated as
an auxiliary process and can use shared memory. This is an infrastructure
patch required for upcoming shared-memory based stats collector patch
series. These patch series basically need any processes including archiver
that can report the statistics to access to shared memory. Since this patch
itself is useful to simplify the code and when users monitor the status of
archiver, it's committed separately in advance.
This commit simplifies the code for WAL archiving. For example, previously
backends need to signal to archiver via postmaster when they notify
archiver that there are some WAL files to archive. On the other hand,
this commit removes that signal to postmaster and enables backends to
notify archier directly using shared latch.
Also, as the side of this change, the information about archiver process
becomes viewable at pg_stat_activity view.
Author: Kyotaro Horiguchi
Reviewed-by: Andres Freund, Álvaro Herrera, Julien Rouhaud, Tomas Vondra, Arthur Zakirov, Fujii Masao
Discussion: https://postgr.es/m/20180629.173418.190173462.horiguchi.kyotaro@lab.ntt.co.jp
2021-03-15 05:13:14 +01:00
|
|
|
pqsignal(SIGUSR1, procsignal_sigusr1_handler);
|
2008-01-11 01:54:09 +01:00
|
|
|
pqsignal(SIGUSR2, pgarch_waken_stop);
|
Make archiver process an auxiliary process.
This commit changes WAL archiver process so that it's treated as
an auxiliary process and can use shared memory. This is an infrastructure
patch required for upcoming shared-memory based stats collector patch
series. These patch series basically need any processes including archiver
that can report the statistics to access to shared memory. Since this patch
itself is useful to simplify the code and when users monitor the status of
archiver, it's committed separately in advance.
This commit simplifies the code for WAL archiving. For example, previously
backends need to signal to archiver via postmaster when they notify
archiver that there are some WAL files to archive. On the other hand,
this commit removes that signal to postmaster and enables backends to
notify archier directly using shared latch.
Also, as the side of this change, the information about archiver process
becomes viewable at pg_stat_activity view.
Author: Kyotaro Horiguchi
Reviewed-by: Andres Freund, Álvaro Herrera, Julien Rouhaud, Tomas Vondra, Arthur Zakirov, Fujii Masao
Discussion: https://postgr.es/m/20180629.173418.190173462.horiguchi.kyotaro@lab.ntt.co.jp
2021-03-15 05:13:14 +01:00
|
|
|
|
Leave SIGTTIN/SIGTTOU signal handling alone in postmaster child processes.
For reasons lost in the mists of time, most postmaster child processes
reset SIGTTIN/SIGTTOU signal handling to SIG_DFL, with the major exception
that backend sessions do not. It seems like a pretty bad idea for any
postmaster children to do that: if stderr is connected to the terminal,
and the user has put the postmaster in background, any log output would
result in the child process freezing up. Hence, switch them all to
doing what backends do, ie, nothing. This allows them to inherit the
postmaster's SIG_IGN setting. On the other hand, manually-launched
processes such as standalone backends will have default processing,
which seems fine.
In passing, also remove useless resets of SIGCONT and SIGWINCH signal
processing. Perhaps the postmaster once changed those to something
besides SIG_DFL, but it doesn't now, so these are just wasted (and
confusing) syscalls.
Basically, this propagates the changes made in commit 8e2998d8a from
backends to other postmaster children. Probably the only reason these
calls now exist elsewhere is that I missed changing pgstat.c along with
postgres.c at the time.
Given the lack of field complaints that can be traced to this, I don't
presently feel a need to back-patch.
Discussion: https://postgr.es/m/5627.1542477392@sss.pgh.pa.us
2018-11-17 22:23:55 +01:00
|
|
|
/* Reset some signals that are accepted by postmaster but not here */
|
2004-07-19 04:47:16 +02:00
|
|
|
pqsignal(SIGCHLD, SIG_DFL);
|
Make archiver process an auxiliary process.
This commit changes WAL archiver process so that it's treated as
an auxiliary process and can use shared memory. This is an infrastructure
patch required for upcoming shared-memory based stats collector patch
series. These patch series basically need any processes including archiver
that can report the statistics to access to shared memory. Since this patch
itself is useful to simplify the code and when users monitor the status of
archiver, it's committed separately in advance.
This commit simplifies the code for WAL archiving. For example, previously
backends need to signal to archiver via postmaster when they notify
archiver that there are some WAL files to archive. On the other hand,
this commit removes that signal to postmaster and enables backends to
notify archier directly using shared latch.
Also, as the side of this change, the information about archiver process
becomes viewable at pg_stat_activity view.
Author: Kyotaro Horiguchi
Reviewed-by: Andres Freund, Álvaro Herrera, Julien Rouhaud, Tomas Vondra, Arthur Zakirov, Fujii Masao
Discussion: https://postgr.es/m/20180629.173418.190173462.horiguchi.kyotaro@lab.ntt.co.jp
2021-03-15 05:13:14 +01:00
|
|
|
|
|
|
|
/* Unblock signals (they were blocked when the postmaster forked us) */
|
2023-02-02 22:34:56 +01:00
|
|
|
sigprocmask(SIG_SETMASK, &UnBlockSig, NULL);
|
2004-08-29 07:07:03 +02:00
|
|
|
|
Make archiver process an auxiliary process.
This commit changes WAL archiver process so that it's treated as
an auxiliary process and can use shared memory. This is an infrastructure
patch required for upcoming shared-memory based stats collector patch
series. These patch series basically need any processes including archiver
that can report the statistics to access to shared memory. Since this patch
itself is useful to simplify the code and when users monitor the status of
archiver, it's committed separately in advance.
This commit simplifies the code for WAL archiving. For example, previously
backends need to signal to archiver via postmaster when they notify
archiver that there are some WAL files to archive. On the other hand,
this commit removes that signal to postmaster and enables backends to
notify archier directly using shared latch.
Also, as the side of this change, the information about archiver process
becomes viewable at pg_stat_activity view.
Author: Kyotaro Horiguchi
Reviewed-by: Andres Freund, Álvaro Herrera, Julien Rouhaud, Tomas Vondra, Arthur Zakirov, Fujii Masao
Discussion: https://postgr.es/m/20180629.173418.190173462.horiguchi.kyotaro@lab.ntt.co.jp
2021-03-15 05:13:14 +01:00
|
|
|
/* We shouldn't be launched unnecessarily. */
|
|
|
|
Assert(XLogArchivingActive());
|
|
|
|
|
|
|
|
/* Arrange to clean up at archiver exit */
|
|
|
|
on_shmem_exit(pgarch_die, 0);
|
|
|
|
|
|
|
|
/*
|
2024-03-03 18:38:22 +01:00
|
|
|
* Advertise our proc number so that backends can use our latch to wake us
|
|
|
|
* up while we're sleeping.
|
Make archiver process an auxiliary process.
This commit changes WAL archiver process so that it's treated as
an auxiliary process and can use shared memory. This is an infrastructure
patch required for upcoming shared-memory based stats collector patch
series. These patch series basically need any processes including archiver
that can report the statistics to access to shared memory. Since this patch
itself is useful to simplify the code and when users monitor the status of
archiver, it's committed separately in advance.
This commit simplifies the code for WAL archiving. For example, previously
backends need to signal to archiver via postmaster when they notify
archiver that there are some WAL files to archive. On the other hand,
this commit removes that signal to postmaster and enables backends to
notify archier directly using shared latch.
Also, as the side of this change, the information about archiver process
becomes viewable at pg_stat_activity view.
Author: Kyotaro Horiguchi
Reviewed-by: Andres Freund, Álvaro Herrera, Julien Rouhaud, Tomas Vondra, Arthur Zakirov, Fujii Masao
Discussion: https://postgr.es/m/20180629.173418.190173462.horiguchi.kyotaro@lab.ntt.co.jp
2021-03-15 05:13:14 +01:00
|
|
|
*/
|
2024-02-22 00:21:34 +01:00
|
|
|
PgArch->pgprocno = MyProcNumber;
|
2004-08-29 07:07:03 +02:00
|
|
|
|
2021-12-29 23:02:50 +01:00
|
|
|
/* Create workspace for pgarch_readyXlog() */
|
|
|
|
arch_files = palloc(sizeof(struct arch_files_state));
|
|
|
|
arch_files->arch_files_size = 0;
|
|
|
|
|
2021-11-11 21:02:53 +01:00
|
|
|
/* Initialize our max-heap for prioritizing files to archive. */
|
2021-12-29 23:02:50 +01:00
|
|
|
arch_files->arch_heap = binaryheap_allocate(NUM_FILES_PER_DIRECTORY_SCAN,
|
|
|
|
ready_file_comparator, NULL);
|
2021-11-11 21:02:53 +01:00
|
|
|
|
2022-02-03 19:57:27 +01:00
|
|
|
/* Load the archive_library. */
|
|
|
|
LoadArchiveLibrary();
|
|
|
|
|
Rework shutdown callback of archiver modules
As currently designed, with a callback registered in a ERROR_CLEANUP
block, the shutdown callback would get called twice when updating
archive_library on SIGHUP, which is something that we want to avoid to
ease the life of extension writers.
Anyway, an ERROR in the archiver process is treated as a FATAL, stopping
it immediately, hence there is no need for a ERROR_CLEANUP block.
Instead of that, the shutdown callback is not called upon
before_shmem_exit(), giving to the modules the opportunity to do any
cleanup actions before the server shuts down its subsystems.
While on it, this commit adds some testing coverage for the shutdown
callback. Neither shell_archive nor basic_archive have been using it,
and one is added to shell_archive, whose trigger is checked in a TAP
test through a shutdown sequence.
Author: Nathan Bossart, Bharath Rupireddy
Reviewed-by: Kyotaro Horiguchi, Michael Paquier
Discussion: https://postgr.es/m/20221015221328.GB1821022@nathanxps13
Backpatch-through: 15
2022-10-19 07:06:56 +02:00
|
|
|
pgarch_MainLoop();
|
2004-07-19 04:47:16 +02:00
|
|
|
|
Make archiver process an auxiliary process.
This commit changes WAL archiver process so that it's treated as
an auxiliary process and can use shared memory. This is an infrastructure
patch required for upcoming shared-memory based stats collector patch
series. These patch series basically need any processes including archiver
that can report the statistics to access to shared memory. Since this patch
itself is useful to simplify the code and when users monitor the status of
archiver, it's committed separately in advance.
This commit simplifies the code for WAL archiving. For example, previously
backends need to signal to archiver via postmaster when they notify
archiver that there are some WAL files to archive. On the other hand,
this commit removes that signal to postmaster and enables backends to
notify archier directly using shared latch.
Also, as the side of this change, the information about archiver process
becomes viewable at pg_stat_activity view.
Author: Kyotaro Horiguchi
Reviewed-by: Andres Freund, Álvaro Herrera, Julien Rouhaud, Tomas Vondra, Arthur Zakirov, Fujii Masao
Discussion: https://postgr.es/m/20180629.173418.190173462.horiguchi.kyotaro@lab.ntt.co.jp
2021-03-15 05:13:14 +01:00
|
|
|
proc_exit(0);
|
2004-07-19 04:47:16 +02:00
|
|
|
}
|
|
|
|
|
Make archiver process an auxiliary process.
This commit changes WAL archiver process so that it's treated as
an auxiliary process and can use shared memory. This is an infrastructure
patch required for upcoming shared-memory based stats collector patch
series. These patch series basically need any processes including archiver
that can report the statistics to access to shared memory. Since this patch
itself is useful to simplify the code and when users monitor the status of
archiver, it's committed separately in advance.
This commit simplifies the code for WAL archiving. For example, previously
backends need to signal to archiver via postmaster when they notify
archiver that there are some WAL files to archive. On the other hand,
this commit removes that signal to postmaster and enables backends to
notify archier directly using shared latch.
Also, as the side of this change, the information about archiver process
becomes viewable at pg_stat_activity view.
Author: Kyotaro Horiguchi
Reviewed-by: Andres Freund, Álvaro Herrera, Julien Rouhaud, Tomas Vondra, Arthur Zakirov, Fujii Masao
Discussion: https://postgr.es/m/20180629.173418.190173462.horiguchi.kyotaro@lab.ntt.co.jp
2021-03-15 05:13:14 +01:00
|
|
|
/*
|
|
|
|
* Wake up the archiver
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
PgArchWakeup(void)
|
2004-07-19 04:47:16 +02:00
|
|
|
{
|
Make archiver process an auxiliary process.
This commit changes WAL archiver process so that it's treated as
an auxiliary process and can use shared memory. This is an infrastructure
patch required for upcoming shared-memory based stats collector patch
series. These patch series basically need any processes including archiver
that can report the statistics to access to shared memory. Since this patch
itself is useful to simplify the code and when users monitor the status of
archiver, it's committed separately in advance.
This commit simplifies the code for WAL archiving. For example, previously
backends need to signal to archiver via postmaster when they notify
archiver that there are some WAL files to archive. On the other hand,
this commit removes that signal to postmaster and enables backends to
notify archier directly using shared latch.
Also, as the side of this change, the information about archiver process
becomes viewable at pg_stat_activity view.
Author: Kyotaro Horiguchi
Reviewed-by: Andres Freund, Álvaro Herrera, Julien Rouhaud, Tomas Vondra, Arthur Zakirov, Fujii Masao
Discussion: https://postgr.es/m/20180629.173418.190173462.horiguchi.kyotaro@lab.ntt.co.jp
2021-03-15 05:13:14 +01:00
|
|
|
int arch_pgprocno = PgArch->pgprocno;
|
2011-08-10 18:20:30 +02:00
|
|
|
|
Make archiver process an auxiliary process.
This commit changes WAL archiver process so that it's treated as
an auxiliary process and can use shared memory. This is an infrastructure
patch required for upcoming shared-memory based stats collector patch
series. These patch series basically need any processes including archiver
that can report the statistics to access to shared memory. Since this patch
itself is useful to simplify the code and when users monitor the status of
archiver, it's committed separately in advance.
This commit simplifies the code for WAL archiving. For example, previously
backends need to signal to archiver via postmaster when they notify
archiver that there are some WAL files to archive. On the other hand,
this commit removes that signal to postmaster and enables backends to
notify archier directly using shared latch.
Also, as the side of this change, the information about archiver process
becomes viewable at pg_stat_activity view.
Author: Kyotaro Horiguchi
Reviewed-by: Andres Freund, Álvaro Herrera, Julien Rouhaud, Tomas Vondra, Arthur Zakirov, Fujii Masao
Discussion: https://postgr.es/m/20180629.173418.190173462.horiguchi.kyotaro@lab.ntt.co.jp
2021-03-15 05:13:14 +01:00
|
|
|
/*
|
|
|
|
* We don't acquire ProcArrayLock here. It's actually fine because
|
|
|
|
* procLatch isn't ever freed, so we just can potentially set the wrong
|
|
|
|
* process' (or no process') latch. Even in that case the archiver will
|
|
|
|
* be relaunched shortly and will start archiving.
|
|
|
|
*/
|
2024-03-03 18:38:22 +01:00
|
|
|
if (arch_pgprocno != INVALID_PROC_NUMBER)
|
Make archiver process an auxiliary process.
This commit changes WAL archiver process so that it's treated as
an auxiliary process and can use shared memory. This is an infrastructure
patch required for upcoming shared-memory based stats collector patch
series. These patch series basically need any processes including archiver
that can report the statistics to access to shared memory. Since this patch
itself is useful to simplify the code and when users monitor the status of
archiver, it's committed separately in advance.
This commit simplifies the code for WAL archiving. For example, previously
backends need to signal to archiver via postmaster when they notify
archiver that there are some WAL files to archive. On the other hand,
this commit removes that signal to postmaster and enables backends to
notify archier directly using shared latch.
Also, as the side of this change, the information about archiver process
becomes viewable at pg_stat_activity view.
Author: Kyotaro Horiguchi
Reviewed-by: Andres Freund, Álvaro Herrera, Julien Rouhaud, Tomas Vondra, Arthur Zakirov, Fujii Masao
Discussion: https://postgr.es/m/20180629.173418.190173462.horiguchi.kyotaro@lab.ntt.co.jp
2021-03-15 05:13:14 +01:00
|
|
|
SetLatch(&ProcGlobal->allProcs[arch_pgprocno].procLatch);
|
2004-07-19 04:47:16 +02:00
|
|
|
}
|
|
|
|
|
Make archiver process an auxiliary process.
This commit changes WAL archiver process so that it's treated as
an auxiliary process and can use shared memory. This is an infrastructure
patch required for upcoming shared-memory based stats collector patch
series. These patch series basically need any processes including archiver
that can report the statistics to access to shared memory. Since this patch
itself is useful to simplify the code and when users monitor the status of
archiver, it's committed separately in advance.
This commit simplifies the code for WAL archiving. For example, previously
backends need to signal to archiver via postmaster when they notify
archiver that there are some WAL files to archive. On the other hand,
this commit removes that signal to postmaster and enables backends to
notify archier directly using shared latch.
Also, as the side of this change, the information about archiver process
becomes viewable at pg_stat_activity view.
Author: Kyotaro Horiguchi
Reviewed-by: Andres Freund, Álvaro Herrera, Julien Rouhaud, Tomas Vondra, Arthur Zakirov, Fujii Masao
Discussion: https://postgr.es/m/20180629.173418.190173462.horiguchi.kyotaro@lab.ntt.co.jp
2021-03-15 05:13:14 +01:00
|
|
|
|
2008-01-11 01:54:09 +01:00
|
|
|
/* SIGUSR2 signal handler for archiver process */
|
|
|
|
static void
|
|
|
|
pgarch_waken_stop(SIGNAL_ARGS)
|
|
|
|
{
|
|
|
|
/* set flag to do a final cycle and shut down afterwards */
|
|
|
|
ready_to_stop = true;
|
2015-01-14 18:45:22 +01:00
|
|
|
SetLatch(MyLatch);
|
2008-01-11 01:54:09 +01:00
|
|
|
}
|
|
|
|
|
2004-07-19 04:47:16 +02:00
|
|
|
/*
|
|
|
|
* pgarch_MainLoop
|
|
|
|
*
|
|
|
|
* Main loop for archiver
|
|
|
|
*/
|
|
|
|
static void
|
|
|
|
pgarch_MainLoop(void)
|
|
|
|
{
|
2008-01-11 01:54:09 +01:00
|
|
|
bool time_to_stop;
|
2004-07-19 04:47:16 +02:00
|
|
|
|
Introduce a pipe between postmaster and each backend, which can be used to
detect postmaster death. Postmaster keeps the write-end of the pipe open,
so when it dies, children get EOF in the read-end. That can conveniently
be waited for in select(), which allows eliminating some of the polling
loops that check for postmaster death. This patch doesn't yet change all
the loops to use the new mechanism, expect a follow-on patch to do that.
This changes the interface to WaitLatch, so that it takes as argument a
bitmask of events that it waits for. Possible events are latch set, timeout,
postmaster death, and socket becoming readable or writeable.
The pipe method behaves slightly differently from the kill() method
previously used in PostmasterIsAlive() in the case that postmaster has died,
but its parent has not yet read its exit code with waitpid(). The pipe
returns EOF as soon as the process dies, but kill() continues to return
true until waitpid() has been called (IOW while the process is a zombie).
Because of that, change PostmasterIsAlive() to use the pipe too, otherwise
WaitLatch() would return immediately with WL_POSTMASTER_DEATH, while
PostmasterIsAlive() would claim it's still alive. That could easily lead to
busy-waiting while postmaster is in zombie state.
Peter Geoghegan with further changes by me, reviewed by Fujii Masao and
Florian Pflug.
2011-07-08 17:27:49 +02:00
|
|
|
/*
|
|
|
|
* There shouldn't be anything for the archiver to do except to wait for a
|
2023-02-01 07:46:04 +01:00
|
|
|
* signal ... however, the archiver exists to protect our data, so it
|
|
|
|
* wakes up occasionally to allow itself to be proactive.
|
Introduce a pipe between postmaster and each backend, which can be used to
detect postmaster death. Postmaster keeps the write-end of the pipe open,
so when it dies, children get EOF in the read-end. That can conveniently
be waited for in select(), which allows eliminating some of the polling
loops that check for postmaster death. This patch doesn't yet change all
the loops to use the new mechanism, expect a follow-on patch to do that.
This changes the interface to WaitLatch, so that it takes as argument a
bitmask of events that it waits for. Possible events are latch set, timeout,
postmaster death, and socket becoming readable or writeable.
The pipe method behaves slightly differently from the kill() method
previously used in PostmasterIsAlive() in the case that postmaster has died,
but its parent has not yet read its exit code with waitpid(). The pipe
returns EOF as soon as the process dies, but kill() continues to return
true until waitpid() has been called (IOW while the process is a zombie).
Because of that, change PostmasterIsAlive() to use the pipe too, otherwise
WaitLatch() would return immediately with WL_POSTMASTER_DEATH, while
PostmasterIsAlive() would claim it's still alive. That could easily lead to
busy-waiting while postmaster is in zombie state.
Peter Geoghegan with further changes by me, reviewed by Fujii Masao and
Florian Pflug.
2011-07-08 17:27:49 +02:00
|
|
|
*/
|
2004-07-19 04:47:16 +02:00
|
|
|
do
|
|
|
|
{
|
2015-01-14 18:45:22 +01:00
|
|
|
ResetLatch(MyLatch);
|
Introduce a pipe between postmaster and each backend, which can be used to
detect postmaster death. Postmaster keeps the write-end of the pipe open,
so when it dies, children get EOF in the read-end. That can conveniently
be waited for in select(), which allows eliminating some of the polling
loops that check for postmaster death. This patch doesn't yet change all
the loops to use the new mechanism, expect a follow-on patch to do that.
This changes the interface to WaitLatch, so that it takes as argument a
bitmask of events that it waits for. Possible events are latch set, timeout,
postmaster death, and socket becoming readable or writeable.
The pipe method behaves slightly differently from the kill() method
previously used in PostmasterIsAlive() in the case that postmaster has died,
but its parent has not yet read its exit code with waitpid(). The pipe
returns EOF as soon as the process dies, but kill() continues to return
true until waitpid() has been called (IOW while the process is a zombie).
Because of that, change PostmasterIsAlive() to use the pipe too, otherwise
WaitLatch() would return immediately with WL_POSTMASTER_DEATH, while
PostmasterIsAlive() would claim it's still alive. That could easily lead to
busy-waiting while postmaster is in zombie state.
Peter Geoghegan with further changes by me, reviewed by Fujii Masao and
Florian Pflug.
2011-07-08 17:27:49 +02:00
|
|
|
|
2008-01-11 01:54:09 +01:00
|
|
|
/* When we get SIGUSR2, we do one more archive cycle, then exit */
|
|
|
|
time_to_stop = ready_to_stop;
|
|
|
|
|
2021-06-18 10:57:09 +02:00
|
|
|
/* Check for barrier events and config update */
|
|
|
|
HandlePgArchInterrupts();
|
2004-07-19 04:47:16 +02:00
|
|
|
|
2008-01-11 01:54:09 +01:00
|
|
|
/*
|
|
|
|
* If we've gotten SIGTERM, we normally just sit and do nothing until
|
|
|
|
* SIGUSR2 arrives. However, that means a random SIGTERM would
|
|
|
|
* disable archiving indefinitely, which doesn't seem like a good
|
|
|
|
* idea. If more than 60 seconds pass since SIGTERM, exit anyway, so
|
|
|
|
* that the postmaster can start a new archiver if needed.
|
|
|
|
*/
|
2019-12-17 19:14:28 +01:00
|
|
|
if (ShutdownRequestPending)
|
2008-01-11 01:54:09 +01:00
|
|
|
{
|
|
|
|
time_t curtime = time(NULL);
|
|
|
|
|
|
|
|
if (last_sigterm_time == 0)
|
|
|
|
last_sigterm_time = curtime;
|
|
|
|
else if ((unsigned int) (curtime - last_sigterm_time) >=
|
|
|
|
(unsigned int) 60)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2004-07-19 04:47:16 +02:00
|
|
|
/* Do what we're here for */
|
Make archiver process an auxiliary process.
This commit changes WAL archiver process so that it's treated as
an auxiliary process and can use shared memory. This is an infrastructure
patch required for upcoming shared-memory based stats collector patch
series. These patch series basically need any processes including archiver
that can report the statistics to access to shared memory. Since this patch
itself is useful to simplify the code and when users monitor the status of
archiver, it's committed separately in advance.
This commit simplifies the code for WAL archiving. For example, previously
backends need to signal to archiver via postmaster when they notify
archiver that there are some WAL files to archive. On the other hand,
this commit removes that signal to postmaster and enables backends to
notify archier directly using shared latch.
Also, as the side of this change, the information about archiver process
becomes viewable at pg_stat_activity view.
Author: Kyotaro Horiguchi
Reviewed-by: Andres Freund, Álvaro Herrera, Julien Rouhaud, Tomas Vondra, Arthur Zakirov, Fujii Masao
Discussion: https://postgr.es/m/20180629.173418.190173462.horiguchi.kyotaro@lab.ntt.co.jp
2021-03-15 05:13:14 +01:00
|
|
|
pgarch_ArchiverCopyLoop();
|
2004-07-19 04:47:16 +02:00
|
|
|
|
|
|
|
/*
|
Introduce a pipe between postmaster and each backend, which can be used to
detect postmaster death. Postmaster keeps the write-end of the pipe open,
so when it dies, children get EOF in the read-end. That can conveniently
be waited for in select(), which allows eliminating some of the polling
loops that check for postmaster death. This patch doesn't yet change all
the loops to use the new mechanism, expect a follow-on patch to do that.
This changes the interface to WaitLatch, so that it takes as argument a
bitmask of events that it waits for. Possible events are latch set, timeout,
postmaster death, and socket becoming readable or writeable.
The pipe method behaves slightly differently from the kill() method
previously used in PostmasterIsAlive() in the case that postmaster has died,
but its parent has not yet read its exit code with waitpid(). The pipe
returns EOF as soon as the process dies, but kill() continues to return
true until waitpid() has been called (IOW while the process is a zombie).
Because of that, change PostmasterIsAlive() to use the pipe too, otherwise
WaitLatch() would return immediately with WL_POSTMASTER_DEATH, while
PostmasterIsAlive() would claim it's still alive. That could easily lead to
busy-waiting while postmaster is in zombie state.
Peter Geoghegan with further changes by me, reviewed by Fujii Masao and
Florian Pflug.
2011-07-08 17:27:49 +02:00
|
|
|
* Sleep until a signal is received, or until a poll is forced by
|
2023-02-01 07:46:04 +01:00
|
|
|
* PGARCH_AUTOWAKE_INTERVAL, or until postmaster dies.
|
2004-07-19 04:47:16 +02:00
|
|
|
*/
|
Introduce a pipe between postmaster and each backend, which can be used to
detect postmaster death. Postmaster keeps the write-end of the pipe open,
so when it dies, children get EOF in the read-end. That can conveniently
be waited for in select(), which allows eliminating some of the polling
loops that check for postmaster death. This patch doesn't yet change all
the loops to use the new mechanism, expect a follow-on patch to do that.
This changes the interface to WaitLatch, so that it takes as argument a
bitmask of events that it waits for. Possible events are latch set, timeout,
postmaster death, and socket becoming readable or writeable.
The pipe method behaves slightly differently from the kill() method
previously used in PostmasterIsAlive() in the case that postmaster has died,
but its parent has not yet read its exit code with waitpid(). The pipe
returns EOF as soon as the process dies, but kill() continues to return
true until waitpid() has been called (IOW while the process is a zombie).
Because of that, change PostmasterIsAlive() to use the pipe too, otherwise
WaitLatch() would return immediately with WL_POSTMASTER_DEATH, while
PostmasterIsAlive() would claim it's still alive. That could easily lead to
busy-waiting while postmaster is in zombie state.
Peter Geoghegan with further changes by me, reviewed by Fujii Masao and
Florian Pflug.
2011-07-08 17:27:49 +02:00
|
|
|
if (!time_to_stop) /* Don't wait during last iteration */
|
2004-07-19 04:47:16 +02:00
|
|
|
{
|
2023-02-01 07:46:04 +01:00
|
|
|
int rc;
|
|
|
|
|
|
|
|
rc = WaitLatch(MyLatch,
|
|
|
|
WL_LATCH_SET | WL_TIMEOUT | WL_POSTMASTER_DEATH,
|
|
|
|
PGARCH_AUTOWAKE_INTERVAL * 1000L,
|
|
|
|
WAIT_EVENT_ARCHIVER_MAIN);
|
|
|
|
if (rc & WL_POSTMASTER_DEATH)
|
|
|
|
time_to_stop = true;
|
2004-07-19 04:47:16 +02:00
|
|
|
}
|
2008-01-11 01:54:09 +01:00
|
|
|
|
|
|
|
/*
|
|
|
|
* The archiver quits either when the postmaster dies (not expected)
|
|
|
|
* or after completing one more archiving cycle after receiving
|
|
|
|
* SIGUSR2.
|
|
|
|
*/
|
Add WL_EXIT_ON_PM_DEATH pseudo-event.
Users of the WaitEventSet and WaitLatch() APIs can now choose between
asking for WL_POSTMASTER_DEATH and then handling it explicitly, or asking
for WL_EXIT_ON_PM_DEATH to trigger immediate exit on postmaster death.
This reduces code duplication, since almost all callers want the latter.
Repair all code that was previously ignoring postmaster death completely,
or requesting the event but ignoring it, or requesting the event but then
doing an unconditional PostmasterIsAlive() call every time through its
event loop (which is an expensive syscall on platforms for which we don't
have USE_POSTMASTER_DEATH_SIGNAL support).
Assert that callers of WaitLatchXXX() under the postmaster remember to
ask for either WL_POSTMASTER_DEATH or WL_EXIT_ON_PM_DEATH, to prevent
future bugs.
The only process that doesn't handle postmaster death is syslogger. It
waits until all backends holding the write end of the syslog pipe
(including the postmaster) have closed it by exiting, to be sure to
capture any parting messages. By using the WaitEventSet API directly
it avoids the new assertion, and as a by-product it may be slightly
more efficient on platforms that have epoll().
Author: Thomas Munro
Reviewed-by: Kyotaro Horiguchi, Heikki Linnakangas, Tom Lane
Discussion: https://postgr.es/m/CAEepm%3D1TCviRykkUb69ppWLr_V697rzd1j3eZsRMmbXvETfqbQ%40mail.gmail.com,
https://postgr.es/m/CAEepm=2LqHzizbe7muD7-2yHUbTOoF7Q+qkSD5Q41kuhttRTwA@mail.gmail.com
2018-11-23 08:16:41 +01:00
|
|
|
} while (!time_to_stop);
|
2004-07-19 04:47:16 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* pgarch_ArchiverCopyLoop
|
|
|
|
*
|
|
|
|
* Archives all outstanding xlogs then returns
|
|
|
|
*/
|
|
|
|
static void
|
|
|
|
pgarch_ArchiverCopyLoop(void)
|
|
|
|
{
|
|
|
|
char xlog[MAX_XFN_CHARS + 1];
|
2004-08-29 07:07:03 +02:00
|
|
|
|
2021-11-11 21:02:53 +01:00
|
|
|
/* force directory scan in the first call to pgarch_readyXlog() */
|
2021-12-29 23:02:50 +01:00
|
|
|
arch_files->arch_files_size = 0;
|
2021-11-11 21:02:53 +01:00
|
|
|
|
2004-07-19 04:47:16 +02:00
|
|
|
/*
|
|
|
|
* loop through all xlogs with archive_status of .ready and archive
|
|
|
|
* them...mostly we expect this to be a single file, though it is possible
|
|
|
|
* some backend will add files onto the list of those that need archiving
|
|
|
|
* while we are still copying earlier archives
|
|
|
|
*/
|
2006-05-30 19:08:14 +02:00
|
|
|
while (pgarch_readyXlog(xlog))
|
2004-07-19 04:47:16 +02:00
|
|
|
{
|
|
|
|
int failures = 0;
|
Ensure cleanup of orphan archive status files
When a WAL segment is recycled, its ".ready" and ".done" status files
get also automatically removed, however this is not done in a durable
manner. Hence, in a subsequent crash, it could be possible that a
".ready" status file is still around with its corresponding segment
already gone.
If the backend reaches such a state, the archive command would most
likely complain about a segment non-existing and would keep retrying,
causing WAL segments to bloat pg_wal/, potentially making Postgres crash
hard when running out of space.
As status files are removed after each individual segment, using
durable_unlink() does not completely close the window either, as a crash
could happen between the moment the WAL segment is recycled and the
moment its status files are removed. This has also some performance
impact with the additional fsync() calls needed to make the removal in a
durable manner. Doing the cleanup at recovery is not cost-free either
as this makes crash recovery potentially take longer than necessary.
So, instead, as per an idea of Stephen Frost, make the archiver aware of
orphan status files and remove them on-the-fly if the corresponding
segment goes missing. Removal failures follow a model close to what
happens for WAL segments, where multiple attempts are done before giving
up temporarily, and where a successful orphan removal makes the archiver
move immediately to the next WAL segment thought as ready to be
archived.
Author: Michael Paquier
Reviewed-by: Nathan Bossart, Andres Freund, Stephen Frost, Kyotaro
Horiguchi
Discussion: https://postgr.es/m/20180928032827.GF1500@paquier.xyz
2018-12-10 07:00:59 +01:00
|
|
|
int failures_orphan = 0;
|
2004-07-19 04:47:16 +02:00
|
|
|
|
|
|
|
for (;;)
|
|
|
|
{
|
Ensure cleanup of orphan archive status files
When a WAL segment is recycled, its ".ready" and ".done" status files
get also automatically removed, however this is not done in a durable
manner. Hence, in a subsequent crash, it could be possible that a
".ready" status file is still around with its corresponding segment
already gone.
If the backend reaches such a state, the archive command would most
likely complain about a segment non-existing and would keep retrying,
causing WAL segments to bloat pg_wal/, potentially making Postgres crash
hard when running out of space.
As status files are removed after each individual segment, using
durable_unlink() does not completely close the window either, as a crash
could happen between the moment the WAL segment is recycled and the
moment its status files are removed. This has also some performance
impact with the additional fsync() calls needed to make the removal in a
durable manner. Doing the cleanup at recovery is not cost-free either
as this makes crash recovery potentially take longer than necessary.
So, instead, as per an idea of Stephen Frost, make the archiver aware of
orphan status files and remove them on-the-fly if the corresponding
segment goes missing. Removal failures follow a model close to what
happens for WAL segments, where multiple attempts are done before giving
up temporarily, and where a successful orphan removal makes the archiver
move immediately to the next WAL segment thought as ready to be
archived.
Author: Michael Paquier
Reviewed-by: Nathan Bossart, Andres Freund, Stephen Frost, Kyotaro
Horiguchi
Discussion: https://postgr.es/m/20180928032827.GF1500@paquier.xyz
2018-12-10 07:00:59 +01:00
|
|
|
struct stat stat_buf;
|
|
|
|
char pathname[MAXPGPATH];
|
|
|
|
|
2008-01-11 01:54:09 +01:00
|
|
|
/*
|
|
|
|
* Do not initiate any more archive commands after receiving
|
|
|
|
* SIGTERM, nor after the postmaster has died unexpectedly. The
|
|
|
|
* first condition is to try to keep from having init SIGKILL the
|
|
|
|
* command, and the second is to avoid conflicts with another
|
|
|
|
* archiver spawned by a newer postmaster.
|
|
|
|
*/
|
2019-12-17 19:14:28 +01:00
|
|
|
if (ShutdownRequestPending || !PostmasterIsAlive())
|
2006-05-30 19:08:14 +02:00
|
|
|
return;
|
|
|
|
|
2010-05-11 18:42:28 +02:00
|
|
|
/*
|
2021-06-18 10:57:09 +02:00
|
|
|
* Check for barrier events and config update. This is so that
|
|
|
|
* we'll adopt a new setting for archive_command as soon as
|
|
|
|
* possible, even if there is a backlog of files to be archived.
|
2010-05-11 18:42:28 +02:00
|
|
|
*/
|
2021-06-18 10:57:09 +02:00
|
|
|
HandlePgArchInterrupts();
|
2010-05-11 18:42:28 +02:00
|
|
|
|
2024-03-04 22:41:42 +01:00
|
|
|
/* Reset variables that might be set by the callback */
|
|
|
|
arch_module_check_errdetail_string = NULL;
|
|
|
|
|
2022-02-03 19:57:27 +01:00
|
|
|
/* can't do anything if not configured ... */
|
Redesign archive modules
A new callback named startup_cb, called shortly after a module is
loaded, is added. This makes possible the initialization of any
additional state data required by a module. This initial state data can
be saved in a ArchiveModuleState, that is now passed down to all the
callbacks that can be defined in a module. With this design, it is
possible to have a per-module state, aimed at opening the door to the
support of more than one archive module.
The initialization of the callbacks is changed so as
_PG_archive_module_init() does not anymore give in input a
ArchiveModuleCallbacks that a module has to fill in with callback
definitions. Instead, a module now needs to return a const
ArchiveModuleCallbacks.
All the structure and callback definitions of archive modules are moved
into their own header, named archive_module.h, from pgarch.h.
Command-based archiving follows the same line, with a new set of files
named shell_archive.{c,h}.
There are a few more items that are under discussion to improve the
design of archive modules, like the fact that basic_archive calls
sigsetjmp() by itself to define its own error handling flow. These will
be adjusted later, the changes done here cover already a good portion
of what has been discussed.
Any modules created for v15 will need to be adjusted to this new
design.
Author: Nathan Bossart
Reviewed-by: Andres Freund
Discussion: https://postgr.es/m/20230130194810.6fztfgbn32e7qarj@awork3.anarazel.de
2023-02-17 06:26:42 +01:00
|
|
|
if (ArchiveCallbacks->check_configured_cb != NULL &&
|
|
|
|
!ArchiveCallbacks->check_configured_cb(archive_module_state))
|
2010-05-11 18:42:28 +02:00
|
|
|
{
|
|
|
|
ereport(WARNING,
|
2024-03-04 22:41:42 +01:00
|
|
|
(errmsg("archive_mode enabled, yet archiving is not configured"),
|
|
|
|
arch_module_check_errdetail_string ?
|
|
|
|
errdetail_internal("%s", arch_module_check_errdetail_string) : 0));
|
2010-05-11 18:42:28 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
Ensure cleanup of orphan archive status files
When a WAL segment is recycled, its ".ready" and ".done" status files
get also automatically removed, however this is not done in a durable
manner. Hence, in a subsequent crash, it could be possible that a
".ready" status file is still around with its corresponding segment
already gone.
If the backend reaches such a state, the archive command would most
likely complain about a segment non-existing and would keep retrying,
causing WAL segments to bloat pg_wal/, potentially making Postgres crash
hard when running out of space.
As status files are removed after each individual segment, using
durable_unlink() does not completely close the window either, as a crash
could happen between the moment the WAL segment is recycled and the
moment its status files are removed. This has also some performance
impact with the additional fsync() calls needed to make the removal in a
durable manner. Doing the cleanup at recovery is not cost-free either
as this makes crash recovery potentially take longer than necessary.
So, instead, as per an idea of Stephen Frost, make the archiver aware of
orphan status files and remove them on-the-fly if the corresponding
segment goes missing. Removal failures follow a model close to what
happens for WAL segments, where multiple attempts are done before giving
up temporarily, and where a successful orphan removal makes the archiver
move immediately to the next WAL segment thought as ready to be
archived.
Author: Michael Paquier
Reviewed-by: Nathan Bossart, Andres Freund, Stephen Frost, Kyotaro
Horiguchi
Discussion: https://postgr.es/m/20180928032827.GF1500@paquier.xyz
2018-12-10 07:00:59 +01:00
|
|
|
/*
|
|
|
|
* Since archive status files are not removed in a durable manner,
|
|
|
|
* a system crash could leave behind .ready files for WAL segments
|
|
|
|
* that have already been recycled or removed. In this case,
|
|
|
|
* simply remove the orphan status file and move on. unlink() is
|
|
|
|
* used here as even on subsequent crashes the same orphan files
|
|
|
|
* would get removed, so there is no need to worry about
|
|
|
|
* durability.
|
|
|
|
*/
|
|
|
|
snprintf(pathname, MAXPGPATH, XLOGDIR "/%s", xlog);
|
|
|
|
if (stat(pathname, &stat_buf) != 0 && errno == ENOENT)
|
|
|
|
{
|
|
|
|
char xlogready[MAXPGPATH];
|
|
|
|
|
|
|
|
StatusFilePath(xlogready, xlog, ".ready");
|
|
|
|
if (unlink(xlogready) == 0)
|
|
|
|
{
|
|
|
|
ereport(WARNING,
|
|
|
|
(errmsg("removed orphan archive status file \"%s\"",
|
|
|
|
xlogready)));
|
|
|
|
|
|
|
|
/* leave loop and move to the next status file */
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (++failures_orphan >= NUM_ORPHAN_CLEANUP_RETRIES)
|
|
|
|
{
|
|
|
|
ereport(WARNING,
|
|
|
|
(errmsg("removal of orphan archive status file \"%s\" failed too many times, will try again later",
|
|
|
|
xlogready)));
|
|
|
|
|
|
|
|
/* give up cleanup of orphan status files */
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* wait a bit before retrying */
|
|
|
|
pg_usleep(1000000L);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2004-07-19 04:47:16 +02:00
|
|
|
if (pgarch_archiveXlog(xlog))
|
|
|
|
{
|
|
|
|
/* successful */
|
|
|
|
pgarch_archiveDone(xlog);
|
2014-01-28 18:58:22 +01:00
|
|
|
|
|
|
|
/*
|
2022-04-06 22:56:06 +02:00
|
|
|
* Tell the cumulative stats system about the WAL file that we
|
|
|
|
* successfully archived
|
2014-01-28 18:58:22 +01:00
|
|
|
*/
|
2022-04-06 23:08:57 +02:00
|
|
|
pgstat_report_archiver(xlog, false);
|
2014-01-28 18:58:22 +01:00
|
|
|
|
2004-07-19 04:47:16 +02:00
|
|
|
break; /* out of inner retry loop */
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2014-01-28 18:58:22 +01:00
|
|
|
/*
|
2022-04-06 22:56:06 +02:00
|
|
|
* Tell the cumulative stats system about the WAL file that we
|
|
|
|
* failed to archive
|
2014-01-28 18:58:22 +01:00
|
|
|
*/
|
2022-04-06 23:08:57 +02:00
|
|
|
pgstat_report_archiver(xlog, true);
|
2014-01-28 18:58:22 +01:00
|
|
|
|
2004-07-19 04:47:16 +02:00
|
|
|
if (++failures >= NUM_ARCHIVE_RETRIES)
|
|
|
|
{
|
|
|
|
ereport(WARNING,
|
2017-05-12 17:49:56 +02:00
|
|
|
(errmsg("archiving write-ahead log file \"%s\" failed too many times, will try again later",
|
2004-07-19 04:47:16 +02:00
|
|
|
xlog)));
|
|
|
|
return; /* give up archiving for now */
|
|
|
|
}
|
2004-11-18 18:13:38 +01:00
|
|
|
pg_usleep(1000000L); /* wait a bit before retrying */
|
2004-07-19 04:47:16 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* pgarch_archiveXlog
|
|
|
|
*
|
2022-02-03 19:57:27 +01:00
|
|
|
* Invokes archive_file_cb to copy one archive file to wherever it should go
|
2004-07-19 04:47:16 +02:00
|
|
|
*
|
|
|
|
* Returns true if successful
|
|
|
|
*/
|
|
|
|
static bool
|
|
|
|
pgarch_archiveXlog(char *xlog)
|
|
|
|
{
|
|
|
|
char pathname[MAXPGPATH];
|
2007-12-18 01:49:34 +01:00
|
|
|
char activitymsg[MAXFNAMELEN + 16];
|
2022-01-28 19:29:32 +01:00
|
|
|
bool ret;
|
2004-07-19 04:47:16 +02:00
|
|
|
|
2005-07-04 06:51:52 +02:00
|
|
|
snprintf(pathname, MAXPGPATH, XLOGDIR "/%s", xlog);
|
2004-07-19 04:47:16 +02:00
|
|
|
|
2007-12-18 01:49:34 +01:00
|
|
|
/* Report archive activity in PS display */
|
|
|
|
snprintf(activitymsg, sizeof(activitymsg), "archiving %s", xlog);
|
2020-03-11 16:36:40 +01:00
|
|
|
set_ps_display(activitymsg);
|
2007-12-18 01:49:34 +01:00
|
|
|
|
Redesign archive modules
A new callback named startup_cb, called shortly after a module is
loaded, is added. This makes possible the initialization of any
additional state data required by a module. This initial state data can
be saved in a ArchiveModuleState, that is now passed down to all the
callbacks that can be defined in a module. With this design, it is
possible to have a per-module state, aimed at opening the door to the
support of more than one archive module.
The initialization of the callbacks is changed so as
_PG_archive_module_init() does not anymore give in input a
ArchiveModuleCallbacks that a module has to fill in with callback
definitions. Instead, a module now needs to return a const
ArchiveModuleCallbacks.
All the structure and callback definitions of archive modules are moved
into their own header, named archive_module.h, from pgarch.h.
Command-based archiving follows the same line, with a new set of files
named shell_archive.{c,h}.
There are a few more items that are under discussion to improve the
design of archive modules, like the fact that basic_archive calls
sigsetjmp() by itself to define its own error handling flow. These will
be adjusted later, the changes done here cover already a good portion
of what has been discussed.
Any modules created for v15 will need to be adjusted to this new
design.
Author: Nathan Bossart
Reviewed-by: Andres Freund
Discussion: https://postgr.es/m/20230130194810.6fztfgbn32e7qarj@awork3.anarazel.de
2023-02-17 06:26:42 +01:00
|
|
|
ret = ArchiveCallbacks->archive_file_cb(archive_module_state, xlog, pathname);
|
2022-01-28 19:29:32 +01:00
|
|
|
if (ret)
|
|
|
|
snprintf(activitymsg, sizeof(activitymsg), "last was %s", xlog);
|
|
|
|
else
|
2007-12-18 01:49:34 +01:00
|
|
|
snprintf(activitymsg, sizeof(activitymsg), "failed on %s", xlog);
|
2020-03-11 16:36:40 +01:00
|
|
|
set_ps_display(activitymsg);
|
2007-12-18 01:49:34 +01:00
|
|
|
|
2022-01-28 19:29:32 +01:00
|
|
|
return ret;
|
2004-07-19 04:47:16 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* pgarch_readyXlog
|
|
|
|
*
|
|
|
|
* Return name of the oldest xlog file that has not yet been archived.
|
|
|
|
* No notification is set that file archiving is now in progress, so
|
|
|
|
* this would need to be extended if multiple concurrent archival
|
|
|
|
* tasks were created. If a failure occurs, we will completely
|
|
|
|
* re-copy the file at the next available opportunity.
|
|
|
|
*
|
|
|
|
* It is important that we return the oldest, so that we archive xlogs
|
|
|
|
* in order that they were written, for two reasons:
|
|
|
|
* 1) to maintain the sequential chain of xlogs required for recovery
|
|
|
|
* 2) because the oldest ones will sooner become candidates for
|
|
|
|
* recycling at time of checkpoint
|
2004-07-22 00:31:26 +02:00
|
|
|
*
|
2018-12-24 12:24:16 +01:00
|
|
|
* NOTE: the "oldest" comparison will consider any .history file to be older
|
|
|
|
* than any other file except another .history file. Segments on a timeline
|
|
|
|
* with a smaller ID will be older than all segments on a timeline with a
|
|
|
|
* larger ID; the net result being that past timelines are given higher
|
|
|
|
* priority for archiving. This seems okay, or at least not obviously worth
|
|
|
|
* changing.
|
2004-07-19 04:47:16 +02:00
|
|
|
*/
|
|
|
|
static bool
|
|
|
|
pgarch_readyXlog(char *xlog)
|
|
|
|
{
|
2004-07-22 00:31:26 +02:00
|
|
|
char XLogArchiveStatusDir[MAXPGPATH];
|
2004-07-19 04:47:16 +02:00
|
|
|
DIR *rldir;
|
|
|
|
struct dirent *rlde;
|
|
|
|
|
2021-11-11 21:02:53 +01:00
|
|
|
/*
|
|
|
|
* If a directory scan was requested, clear the stored file names and
|
|
|
|
* proceed.
|
|
|
|
*/
|
2024-02-29 17:17:55 +01:00
|
|
|
if (pg_atomic_exchange_u32(&PgArch->force_dir_scan, 0) == 1)
|
2021-12-29 23:02:50 +01:00
|
|
|
arch_files->arch_files_size = 0;
|
2021-11-11 21:02:53 +01:00
|
|
|
|
|
|
|
/*
|
|
|
|
* If we still have stored file names from the previous directory scan,
|
|
|
|
* try to return one of those. We check to make sure the status file is
|
|
|
|
* still present, as the archive_command for a previous file may have
|
|
|
|
* already marked it done.
|
|
|
|
*/
|
2021-12-29 23:02:50 +01:00
|
|
|
while (arch_files->arch_files_size > 0)
|
2021-11-11 21:02:53 +01:00
|
|
|
{
|
|
|
|
struct stat st;
|
|
|
|
char status_file[MAXPGPATH];
|
|
|
|
char *arch_file;
|
|
|
|
|
2021-12-29 23:02:50 +01:00
|
|
|
arch_files->arch_files_size--;
|
|
|
|
arch_file = arch_files->arch_files[arch_files->arch_files_size];
|
2021-11-11 21:02:53 +01:00
|
|
|
StatusFilePath(status_file, arch_file, ".ready");
|
|
|
|
|
|
|
|
if (stat(status_file, &st) == 0)
|
|
|
|
{
|
|
|
|
strcpy(xlog, arch_file);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
else if (errno != ENOENT)
|
|
|
|
ereport(ERROR,
|
|
|
|
(errcode_for_file_access(),
|
|
|
|
errmsg("could not stat file \"%s\": %m", status_file)));
|
|
|
|
}
|
|
|
|
|
2021-12-29 23:02:50 +01:00
|
|
|
/* arch_heap is probably empty, but let's make sure */
|
|
|
|
binaryheap_reset(arch_files->arch_heap);
|
|
|
|
|
2021-11-11 21:02:53 +01:00
|
|
|
/*
|
|
|
|
* Open the archive status directory and read through the list of files
|
|
|
|
* with the .ready suffix, looking for the earliest files.
|
|
|
|
*/
|
2005-07-04 06:51:52 +02:00
|
|
|
snprintf(XLogArchiveStatusDir, MAXPGPATH, XLOGDIR "/archive_status");
|
2004-07-19 04:47:16 +02:00
|
|
|
rldir = AllocateDir(XLogArchiveStatusDir);
|
|
|
|
|
2005-06-19 23:34:03 +02:00
|
|
|
while ((rlde = ReadDir(rldir, XLogArchiveStatusDir)) != NULL)
|
2004-07-19 04:47:16 +02:00
|
|
|
{
|
|
|
|
int basenamelen = (int) strlen(rlde->d_name) - 6;
|
2018-12-24 12:24:16 +01:00
|
|
|
char basename[MAX_XFN_CHARS + 1];
|
2021-11-11 21:02:53 +01:00
|
|
|
char *arch_file;
|
2004-07-19 04:47:16 +02:00
|
|
|
|
2018-12-24 12:24:16 +01:00
|
|
|
/* Ignore entries with unexpected number of characters */
|
|
|
|
if (basenamelen < MIN_XFN_CHARS ||
|
|
|
|
basenamelen > MAX_XFN_CHARS)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
/* Ignore entries with unexpected characters */
|
|
|
|
if (strspn(rlde->d_name, VALID_XFN_CHARS) < basenamelen)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
/* Ignore anything not suffixed with .ready */
|
|
|
|
if (strcmp(rlde->d_name + basenamelen, ".ready") != 0)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
/* Truncate off the .ready */
|
|
|
|
memcpy(basename, rlde->d_name, basenamelen);
|
|
|
|
basename[basenamelen] = '\0';
|
|
|
|
|
|
|
|
/*
|
2021-11-11 21:02:53 +01:00
|
|
|
* Store the file in our max-heap if it has a high enough priority.
|
2018-12-24 12:24:16 +01:00
|
|
|
*/
|
2021-12-29 23:02:50 +01:00
|
|
|
if (arch_files->arch_heap->bh_size < NUM_FILES_PER_DIRECTORY_SCAN)
|
2004-07-19 04:47:16 +02:00
|
|
|
{
|
2021-11-11 21:02:53 +01:00
|
|
|
/* If the heap isn't full yet, quickly add it. */
|
2021-12-29 23:02:50 +01:00
|
|
|
arch_file = arch_files->arch_filenames[arch_files->arch_heap->bh_size];
|
2021-11-11 21:02:53 +01:00
|
|
|
strcpy(arch_file, basename);
|
2021-12-29 23:02:50 +01:00
|
|
|
binaryheap_add_unordered(arch_files->arch_heap, CStringGetDatum(arch_file));
|
2021-11-11 21:02:53 +01:00
|
|
|
|
|
|
|
/* If we just filled the heap, make it a valid one. */
|
2021-12-29 23:02:50 +01:00
|
|
|
if (arch_files->arch_heap->bh_size == NUM_FILES_PER_DIRECTORY_SCAN)
|
|
|
|
binaryheap_build(arch_files->arch_heap);
|
2018-12-24 12:24:16 +01:00
|
|
|
}
|
2021-12-29 23:02:50 +01:00
|
|
|
else if (ready_file_comparator(binaryheap_first(arch_files->arch_heap),
|
2021-11-11 21:02:53 +01:00
|
|
|
CStringGetDatum(basename), NULL) > 0)
|
2018-12-24 12:24:16 +01:00
|
|
|
{
|
2021-11-11 21:02:53 +01:00
|
|
|
/*
|
|
|
|
* Remove the lowest priority file and add the current one to the
|
|
|
|
* heap.
|
|
|
|
*/
|
2021-12-29 23:02:50 +01:00
|
|
|
arch_file = DatumGetCString(binaryheap_remove_first(arch_files->arch_heap));
|
2021-11-11 21:02:53 +01:00
|
|
|
strcpy(arch_file, basename);
|
2021-12-29 23:02:50 +01:00
|
|
|
binaryheap_add(arch_files->arch_heap, CStringGetDatum(arch_file));
|
2004-07-19 04:47:16 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
FreeDir(rldir);
|
|
|
|
|
2021-11-11 21:02:53 +01:00
|
|
|
/* If no files were found, simply return. */
|
2021-12-29 23:02:50 +01:00
|
|
|
if (arch_files->arch_heap->bh_size == 0)
|
2021-11-11 21:02:53 +01:00
|
|
|
return false;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* If we didn't fill the heap, we didn't make it a valid one. Do that
|
|
|
|
* now.
|
|
|
|
*/
|
2021-12-29 23:02:50 +01:00
|
|
|
if (arch_files->arch_heap->bh_size < NUM_FILES_PER_DIRECTORY_SCAN)
|
|
|
|
binaryheap_build(arch_files->arch_heap);
|
2021-11-11 21:02:53 +01:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Fill arch_files array with the files to archive in ascending order of
|
|
|
|
* priority.
|
|
|
|
*/
|
2021-12-29 23:02:50 +01:00
|
|
|
arch_files->arch_files_size = arch_files->arch_heap->bh_size;
|
|
|
|
for (int i = 0; i < arch_files->arch_files_size; i++)
|
|
|
|
arch_files->arch_files[i] = DatumGetCString(binaryheap_remove_first(arch_files->arch_heap));
|
2021-11-11 21:02:53 +01:00
|
|
|
|
|
|
|
/* Return the highest priority file. */
|
2021-12-29 23:02:50 +01:00
|
|
|
arch_files->arch_files_size--;
|
|
|
|
strcpy(xlog, arch_files->arch_files[arch_files->arch_files_size]);
|
2021-11-11 21:02:53 +01:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* ready_file_comparator
|
|
|
|
*
|
|
|
|
* Compares the archival priority of the given files to archive. If "a"
|
|
|
|
* has a higher priority than "b", a negative value will be returned. If
|
|
|
|
* "b" has a higher priority than "a", a positive value will be returned.
|
|
|
|
* If "a" and "b" have equivalent values, 0 will be returned.
|
|
|
|
*/
|
|
|
|
static int
|
|
|
|
ready_file_comparator(Datum a, Datum b, void *arg)
|
|
|
|
{
|
|
|
|
char *a_str = DatumGetCString(a);
|
|
|
|
char *b_str = DatumGetCString(b);
|
|
|
|
bool a_history = IsTLHistoryFileName(a_str);
|
|
|
|
bool b_history = IsTLHistoryFileName(b_str);
|
|
|
|
|
|
|
|
/* Timeline history files always have the highest priority. */
|
|
|
|
if (a_history != b_history)
|
|
|
|
return a_history ? -1 : 1;
|
|
|
|
|
|
|
|
/* Priority is given to older files. */
|
|
|
|
return strcmp(a_str, b_str);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* PgArchForceDirScan
|
|
|
|
*
|
|
|
|
* When called, the next call to pgarch_readyXlog() will perform a
|
|
|
|
* directory scan. This is useful for ensuring that important files such
|
|
|
|
* as timeline history files are archived as quickly as possible.
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
PgArchForceDirScan(void)
|
|
|
|
{
|
2024-02-29 17:17:55 +01:00
|
|
|
pg_atomic_write_membarrier_u32(&PgArch->force_dir_scan, 1);
|
2004-07-19 04:47:16 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* pgarch_archiveDone
|
|
|
|
*
|
|
|
|
* Emit notification that an xlog file has been successfully archived.
|
|
|
|
* We do this by renaming the status file from NNN.ready to NNN.done.
|
|
|
|
* Eventually, a checkpoint process will notice this and delete both the
|
|
|
|
* NNN.done file and the xlog file itself.
|
|
|
|
*/
|
|
|
|
static void
|
|
|
|
pgarch_archiveDone(char *xlog)
|
|
|
|
{
|
|
|
|
char rlogready[MAXPGPATH];
|
|
|
|
char rlogdone[MAXPGPATH];
|
|
|
|
|
2004-07-22 00:31:26 +02:00
|
|
|
StatusFilePath(rlogready, xlog, ".ready");
|
|
|
|
StatusFilePath(rlogdone, xlog, ".done");
|
2022-07-26 09:00:18 +02:00
|
|
|
|
|
|
|
/*
|
|
|
|
* To avoid extra overhead, we don't durably rename the .ready file to
|
|
|
|
* .done. Archive commands and libraries must gracefully handle attempts
|
|
|
|
* to re-archive files (e.g., if the server crashes just before this
|
|
|
|
* function is called), so it should be okay if the .ready file reappears
|
|
|
|
* after a crash.
|
|
|
|
*/
|
|
|
|
if (rename(rlogready, rlogdone) < 0)
|
|
|
|
ereport(WARNING,
|
|
|
|
(errcode_for_file_access(),
|
|
|
|
errmsg("could not rename file \"%s\" to \"%s\": %m",
|
|
|
|
rlogready, rlogdone)));
|
2004-07-19 04:47:16 +02:00
|
|
|
}
|
Make archiver process an auxiliary process.
This commit changes WAL archiver process so that it's treated as
an auxiliary process and can use shared memory. This is an infrastructure
patch required for upcoming shared-memory based stats collector patch
series. These patch series basically need any processes including archiver
that can report the statistics to access to shared memory. Since this patch
itself is useful to simplify the code and when users monitor the status of
archiver, it's committed separately in advance.
This commit simplifies the code for WAL archiving. For example, previously
backends need to signal to archiver via postmaster when they notify
archiver that there are some WAL files to archive. On the other hand,
this commit removes that signal to postmaster and enables backends to
notify archier directly using shared latch.
Also, as the side of this change, the information about archiver process
becomes viewable at pg_stat_activity view.
Author: Kyotaro Horiguchi
Reviewed-by: Andres Freund, Álvaro Herrera, Julien Rouhaud, Tomas Vondra, Arthur Zakirov, Fujii Masao
Discussion: https://postgr.es/m/20180629.173418.190173462.horiguchi.kyotaro@lab.ntt.co.jp
2021-03-15 05:13:14 +01:00
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* pgarch_die
|
|
|
|
*
|
|
|
|
* Exit-time cleanup handler
|
|
|
|
*/
|
|
|
|
static void
|
|
|
|
pgarch_die(int code, Datum arg)
|
|
|
|
{
|
2024-03-03 18:38:22 +01:00
|
|
|
PgArch->pgprocno = INVALID_PROC_NUMBER;
|
Make archiver process an auxiliary process.
This commit changes WAL archiver process so that it's treated as
an auxiliary process and can use shared memory. This is an infrastructure
patch required for upcoming shared-memory based stats collector patch
series. These patch series basically need any processes including archiver
that can report the statistics to access to shared memory. Since this patch
itself is useful to simplify the code and when users monitor the status of
archiver, it's committed separately in advance.
This commit simplifies the code for WAL archiving. For example, previously
backends need to signal to archiver via postmaster when they notify
archiver that there are some WAL files to archive. On the other hand,
this commit removes that signal to postmaster and enables backends to
notify archier directly using shared latch.
Also, as the side of this change, the information about archiver process
becomes viewable at pg_stat_activity view.
Author: Kyotaro Horiguchi
Reviewed-by: Andres Freund, Álvaro Herrera, Julien Rouhaud, Tomas Vondra, Arthur Zakirov, Fujii Masao
Discussion: https://postgr.es/m/20180629.173418.190173462.horiguchi.kyotaro@lab.ntt.co.jp
2021-03-15 05:13:14 +01:00
|
|
|
}
|
2021-06-18 10:57:09 +02:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Interrupt handler for WAL archiver process.
|
|
|
|
*
|
|
|
|
* This is called in the loops pgarch_MainLoop and pgarch_ArchiverCopyLoop.
|
2022-01-11 15:19:59 +01:00
|
|
|
* It checks for barrier events, config update and request for logging of
|
|
|
|
* memory contexts, but not shutdown request because how to handle
|
|
|
|
* shutdown request is different between those loops.
|
2021-06-18 10:57:09 +02:00
|
|
|
*/
|
|
|
|
static void
|
|
|
|
HandlePgArchInterrupts(void)
|
|
|
|
{
|
|
|
|
if (ProcSignalBarrierPending)
|
|
|
|
ProcessProcSignalBarrier();
|
|
|
|
|
2022-02-03 19:57:27 +01:00
|
|
|
/* Perform logging of memory contexts of this process */
|
|
|
|
if (LogMemoryContextPending)
|
|
|
|
ProcessLogMemoryContextInterrupt();
|
|
|
|
|
2021-06-18 10:57:09 +02:00
|
|
|
if (ConfigReloadPending)
|
|
|
|
{
|
2022-02-03 19:57:27 +01:00
|
|
|
char *archiveLib = pstrdup(XLogArchiveLibrary);
|
|
|
|
bool archiveLibChanged;
|
|
|
|
|
2021-06-18 10:57:09 +02:00
|
|
|
ConfigReloadPending = false;
|
|
|
|
ProcessConfigFile(PGC_SIGHUP);
|
2022-02-03 19:57:27 +01:00
|
|
|
|
2022-11-15 10:03:12 +01:00
|
|
|
if (XLogArchiveLibrary[0] != '\0' && XLogArchiveCommand[0] != '\0')
|
|
|
|
ereport(ERROR,
|
|
|
|
(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
|
|
|
|
errmsg("both archive_command and archive_library set"),
|
|
|
|
errdetail("Only one of archive_command, archive_library may be set.")));
|
|
|
|
|
2022-02-03 19:57:27 +01:00
|
|
|
archiveLibChanged = strcmp(XLogArchiveLibrary, archiveLib) != 0;
|
|
|
|
pfree(archiveLib);
|
|
|
|
|
|
|
|
if (archiveLibChanged)
|
|
|
|
{
|
|
|
|
/*
|
|
|
|
* Ideally, we would simply unload the previous archive module and
|
|
|
|
* load the new one, but there is presently no mechanism for
|
|
|
|
* unloading a library (see the comment above
|
2022-05-11 21:27:33 +02:00
|
|
|
* internal_load_library()). To deal with this, we simply restart
|
2022-02-03 19:57:27 +01:00
|
|
|
* the archiver. The new archive module will be loaded when the
|
Rework shutdown callback of archiver modules
As currently designed, with a callback registered in a ERROR_CLEANUP
block, the shutdown callback would get called twice when updating
archive_library on SIGHUP, which is something that we want to avoid to
ease the life of extension writers.
Anyway, an ERROR in the archiver process is treated as a FATAL, stopping
it immediately, hence there is no need for a ERROR_CLEANUP block.
Instead of that, the shutdown callback is not called upon
before_shmem_exit(), giving to the modules the opportunity to do any
cleanup actions before the server shuts down its subsystems.
While on it, this commit adds some testing coverage for the shutdown
callback. Neither shell_archive nor basic_archive have been using it,
and one is added to shell_archive, whose trigger is checked in a TAP
test through a shutdown sequence.
Author: Nathan Bossart, Bharath Rupireddy
Reviewed-by: Kyotaro Horiguchi, Michael Paquier
Discussion: https://postgr.es/m/20221015221328.GB1821022@nathanxps13
Backpatch-through: 15
2022-10-19 07:06:56 +02:00
|
|
|
* new archiver process starts up. Note that this triggers the
|
|
|
|
* module's shutdown callback, if defined.
|
2022-02-03 19:57:27 +01:00
|
|
|
*/
|
|
|
|
ereport(LOG,
|
|
|
|
(errmsg("restarting archiver process because value of "
|
2023-11-30 06:11:45 +01:00
|
|
|
"archive_library was changed")));
|
2022-02-03 19:57:27 +01:00
|
|
|
|
|
|
|
proc_exit(0);
|
|
|
|
}
|
2021-06-18 10:57:09 +02:00
|
|
|
}
|
2022-02-03 19:57:27 +01:00
|
|
|
}
|
2022-01-11 15:19:59 +01:00
|
|
|
|
2022-02-03 19:57:27 +01:00
|
|
|
/*
|
|
|
|
* LoadArchiveLibrary
|
|
|
|
*
|
Redesign archive modules
A new callback named startup_cb, called shortly after a module is
loaded, is added. This makes possible the initialization of any
additional state data required by a module. This initial state data can
be saved in a ArchiveModuleState, that is now passed down to all the
callbacks that can be defined in a module. With this design, it is
possible to have a per-module state, aimed at opening the door to the
support of more than one archive module.
The initialization of the callbacks is changed so as
_PG_archive_module_init() does not anymore give in input a
ArchiveModuleCallbacks that a module has to fill in with callback
definitions. Instead, a module now needs to return a const
ArchiveModuleCallbacks.
All the structure and callback definitions of archive modules are moved
into their own header, named archive_module.h, from pgarch.h.
Command-based archiving follows the same line, with a new set of files
named shell_archive.{c,h}.
There are a few more items that are under discussion to improve the
design of archive modules, like the fact that basic_archive calls
sigsetjmp() by itself to define its own error handling flow. These will
be adjusted later, the changes done here cover already a good portion
of what has been discussed.
Any modules created for v15 will need to be adjusted to this new
design.
Author: Nathan Bossart
Reviewed-by: Andres Freund
Discussion: https://postgr.es/m/20230130194810.6fztfgbn32e7qarj@awork3.anarazel.de
2023-02-17 06:26:42 +01:00
|
|
|
* Loads the archiving callbacks into our local ArchiveCallbacks.
|
2022-02-03 19:57:27 +01:00
|
|
|
*/
|
|
|
|
static void
|
|
|
|
LoadArchiveLibrary(void)
|
|
|
|
{
|
|
|
|
ArchiveModuleInit archive_init;
|
|
|
|
|
2022-11-15 10:03:12 +01:00
|
|
|
if (XLogArchiveLibrary[0] != '\0' && XLogArchiveCommand[0] != '\0')
|
|
|
|
ereport(ERROR,
|
|
|
|
(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
|
|
|
|
errmsg("both archive_command and archive_library set"),
|
|
|
|
errdetail("Only one of archive_command, archive_library may be set.")));
|
|
|
|
|
2022-02-03 19:57:27 +01:00
|
|
|
/*
|
|
|
|
* If shell archiving is enabled, use our special initialization function.
|
|
|
|
* Otherwise, load the library and call its _PG_archive_module_init().
|
|
|
|
*/
|
|
|
|
if (XLogArchiveLibrary[0] == '\0')
|
|
|
|
archive_init = shell_archive_init;
|
|
|
|
else
|
|
|
|
archive_init = (ArchiveModuleInit)
|
|
|
|
load_external_function(XLogArchiveLibrary,
|
|
|
|
"_PG_archive_module_init", false, NULL);
|
|
|
|
|
|
|
|
if (archive_init == NULL)
|
|
|
|
ereport(ERROR,
|
2022-09-25 00:38:35 +02:00
|
|
|
(errmsg("archive modules have to define the symbol %s", "_PG_archive_module_init")));
|
2022-02-03 19:57:27 +01:00
|
|
|
|
Redesign archive modules
A new callback named startup_cb, called shortly after a module is
loaded, is added. This makes possible the initialization of any
additional state data required by a module. This initial state data can
be saved in a ArchiveModuleState, that is now passed down to all the
callbacks that can be defined in a module. With this design, it is
possible to have a per-module state, aimed at opening the door to the
support of more than one archive module.
The initialization of the callbacks is changed so as
_PG_archive_module_init() does not anymore give in input a
ArchiveModuleCallbacks that a module has to fill in with callback
definitions. Instead, a module now needs to return a const
ArchiveModuleCallbacks.
All the structure and callback definitions of archive modules are moved
into their own header, named archive_module.h, from pgarch.h.
Command-based archiving follows the same line, with a new set of files
named shell_archive.{c,h}.
There are a few more items that are under discussion to improve the
design of archive modules, like the fact that basic_archive calls
sigsetjmp() by itself to define its own error handling flow. These will
be adjusted later, the changes done here cover already a good portion
of what has been discussed.
Any modules created for v15 will need to be adjusted to this new
design.
Author: Nathan Bossart
Reviewed-by: Andres Freund
Discussion: https://postgr.es/m/20230130194810.6fztfgbn32e7qarj@awork3.anarazel.de
2023-02-17 06:26:42 +01:00
|
|
|
ArchiveCallbacks = (*archive_init) ();
|
2022-02-03 19:57:27 +01:00
|
|
|
|
Redesign archive modules
A new callback named startup_cb, called shortly after a module is
loaded, is added. This makes possible the initialization of any
additional state data required by a module. This initial state data can
be saved in a ArchiveModuleState, that is now passed down to all the
callbacks that can be defined in a module. With this design, it is
possible to have a per-module state, aimed at opening the door to the
support of more than one archive module.
The initialization of the callbacks is changed so as
_PG_archive_module_init() does not anymore give in input a
ArchiveModuleCallbacks that a module has to fill in with callback
definitions. Instead, a module now needs to return a const
ArchiveModuleCallbacks.
All the structure and callback definitions of archive modules are moved
into their own header, named archive_module.h, from pgarch.h.
Command-based archiving follows the same line, with a new set of files
named shell_archive.{c,h}.
There are a few more items that are under discussion to improve the
design of archive modules, like the fact that basic_archive calls
sigsetjmp() by itself to define its own error handling flow. These will
be adjusted later, the changes done here cover already a good portion
of what has been discussed.
Any modules created for v15 will need to be adjusted to this new
design.
Author: Nathan Bossart
Reviewed-by: Andres Freund
Discussion: https://postgr.es/m/20230130194810.6fztfgbn32e7qarj@awork3.anarazel.de
2023-02-17 06:26:42 +01:00
|
|
|
if (ArchiveCallbacks->archive_file_cb == NULL)
|
2022-02-03 19:57:27 +01:00
|
|
|
ereport(ERROR,
|
|
|
|
(errmsg("archive modules must register an archive callback")));
|
Rework shutdown callback of archiver modules
As currently designed, with a callback registered in a ERROR_CLEANUP
block, the shutdown callback would get called twice when updating
archive_library on SIGHUP, which is something that we want to avoid to
ease the life of extension writers.
Anyway, an ERROR in the archiver process is treated as a FATAL, stopping
it immediately, hence there is no need for a ERROR_CLEANUP block.
Instead of that, the shutdown callback is not called upon
before_shmem_exit(), giving to the modules the opportunity to do any
cleanup actions before the server shuts down its subsystems.
While on it, this commit adds some testing coverage for the shutdown
callback. Neither shell_archive nor basic_archive have been using it,
and one is added to shell_archive, whose trigger is checked in a TAP
test through a shutdown sequence.
Author: Nathan Bossart, Bharath Rupireddy
Reviewed-by: Kyotaro Horiguchi, Michael Paquier
Discussion: https://postgr.es/m/20221015221328.GB1821022@nathanxps13
Backpatch-through: 15
2022-10-19 07:06:56 +02:00
|
|
|
|
Redesign archive modules
A new callback named startup_cb, called shortly after a module is
loaded, is added. This makes possible the initialization of any
additional state data required by a module. This initial state data can
be saved in a ArchiveModuleState, that is now passed down to all the
callbacks that can be defined in a module. With this design, it is
possible to have a per-module state, aimed at opening the door to the
support of more than one archive module.
The initialization of the callbacks is changed so as
_PG_archive_module_init() does not anymore give in input a
ArchiveModuleCallbacks that a module has to fill in with callback
definitions. Instead, a module now needs to return a const
ArchiveModuleCallbacks.
All the structure and callback definitions of archive modules are moved
into their own header, named archive_module.h, from pgarch.h.
Command-based archiving follows the same line, with a new set of files
named shell_archive.{c,h}.
There are a few more items that are under discussion to improve the
design of archive modules, like the fact that basic_archive calls
sigsetjmp() by itself to define its own error handling flow. These will
be adjusted later, the changes done here cover already a good portion
of what has been discussed.
Any modules created for v15 will need to be adjusted to this new
design.
Author: Nathan Bossart
Reviewed-by: Andres Freund
Discussion: https://postgr.es/m/20230130194810.6fztfgbn32e7qarj@awork3.anarazel.de
2023-02-17 06:26:42 +01:00
|
|
|
archive_module_state = (ArchiveModuleState *) palloc0(sizeof(ArchiveModuleState));
|
|
|
|
if (ArchiveCallbacks->startup_cb != NULL)
|
|
|
|
ArchiveCallbacks->startup_cb(archive_module_state);
|
|
|
|
|
Rework shutdown callback of archiver modules
As currently designed, with a callback registered in a ERROR_CLEANUP
block, the shutdown callback would get called twice when updating
archive_library on SIGHUP, which is something that we want to avoid to
ease the life of extension writers.
Anyway, an ERROR in the archiver process is treated as a FATAL, stopping
it immediately, hence there is no need for a ERROR_CLEANUP block.
Instead of that, the shutdown callback is not called upon
before_shmem_exit(), giving to the modules the opportunity to do any
cleanup actions before the server shuts down its subsystems.
While on it, this commit adds some testing coverage for the shutdown
callback. Neither shell_archive nor basic_archive have been using it,
and one is added to shell_archive, whose trigger is checked in a TAP
test through a shutdown sequence.
Author: Nathan Bossart, Bharath Rupireddy
Reviewed-by: Kyotaro Horiguchi, Michael Paquier
Discussion: https://postgr.es/m/20221015221328.GB1821022@nathanxps13
Backpatch-through: 15
2022-10-19 07:06:56 +02:00
|
|
|
before_shmem_exit(pgarch_call_module_shutdown_cb, 0);
|
2022-02-03 19:57:27 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
Rework shutdown callback of archiver modules
As currently designed, with a callback registered in a ERROR_CLEANUP
block, the shutdown callback would get called twice when updating
archive_library on SIGHUP, which is something that we want to avoid to
ease the life of extension writers.
Anyway, an ERROR in the archiver process is treated as a FATAL, stopping
it immediately, hence there is no need for a ERROR_CLEANUP block.
Instead of that, the shutdown callback is not called upon
before_shmem_exit(), giving to the modules the opportunity to do any
cleanup actions before the server shuts down its subsystems.
While on it, this commit adds some testing coverage for the shutdown
callback. Neither shell_archive nor basic_archive have been using it,
and one is added to shell_archive, whose trigger is checked in a TAP
test through a shutdown sequence.
Author: Nathan Bossart, Bharath Rupireddy
Reviewed-by: Kyotaro Horiguchi, Michael Paquier
Discussion: https://postgr.es/m/20221015221328.GB1821022@nathanxps13
Backpatch-through: 15
2022-10-19 07:06:56 +02:00
|
|
|
* Call the shutdown callback of the loaded archive module, if defined.
|
2022-02-03 19:57:27 +01:00
|
|
|
*/
|
|
|
|
static void
|
Rework shutdown callback of archiver modules
As currently designed, with a callback registered in a ERROR_CLEANUP
block, the shutdown callback would get called twice when updating
archive_library on SIGHUP, which is something that we want to avoid to
ease the life of extension writers.
Anyway, an ERROR in the archiver process is treated as a FATAL, stopping
it immediately, hence there is no need for a ERROR_CLEANUP block.
Instead of that, the shutdown callback is not called upon
before_shmem_exit(), giving to the modules the opportunity to do any
cleanup actions before the server shuts down its subsystems.
While on it, this commit adds some testing coverage for the shutdown
callback. Neither shell_archive nor basic_archive have been using it,
and one is added to shell_archive, whose trigger is checked in a TAP
test through a shutdown sequence.
Author: Nathan Bossart, Bharath Rupireddy
Reviewed-by: Kyotaro Horiguchi, Michael Paquier
Discussion: https://postgr.es/m/20221015221328.GB1821022@nathanxps13
Backpatch-through: 15
2022-10-19 07:06:56 +02:00
|
|
|
pgarch_call_module_shutdown_cb(int code, Datum arg)
|
2022-02-03 19:57:27 +01:00
|
|
|
{
|
Redesign archive modules
A new callback named startup_cb, called shortly after a module is
loaded, is added. This makes possible the initialization of any
additional state data required by a module. This initial state data can
be saved in a ArchiveModuleState, that is now passed down to all the
callbacks that can be defined in a module. With this design, it is
possible to have a per-module state, aimed at opening the door to the
support of more than one archive module.
The initialization of the callbacks is changed so as
_PG_archive_module_init() does not anymore give in input a
ArchiveModuleCallbacks that a module has to fill in with callback
definitions. Instead, a module now needs to return a const
ArchiveModuleCallbacks.
All the structure and callback definitions of archive modules are moved
into their own header, named archive_module.h, from pgarch.h.
Command-based archiving follows the same line, with a new set of files
named shell_archive.{c,h}.
There are a few more items that are under discussion to improve the
design of archive modules, like the fact that basic_archive calls
sigsetjmp() by itself to define its own error handling flow. These will
be adjusted later, the changes done here cover already a good portion
of what has been discussed.
Any modules created for v15 will need to be adjusted to this new
design.
Author: Nathan Bossart
Reviewed-by: Andres Freund
Discussion: https://postgr.es/m/20230130194810.6fztfgbn32e7qarj@awork3.anarazel.de
2023-02-17 06:26:42 +01:00
|
|
|
if (ArchiveCallbacks->shutdown_cb != NULL)
|
|
|
|
ArchiveCallbacks->shutdown_cb(archive_module_state);
|
2021-06-18 10:57:09 +02:00
|
|
|
}
|