diff options
author | Robert Haas <rhaas@postgresql.org> | 2024-01-11 12:41:18 -0500 |
---|---|---|
committer | Robert Haas <rhaas@postgresql.org> | 2024-01-11 12:41:18 -0500 |
commit | d9ef650fca7bc574586f4171cd929cfd5240326e (patch) | |
tree | f855558ef73e86522b3859fa8ad4bc3fd005a38f /src/backend/backup/walsummaryfuncs.c | |
parent | 544bcb5a5e778e8ef8d784de611c5f85bc33433c (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/backup/walsummaryfuncs.c')
-rw-r--r-- | src/backend/backup/walsummaryfuncs.c | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/src/backend/backup/walsummaryfuncs.c b/src/backend/backup/walsummaryfuncs.c index 89c660c6969..f082488b33f 100644 --- a/src/backend/backup/walsummaryfuncs.c +++ b/src/backend/backup/walsummaryfuncs.c @@ -16,11 +16,13 @@ #include "common/blkreftable.h" #include "funcapi.h" #include "miscadmin.h" +#include "postmaster/walsummarizer.h" #include "utils/fmgrprotos.h" #include "utils/pg_lsn.h" #define NUM_WS_ATTS 3 #define NUM_SUMMARY_ATTS 6 +#define NUM_STATE_ATTS 4 #define MAX_BLOCKS_PER_CALL 256 /* @@ -167,3 +169,40 @@ pg_wal_summary_contents(PG_FUNCTION_ARGS) return (Datum) 0; } + +/* + * Returns information about the state of the WAL summarizer process. + */ +Datum +pg_get_wal_summarizer_state(PG_FUNCTION_ARGS) +{ + Datum values[NUM_STATE_ATTS]; + bool nulls[NUM_STATE_ATTS]; + TimeLineID summarized_tli; + XLogRecPtr summarized_lsn; + XLogRecPtr pending_lsn; + int summarizer_pid; + TupleDesc tupdesc; + HeapTuple htup; + + GetWalSummarizerState(&summarized_tli, &summarized_lsn, &pending_lsn, + &summarizer_pid); + + if (get_call_result_type(fcinfo, NULL, &tupdesc) != TYPEFUNC_COMPOSITE) + elog(ERROR, "return type must be a row type"); + + memset(nulls, 0, sizeof(nulls)); + + values[0] = Int64GetDatum((int64) summarized_tli); + values[1] = LSNGetDatum(summarized_lsn); + values[2] = LSNGetDatum(pending_lsn); + + if (summarizer_pid < 0) + nulls[3] = true; + else + values[3] = Int32GetDatum(summarizer_pid); + + htup = heap_form_tuple(tupdesc, values, nulls); + + PG_RETURN_DATUM(HeapTupleGetDatum(htup)); +} |