1/*-------------------------------------------------------------------------
4 * SQL-callable functions for accessing WAL summary data.
6 * Portions Copyright (c) 2010-2025, PostgreSQL Global Development Group
8 * src/backend/backup/walsummaryfuncs.c
10 *-------------------------------------------------------------------------
20#include "utils/fmgrprotos.h"
24 #define NUM_SUMMARY_ATTS 6
25 #define NUM_STATE_ATTS 4
26 #define MAX_BLOCKS_PER_CALL 256
29 * List the WAL summary files available in pg_wal/summaries.
43 memset(nulls, 0,
sizeof(nulls));
65 * List the contents of a WAL summary file identified by TLI, start LSN,
84 memset(nulls, 0,
sizeof(nulls));
87 * Since the timeline could at least in theory be more than 2^31, and
88 * since we don't have unsigned types at the SQL level, it is passed as a
89 * 64-bit integer. Test whether it's out of range.
94 errcode(ERRCODE_INVALID_PARAMETER_VALUE),
95 errmsg(
"invalid timeline %" PRId64, raw_tli));
97 /* Prepare to read the specified WAL summary file. */
107 /* Loop over relation forks. */
122 * If the limit block is not InvalidBlockNumber, emit an extra row
123 * with that block number and limit_block = true.
125 * There is no point in doing this when the limit_block is
126 * InvalidBlockNumber, because no block with that number or any higher
127 * number can ever exist.
138 /* Loop over blocks within the current relation fork. */
152 * For each block that we specifically know to have been modified,
153 * emit a row with that block number and limit_block = false.
156 for (
i = 0;
i < nblocks; ++
i)
174 * Returns information about the state of the WAL summarizer process.
192 elog(
ERROR,
"return type must be a row type");
194 memset(nulls, 0,
sizeof(nulls));
200 if (summarizer_pid < 0)
bool BlockRefTableReaderNextRelation(BlockRefTableReader *reader, RelFileLocator *rlocator, ForkNumber *forknum, BlockNumber *limit_block)
BlockRefTableReader * CreateBlockRefTableReader(io_callback_fn read_callback, void *read_callback_arg, char *error_filename, report_error_fn error_callback, void *error_callback_arg)
unsigned BlockRefTableReaderGetBlocks(BlockRefTableReader *reader, BlockNumber *blocks, int nblocks)
void DestroyBlockRefTableReader(BlockRefTableReader *reader)
static bool BlockNumberIsValid(BlockNumber blockNumber)
static Datum values[MAXATTR]
int errcode(int sqlerrcode)
int errmsg(const char *fmt,...)
#define ereport(elevel,...)
char * FilePathName(File file)
void FileClose(File file)
#define PG_GETARG_INT64(n)
#define PG_RETURN_DATUM(x)
void InitMaterializedSRF(FunctionCallInfo fcinfo, bits32 flags)
TypeFuncClass get_call_result_type(FunctionCallInfo fcinfo, Oid *resultTypeId, TupleDesc *resultTupleDesc)
static Datum HeapTupleGetDatum(const HeapTupleData *tuple)
HeapTuple heap_form_tuple(TupleDesc tupleDescriptor, const Datum *values, const bool *isnull)
#define CHECK_FOR_INTERRUPTS()
static Datum LSNGetDatum(XLogRecPtr X)
static Datum Int64GetDatum(int64 X)
static Datum Int16GetDatum(int16 X)
static Datum BoolGetDatum(bool X)
static Datum ObjectIdGetDatum(Oid X)
static Datum Int32GetDatum(int32 X)
Tuplestorestate * setResult
void tuplestore_puttuple(Tuplestorestate *state, HeapTuple tuple)
void GetWalSummarizerState(TimeLineID *summarized_tli, XLogRecPtr *summarized_lsn, XLogRecPtr *pending_lsn, int *summarizer_pid)
File OpenWalSummaryFile(WalSummaryFile *ws, bool missing_ok)
int ReadWalSummary(void *wal_summary_io, void *data, int length)
List * GetWalSummaries(TimeLineID tli, XLogRecPtr start_lsn, XLogRecPtr end_lsn)
void ReportWalSummaryError(void *callback_arg, char *fmt,...)
Datum pg_get_wal_summarizer_state(PG_FUNCTION_ARGS)
Datum pg_available_wal_summaries(PG_FUNCTION_ARGS)
#define MAX_BLOCKS_PER_CALL
Datum pg_wal_summary_contents(PG_FUNCTION_ARGS)
#define InvalidXLogRecPtr