@@ -142,6 +142,7 @@ static XLogRecPtr redo_pointer_at_last_summary_removal = InvalidXLogRecPtr;
142
142
bool summarize_wal = false;
143
143
int wal_summary_keep_time = 10 * 24 * 60 ;
144
144
145
+ static void WalSummarizerShutdown (int code , Datum arg );
145
146
static XLogRecPtr GetLatestLSN (TimeLineID * tli );
146
147
static void HandleWalSummarizerInterrupts (void );
147
148
static XLogRecPtr SummarizeWAL (TimeLineID tli , XLogRecPtr start_lsn ,
@@ -245,6 +246,7 @@ WalSummarizerMain(void)
245
246
pqsignal (SIGUSR2 , SIG_IGN ); /* not used */
246
247
247
248
/* Advertise ourselves. */
249
+ on_shmem_exit (WalSummarizerShutdown , (Datum ) 0 );
248
250
LWLockAcquire (WALSummarizerLock , LW_EXCLUSIVE );
249
251
WalSummarizerCtl -> summarizer_pgprocno = MyProc -> pgprocno ;
250
252
LWLockRelease (WALSummarizerLock );
@@ -417,6 +419,57 @@ WalSummarizerMain(void)
417
419
}
418
420
}
419
421
422
+ /*
423
+ * Get information about the state of the WAL summarizer.
424
+ */
425
+ void
426
+ GetWalSummarizerState (TimeLineID * summarized_tli , XLogRecPtr * summarized_lsn ,
427
+ XLogRecPtr * pending_lsn , int * summarizer_pid )
428
+ {
429
+ LWLockAcquire (WALSummarizerLock , LW_SHARED );
430
+ if (!WalSummarizerCtl -> initialized )
431
+ {
432
+ /*
433
+ * If initialized is false, the rest of the structure contents are
434
+ * undefined.
435
+ */
436
+ * summarized_tli = 0 ;
437
+ * summarized_lsn = InvalidXLogRecPtr ;
438
+ * pending_lsn = InvalidXLogRecPtr ;
439
+ * summarizer_pid = -1 ;
440
+ }
441
+ else
442
+ {
443
+ int summarizer_pgprocno = WalSummarizerCtl -> summarizer_pgprocno ;
444
+
445
+ * summarized_tli = WalSummarizerCtl -> summarized_tli ;
446
+ * summarized_lsn = WalSummarizerCtl -> summarized_lsn ;
447
+ if (summarizer_pgprocno == INVALID_PGPROCNO )
448
+ {
449
+ /*
450
+ * If the summarizer has exited, the fact that it had processed
451
+ * beyond summarized_lsn is irrelevant now.
452
+ */
453
+ * pending_lsn = WalSummarizerCtl -> summarized_lsn ;
454
+ * summarizer_pid = -1 ;
455
+ }
456
+ else
457
+ {
458
+ * pending_lsn = WalSummarizerCtl -> pending_lsn ;
459
+
460
+ /*
461
+ * We're not fussed about inexact answers here, since they could
462
+ * become stale instantly, so we don't bother taking the lock, but
463
+ * make sure that invalid PID values are normalized to -1.
464
+ */
465
+ * summarizer_pid = GetPGProcByNumber (summarizer_pgprocno )-> pid ;
466
+ if (* summarizer_pid <= 0 )
467
+ * summarizer_pid = -1 ;
468
+ }
469
+ }
470
+ LWLockRelease (WALSummarizerLock );
471
+ }
472
+
420
473
/*
421
474
* Get the oldest LSN in this server's timeline history that has not yet been
422
475
* summarized.
@@ -622,6 +675,18 @@ WaitForWalSummarization(XLogRecPtr lsn, long timeout, XLogRecPtr *pending_lsn)
622
675
return summarized_lsn ;
623
676
}
624
677
678
+ /*
679
+ * On exit, update shared memory to make it clear that we're no longer
680
+ * running.
681
+ */
682
+ static void
683
+ WalSummarizerShutdown (int code , Datum arg )
684
+ {
685
+ LWLockAcquire (WALSummarizerLock , LW_EXCLUSIVE );
686
+ WalSummarizerCtl -> summarizer_pgprocno = INVALID_PGPROCNO ;
687
+ LWLockRelease (WALSummarizerLock );
688
+ }
689
+
625
690
/*
626
691
* Get the latest LSN that is eligible to be summarized, and set *tli to the
627
692
* corresponding timeline.
0 commit comments