summaryrefslogtreecommitdiff
path: root/src/backend/postmaster
diff options
context:
space:
mode:
authorRobert Haas2024-01-11 17:41:18 +0000
committerRobert Haas2024-01-11 17:41:18 +0000
commitd9ef650fca7bc574586f4171cd929cfd5240326e (patch)
treef855558ef73e86522b3859fa8ad4bc3fd005a38f /src/backend/postmaster
parent544bcb5a5e778e8ef8d784de611c5f85bc33433c (diff)
Add new function pg_get_wal_summarizer_state().
This makes it possible to access information about the progress of WAL summarization from SQL. The previously-added functions pg_available_wal_summaries() and pg_wal_summary_contents() only examine on-disk state, but this function exposes information from the server's shared memory. Discussion: http://postgr.es/m/CA+Tgmobvqqj-DW9F7uUzT-cQqs6wcVb-Xhs=w=hzJnXSE-kRGw@mail.gmail.com
Diffstat (limited to 'src/backend/postmaster')
-rw-r--r--src/backend/postmaster/walsummarizer.c65
1 files changed, 65 insertions, 0 deletions
diff --git a/src/backend/postmaster/walsummarizer.c b/src/backend/postmaster/walsummarizer.c
index f828cc436a6..7287f07529e 100644
--- a/src/backend/postmaster/walsummarizer.c
+++ b/src/backend/postmaster/walsummarizer.c
@@ -142,6 +142,7 @@ static XLogRecPtr redo_pointer_at_last_summary_removal = InvalidXLogRecPtr;
bool summarize_wal = false;
int wal_summary_keep_time = 10 * 24 * 60;
+static void WalSummarizerShutdown(int code, Datum arg);
static XLogRecPtr GetLatestLSN(TimeLineID *tli);
static void HandleWalSummarizerInterrupts(void);
static XLogRecPtr SummarizeWAL(TimeLineID tli, XLogRecPtr start_lsn,
@@ -245,6 +246,7 @@ WalSummarizerMain(void)
pqsignal(SIGUSR2, SIG_IGN); /* not used */
/* Advertise ourselves. */
+ on_shmem_exit(WalSummarizerShutdown, (Datum) 0);
LWLockAcquire(WALSummarizerLock, LW_EXCLUSIVE);
WalSummarizerCtl->summarizer_pgprocno = MyProc->pgprocno;
LWLockRelease(WALSummarizerLock);
@@ -418,6 +420,57 @@ WalSummarizerMain(void)
}
/*
+ * Get information about the state of the WAL summarizer.
+ */
+void
+GetWalSummarizerState(TimeLineID *summarized_tli, XLogRecPtr *summarized_lsn,
+ XLogRecPtr *pending_lsn, int *summarizer_pid)
+{
+ LWLockAcquire(WALSummarizerLock, LW_SHARED);
+ if (!WalSummarizerCtl->initialized)
+ {
+ /*
+ * If initialized is false, the rest of the structure contents are
+ * undefined.
+ */
+ *summarized_tli = 0;
+ *summarized_lsn = InvalidXLogRecPtr;
+ *pending_lsn = InvalidXLogRecPtr;
+ *summarizer_pid = -1;
+ }
+ else
+ {
+ int summarizer_pgprocno = WalSummarizerCtl->summarizer_pgprocno;
+
+ *summarized_tli = WalSummarizerCtl->summarized_tli;
+ *summarized_lsn = WalSummarizerCtl->summarized_lsn;
+ if (summarizer_pgprocno == INVALID_PGPROCNO)
+ {
+ /*
+ * If the summarizer has exited, the fact that it had processed
+ * beyond summarized_lsn is irrelevant now.
+ */
+ *pending_lsn = WalSummarizerCtl->summarized_lsn;
+ *summarizer_pid = -1;
+ }
+ else
+ {
+ *pending_lsn = WalSummarizerCtl->pending_lsn;
+
+ /*
+ * We're not fussed about inexact answers here, since they could
+ * become stale instantly, so we don't bother taking the lock, but
+ * make sure that invalid PID values are normalized to -1.
+ */
+ *summarizer_pid = GetPGProcByNumber(summarizer_pgprocno)->pid;
+ if (*summarizer_pid <= 0)
+ *summarizer_pid = -1;
+ }
+ }
+ LWLockRelease(WALSummarizerLock);
+}
+
+/*
* Get the oldest LSN in this server's timeline history that has not yet been
* summarized.
*
@@ -623,6 +676,18 @@ WaitForWalSummarization(XLogRecPtr lsn, long timeout, XLogRecPtr *pending_lsn)
}
/*
+ * On exit, update shared memory to make it clear that we're no longer
+ * running.
+ */
+static void
+WalSummarizerShutdown(int code, Datum arg)
+{
+ LWLockAcquire(WALSummarizerLock, LW_EXCLUSIVE);
+ WalSummarizerCtl->summarizer_pgprocno = INVALID_PGPROCNO;
+ LWLockRelease(WALSummarizerLock);
+}
+
+/*
* Get the latest LSN that is eligible to be summarized, and set *tli to the
* corresponding timeline.
*/