2021-08-05 21:09:19 +02:00
|
|
|
/*-------------------------------------------------------------------------
|
|
|
|
* auxprocess.c
|
|
|
|
* functions related to auxiliary processes.
|
|
|
|
*
|
|
|
|
*
|
2024-01-04 02:49:05 +01:00
|
|
|
* Portions Copyright (c) 1996-2024, PostgreSQL Global Development Group
|
2021-08-05 21:09:19 +02:00
|
|
|
* Portions Copyright (c) 1994, Regents of the University of California
|
|
|
|
*
|
|
|
|
* IDENTIFICATION
|
|
|
|
* src/backend/postmaster/auxprocess.c
|
|
|
|
*-------------------------------------------------------------------------
|
|
|
|
*/
|
|
|
|
#include "postgres.h"
|
|
|
|
|
|
|
|
#include <unistd.h>
|
|
|
|
#include <signal.h>
|
|
|
|
|
|
|
|
#include "libpq/pqsignal.h"
|
|
|
|
#include "miscadmin.h"
|
|
|
|
#include "pgstat.h"
|
|
|
|
#include "postmaster/auxprocess.h"
|
|
|
|
#include "postmaster/bgwriter.h"
|
|
|
|
#include "postmaster/startup.h"
|
Add a new WAL summarizer process.
When active, this process writes WAL summary files to
$PGDATA/pg_wal/summaries. Each summary file contains information for a
certain range of LSNs on a certain TLI. For each relation, it stores a
"limit block" which is 0 if a relation is created or destroyed within
a certain range of WAL records, or otherwise the shortest length to
which the relation was truncated during that range of WAL records, or
otherwise InvalidBlockNumber. In addition, it stores a list of blocks
which have been modified during that range of WAL records, but
excluding blocks which were removed by truncation after they were
modified and never subsequently modified again.
In other words, it tells us which blocks need to copied in case of an
incremental backup covering that range of WAL records. But this
doesn't yet add the capability to actually perform an incremental
backup; the next patch will do that.
A new parameter summarize_wal enables or disables this new background
process. The background process also automatically deletes summary
files that are older than wal_summarize_keep_time, if that parameter
has a non-zero value and the summarizer is configured to run.
Patch by me, with some design help from Dilip Kumar and Andres Freund.
Reviewed by Matthias van de Meent, Dilip Kumar, Jakub Wartak, Peter
Eisentraut, and Álvaro Herrera.
Discussion: http://postgr.es/m/CA+TgmoYOYZfMCyOXFyC-P+-mdrZqm5pP2N7S-r0z3_402h9rsA@mail.gmail.com
2023-12-20 14:41:09 +01:00
|
|
|
#include "postmaster/walsummarizer.h"
|
2021-08-05 21:09:19 +02:00
|
|
|
#include "postmaster/walwriter.h"
|
|
|
|
#include "replication/walreceiver.h"
|
|
|
|
#include "storage/bufmgr.h"
|
|
|
|
#include "storage/bufpage.h"
|
|
|
|
#include "storage/condition_variable.h"
|
|
|
|
#include "storage/ipc.h"
|
|
|
|
#include "storage/proc.h"
|
|
|
|
#include "tcop/tcopprot.h"
|
|
|
|
#include "utils/memutils.h"
|
|
|
|
#include "utils/ps_status.h"
|
|
|
|
#include "utils/rel.h"
|
|
|
|
|
|
|
|
|
|
|
|
static void ShutdownAuxiliaryProcess(int code, Datum arg);
|
|
|
|
|
|
|
|
|
|
|
|
/* ----------------
|
|
|
|
* global variables
|
|
|
|
* ----------------
|
|
|
|
*/
|
|
|
|
|
|
|
|
AuxProcType MyAuxProcType = NotAnAuxProcess; /* declared in miscadmin.h */
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* AuxiliaryProcessMain
|
|
|
|
*
|
|
|
|
* The main entry point for auxiliary processes, such as the bgwriter,
|
|
|
|
* walwriter, walreceiver, bootstrapper and the shared memory checker code.
|
|
|
|
*
|
|
|
|
* This code is here just because of historical reasons.
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
AuxiliaryProcessMain(AuxProcType auxtype)
|
|
|
|
{
|
|
|
|
Assert(IsUnderPostmaster);
|
|
|
|
|
|
|
|
MyAuxProcType = auxtype;
|
|
|
|
|
|
|
|
switch (MyAuxProcType)
|
|
|
|
{
|
|
|
|
case StartupProcess:
|
|
|
|
MyBackendType = B_STARTUP;
|
|
|
|
break;
|
|
|
|
case ArchiverProcess:
|
|
|
|
MyBackendType = B_ARCHIVER;
|
|
|
|
break;
|
|
|
|
case BgWriterProcess:
|
|
|
|
MyBackendType = B_BG_WRITER;
|
|
|
|
break;
|
|
|
|
case CheckpointerProcess:
|
|
|
|
MyBackendType = B_CHECKPOINTER;
|
|
|
|
break;
|
|
|
|
case WalWriterProcess:
|
|
|
|
MyBackendType = B_WAL_WRITER;
|
|
|
|
break;
|
|
|
|
case WalReceiverProcess:
|
|
|
|
MyBackendType = B_WAL_RECEIVER;
|
|
|
|
break;
|
Add a new WAL summarizer process.
When active, this process writes WAL summary files to
$PGDATA/pg_wal/summaries. Each summary file contains information for a
certain range of LSNs on a certain TLI. For each relation, it stores a
"limit block" which is 0 if a relation is created or destroyed within
a certain range of WAL records, or otherwise the shortest length to
which the relation was truncated during that range of WAL records, or
otherwise InvalidBlockNumber. In addition, it stores a list of blocks
which have been modified during that range of WAL records, but
excluding blocks which were removed by truncation after they were
modified and never subsequently modified again.
In other words, it tells us which blocks need to copied in case of an
incremental backup covering that range of WAL records. But this
doesn't yet add the capability to actually perform an incremental
backup; the next patch will do that.
A new parameter summarize_wal enables or disables this new background
process. The background process also automatically deletes summary
files that are older than wal_summarize_keep_time, if that parameter
has a non-zero value and the summarizer is configured to run.
Patch by me, with some design help from Dilip Kumar and Andres Freund.
Reviewed by Matthias van de Meent, Dilip Kumar, Jakub Wartak, Peter
Eisentraut, and Álvaro Herrera.
Discussion: http://postgr.es/m/CA+TgmoYOYZfMCyOXFyC-P+-mdrZqm5pP2N7S-r0z3_402h9rsA@mail.gmail.com
2023-12-20 14:41:09 +01:00
|
|
|
case WalSummarizerProcess:
|
|
|
|
MyBackendType = B_WAL_SUMMARIZER;
|
|
|
|
break;
|
2021-08-05 21:09:19 +02:00
|
|
|
default:
|
2022-08-11 20:12:11 +02:00
|
|
|
elog(PANIC, "unrecognized process type: %d", (int) MyAuxProcType);
|
2021-08-05 21:09:19 +02:00
|
|
|
MyBackendType = B_INVALID;
|
|
|
|
}
|
|
|
|
|
|
|
|
init_ps_display(NULL);
|
|
|
|
|
|
|
|
SetProcessingMode(BootstrapProcessing);
|
|
|
|
IgnoreSystemIndexes = true;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* As an auxiliary process, we aren't going to do the full InitPostgres
|
|
|
|
* pushups, but there are a couple of things that need to get lit up even
|
|
|
|
* in an auxiliary process.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
2023-12-03 15:39:18 +01:00
|
|
|
* Create a PGPROC so we can use LWLocks and access shared memory.
|
2021-08-05 21:09:19 +02:00
|
|
|
*/
|
|
|
|
InitAuxiliaryProcess();
|
|
|
|
|
2021-08-05 23:37:09 +02:00
|
|
|
BaseInit();
|
|
|
|
|
2021-08-05 21:09:19 +02:00
|
|
|
/*
|
|
|
|
* Assign the ProcSignalSlot for an auxiliary process. Since it doesn't
|
|
|
|
* have a BackendId, the slot is statically allocated based on the
|
|
|
|
* auxiliary process type (MyAuxProcType). Backends use slots indexed in
|
|
|
|
* the range from 1 to MaxBackends (inclusive), so we use MaxBackends +
|
|
|
|
* AuxProcType + 1 as the index of the slot for an auxiliary process.
|
|
|
|
*
|
|
|
|
* This will need rethinking if we ever want more than one of a particular
|
|
|
|
* auxiliary process type.
|
|
|
|
*/
|
2022-04-12 20:45:23 +02:00
|
|
|
ProcSignalInit(MaxBackends + MyAuxProcType + 1);
|
2021-08-05 21:09:19 +02:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Auxiliary processes don't run transactions, but they may need a
|
|
|
|
* resource owner anyway to manage buffer pins acquired outside
|
|
|
|
* transactions (and, perhaps, other things in future).
|
|
|
|
*/
|
|
|
|
CreateAuxProcessResourceOwner();
|
|
|
|
|
|
|
|
|
|
|
|
/* Initialize backend status information */
|
|
|
|
pgstat_beinit();
|
|
|
|
pgstat_bestart();
|
|
|
|
|
|
|
|
/* register a before-shutdown callback for LWLock cleanup */
|
|
|
|
before_shmem_exit(ShutdownAuxiliaryProcess, 0);
|
|
|
|
|
|
|
|
SetProcessingMode(NormalProcessing);
|
|
|
|
|
|
|
|
switch (MyAuxProcType)
|
|
|
|
{
|
|
|
|
case StartupProcess:
|
|
|
|
StartupProcessMain();
|
|
|
|
proc_exit(1);
|
|
|
|
|
|
|
|
case ArchiverProcess:
|
|
|
|
PgArchiverMain();
|
|
|
|
proc_exit(1);
|
|
|
|
|
|
|
|
case BgWriterProcess:
|
|
|
|
BackgroundWriterMain();
|
|
|
|
proc_exit(1);
|
|
|
|
|
|
|
|
case CheckpointerProcess:
|
|
|
|
CheckpointerMain();
|
|
|
|
proc_exit(1);
|
|
|
|
|
|
|
|
case WalWriterProcess:
|
|
|
|
WalWriterMain();
|
|
|
|
proc_exit(1);
|
|
|
|
|
|
|
|
case WalReceiverProcess:
|
|
|
|
WalReceiverMain();
|
|
|
|
proc_exit(1);
|
|
|
|
|
Add a new WAL summarizer process.
When active, this process writes WAL summary files to
$PGDATA/pg_wal/summaries. Each summary file contains information for a
certain range of LSNs on a certain TLI. For each relation, it stores a
"limit block" which is 0 if a relation is created or destroyed within
a certain range of WAL records, or otherwise the shortest length to
which the relation was truncated during that range of WAL records, or
otherwise InvalidBlockNumber. In addition, it stores a list of blocks
which have been modified during that range of WAL records, but
excluding blocks which were removed by truncation after they were
modified and never subsequently modified again.
In other words, it tells us which blocks need to copied in case of an
incremental backup covering that range of WAL records. But this
doesn't yet add the capability to actually perform an incremental
backup; the next patch will do that.
A new parameter summarize_wal enables or disables this new background
process. The background process also automatically deletes summary
files that are older than wal_summarize_keep_time, if that parameter
has a non-zero value and the summarizer is configured to run.
Patch by me, with some design help from Dilip Kumar and Andres Freund.
Reviewed by Matthias van de Meent, Dilip Kumar, Jakub Wartak, Peter
Eisentraut, and Álvaro Herrera.
Discussion: http://postgr.es/m/CA+TgmoYOYZfMCyOXFyC-P+-mdrZqm5pP2N7S-r0z3_402h9rsA@mail.gmail.com
2023-12-20 14:41:09 +01:00
|
|
|
case WalSummarizerProcess:
|
|
|
|
WalSummarizerMain();
|
|
|
|
proc_exit(1);
|
|
|
|
|
2021-08-05 21:09:19 +02:00
|
|
|
default:
|
|
|
|
elog(PANIC, "unrecognized process type: %d", (int) MyAuxProcType);
|
|
|
|
proc_exit(1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Begin shutdown of an auxiliary process. This is approximately the equivalent
|
|
|
|
* of ShutdownPostgres() in postinit.c. We can't run transactions in an
|
|
|
|
* auxiliary process, so most of the work of AbortTransaction() is not needed,
|
|
|
|
* but we do need to make sure we've released any LWLocks we are holding.
|
|
|
|
* (This is only critical during an error exit.)
|
|
|
|
*/
|
|
|
|
static void
|
|
|
|
ShutdownAuxiliaryProcess(int code, Datum arg)
|
|
|
|
{
|
|
|
|
LWLockReleaseAll();
|
|
|
|
ConditionVariableCancelSleep();
|
|
|
|
pgstat_report_wait_end();
|
|
|
|
}
|