46 bool *nulls,
uint32 ncols);
52 bool stats_per_record);
54 uint64 rec_len, uint64 total_rec_len,
55 uint64 fpi_len, uint64 total_fpi_len,
56 uint64 tot_len, uint64 total_len,
61 bool stats_per_record);
102 if (lsn < XLOG_BLCKSZ)
104 (
errmsg(
"could not read WAL at LSN %X/%X",
118 (
errcode(ERRCODE_OUT_OF_MEMORY),
120 errdetail(
"Failed while allocating a WAL reading processor.")));
127 (
errmsg(
"could not find a valid record after %X/%X",
167 errmsg(
"could not read WAL at %X/%X: %s",
172 errmsg(
"could not read WAL at %X/%X",
189 bool *nulls,
uint32 ncols)
191 const char *record_type;
201 if (record_type == NULL)
205 desc.
rm_desc(&rec_desc, record);
223 if (rec_desc.
len > 0)
251 #define PG_GET_WAL_BLOCK_INFO_COLS 20
255 const char *record_type;
263 if (record_type == NULL)
264 record_type =
psprintf(
"UNKNOWN (%x)",
268 desc.rm_desc(&rec_desc, record);
278 uint32 block_data_len = 0,
289 &rnode, &forknum, &blkno, NULL);
358 if (rec_desc.len > 0)
370 memcpy(
VARDATA(block_data), blk->
data, block_data_len);
381 bytea *block_fpi_data;
386 (
errcode(ERRCODE_INTERNAL_ERROR),
391 memcpy(
VARDATA(block_fpi_data), page, BLCKSZ);
404 #undef PG_GET_WAL_BLOCK_INFO_COLS
427 "pg_get_wal_block_info temporary cxt",
461 #define PG_GET_WAL_RECORD_INFO_COLS 11
476 (
errcode(ERRCODE_INVALID_PARAMETER_VALUE),
477 errmsg(
"WAL input LSN must be less than current LSN"),
478 errdetail(
"Current WAL LSN on the database system is at %X/%X.",
483 elog(
ERROR,
"return type must be a row type");
489 (
errcode(ERRCODE_INVALID_PARAMETER_VALUE),
490 errmsg(
"could not read WAL at %X/%X",
502 #undef PG_GET_WAL_RECORD_INFO_COLS
516 if (start_lsn > curr_lsn)
518 (
errcode(ERRCODE_INVALID_PARAMETER_VALUE),
519 errmsg(
"WAL start LSN must be less than current LSN"),
520 errdetail(
"Current WAL LSN on the database system is at %X/%X.",
523 if (start_lsn > *end_lsn)
525 (
errcode(ERRCODE_INVALID_PARAMETER_VALUE),
526 errmsg(
"WAL start LSN must be less than end LSN")));
528 if (*end_lsn > curr_lsn)
539 #define PG_GET_WAL_RECORDS_INFO_COLS 11
545 Assert(start_lsn <= end_lsn);
552 "GetWALRecordsInfo temporary cxt",
581 #undef PG_GET_WAL_RECORDS_INFO_COLS
604 uint64 n, uint64 total_count,
605 uint64 rec_len, uint64 total_rec_len,
606 uint64 fpi_len, uint64 total_fpi_len,
607 uint64 tot_len, uint64 total_len,
617 if (total_count != 0)
618 n_pct = 100 * (double) n / total_count;
621 if (total_rec_len != 0)
622 rec_len_pct = 100 * (double) rec_len / total_rec_len;
625 if (total_fpi_len != 0)
626 fpi_len_pct = 100 * (double) fpi_len / total_fpi_len;
630 tot_len_pct = 100 * (double) tot_len / total_len;
651 bool stats_per_record)
655 uint64 total_count = 0;
656 uint64 total_rec_len = 0;
657 uint64 total_fpi_len = 0;
658 uint64 total_len = 0;
674 total_len = total_rec_len + total_fpi_len;
677 "GetXLogSummaryStats temporary cxt",
696 if (stats_per_record)
707 tot_len = rec_len + fpi_len;
718 id =
psprintf(
"UNKNOWN (%x)", rj << 4);
721 total_count, rec_len, total_rec_len, fpi_len,
722 total_fpi_len, tot_len, total_len,
738 tot_len = rec_len + fpi_len;
743 total_rec_len, fpi_len, total_fpi_len, tot_len,
744 total_len,
values, nulls, ncols);
763 bool stats_per_record)
765 #define PG_GET_WAL_STATS_COLS 9
772 Assert(start_lsn <= end_lsn);
793 #undef PG_GET_WAL_STATS_COLS
807 GetWalStats(fcinfo, start_lsn, end_lsn, stats_per_record);
822 if (start_lsn > end_lsn)
824 (
errcode(ERRCODE_INVALID_PARAMETER_VALUE),
825 errmsg(
"WAL start LSN must be less than current LSN"),
826 errdetail(
"Current WAL LSN on the database system is at %X/%X.",
841 if (start_lsn > end_lsn)
843 (
errcode(ERRCODE_INVALID_PARAMETER_VALUE),
844 errmsg(
"WAL start LSN must be less than current LSN"),
845 errdetail(
"Current WAL LSN on the database system is at %X/%X.",
848 GetWalStats(fcinfo, start_lsn, end_lsn, stats_per_record);
ArrayType * construct_array_builtin(Datum *elems, int nelems, Oid elmtype)
static Datum values[MAXATTR]
#define CStringGetTextDatum(s)
elog(ERROR, "%s: %s", p2, msg)
int errmsg_internal(const char *fmt,...)
int errcode_for_file_access(void)
int errdetail(const char *fmt,...)
int errcode(int sqlerrcode)
int errmsg(const char *fmt,...)
#define ereport(elevel,...)
Datum Int64GetDatum(int64 X)
Datum Float8GetDatum(float8 X)
#define PG_GETARG_BOOL(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, Datum *values, bool *isnull)
if(TABLE==NULL||TABLE_index==NULL)
Assert(fmt[strlen(fmt) - 1] !='\n')
void MemoryContextReset(MemoryContext context)
void pfree(void *pointer)
void * palloc0(Size size)
MemoryContext CurrentMemoryContext
void MemoryContextDelete(MemoryContext context)
#define AllocSetContextCreate
#define ALLOCSET_DEFAULT_SIZES
#define CHECK_FOR_INTERRUPTS()
static MemoryContext MemoryContextSwitchTo(MemoryContext context)
uint64 pg_popcount(const char *buf, int bytes)
static Datum LSNGetDatum(XLogRecPtr X)
static void GetWALRecordInfo(XLogReaderState *record, Datum *values, bool *nulls, uint32 ncols)
#define PG_GET_WAL_STATS_COLS
Datum pg_get_wal_records_info(PG_FUNCTION_ARGS)
Datum pg_get_wal_stats(PG_FUNCTION_ARGS)
static void GetWalStats(FunctionCallInfo fcinfo, XLogRecPtr start_lsn, XLogRecPtr end_lsn, bool stats_per_record)
#define PG_GET_WAL_RECORDS_INFO_COLS
#define PG_GET_WAL_RECORD_INFO_COLS
static void GetWALBlockInfo(FunctionCallInfo fcinfo, XLogReaderState *record, bool show_data)
Datum pg_get_wal_block_info(PG_FUNCTION_ARGS)
static void GetWALRecordsInfo(FunctionCallInfo fcinfo, XLogRecPtr start_lsn, XLogRecPtr end_lsn)
Datum pg_get_wal_records_info_till_end_of_wal(PG_FUNCTION_ARGS)
#define PG_GET_WAL_BLOCK_INFO_COLS
static XLogRecord * ReadNextXLogRecord(XLogReaderState *xlogreader)
static XLogReaderState * InitXLogReaderState(XLogRecPtr lsn)
Datum pg_get_wal_stats_till_end_of_wal(PG_FUNCTION_ARGS)
static void GetXLogSummaryStats(XLogStats *stats, ReturnSetInfo *rsinfo, Datum *values, bool *nulls, uint32 ncols, bool stats_per_record)
PG_FUNCTION_INFO_V1(pg_get_wal_block_info)
static void FillXLogStatsRow(const char *name, uint64 n, uint64 total_count, uint64 rec_len, uint64 total_rec_len, uint64 fpi_len, uint64 total_fpi_len, uint64 tot_len, uint64 total_len, Datum *values, bool *nulls, uint32 ncols)
static void ValidateInputLSNs(XLogRecPtr start_lsn, XLogRecPtr *end_lsn)
Datum pg_get_wal_record_info(PG_FUNCTION_ARGS)
static XLogRecPtr GetCurrentLSN(void)
static Datum PointerGetDatum(const void *X)
static Datum TransactionIdGetDatum(TransactionId X)
static Datum Int16GetDatum(int16 X)
static Datum ObjectIdGetDatum(Oid X)
static Datum UInt32GetDatum(uint32 X)
char * psprintf(const char *fmt,...)
#define RmgrIdIsValid(rmid)
void initStringInfo(StringInfo str)
Tuplestorestate * setResult
const char *(* rm_identify)(uint8 info)
void(* rm_desc)(StringInfo buf, XLogReaderState *record)
XLogRecStats record_stats[RM_MAX_ID+1][MAX_XLINFO_TYPES]
XLogRecStats rmgr_stats[RM_MAX_ID+1]
void tuplestore_putvalues(Tuplestorestate *state, TupleDesc tdesc, Datum *values, bool *isnull)
#define SET_VARSIZE(PTR, len)
bool RecoveryInProgress(void)
XLogRecPtr GetFlushRecPtr(TimeLineID *insertTLI)
static RmgrData GetRmgr(RmgrId rmid)
static bool RmgrIdExists(RmgrId rmid)
#define LSN_FORMAT_ARGS(lsn)
#define XLogRecPtrIsInvalid(r)
void XLogRecGetBlockRefInfo(XLogReaderState *record, bool pretty, bool detailed_format, StringInfo buf, uint32 *fpi_len)
bool XLogRecGetBlockTagExtended(XLogReaderState *record, uint8 block_id, RelFileLocator *rlocator, ForkNumber *forknum, BlockNumber *blknum, Buffer *prefetch_buffer)
XLogRecord * XLogReadRecord(XLogReaderState *state, char **errormsg)
void XLogReaderFree(XLogReaderState *state)
XLogReaderState * XLogReaderAllocate(int wal_segment_size, const char *waldir, XLogReaderRoutine *routine, void *private_data)
XLogRecPtr XLogFindNextRecord(XLogReaderState *state, XLogRecPtr RecPtr)
bool RestoreBlockImage(XLogReaderState *record, uint8 block_id, char *page)
#define XLogRecGetDataLen(decoder)
#define XLogRecGetInfo(decoder)
#define XLogRecGetRmid(decoder)
#define XLogRecGetTotalLen(decoder)
#define XLogRecGetXid(decoder)
#define XLogRecGetBlock(decoder, i)
#define XLogRecMaxBlockId(decoder)
#define XLogRecHasBlockRef(decoder, block_id)
#define XLogRecGetPrev(decoder)
#define XLogRecHasAnyBlockRefs(decoder)
#define BKPIMAGE_COMPRESS_ZSTD
#define BKPIMAGE_HAS_HOLE
#define BKPIMAGE_COMPRESS_LZ4
#define BKPIMAGE_COMPRESS_PGLZ
XLogRecPtr GetXLogReplayRecPtr(TimeLineID *replayTLI)
static XLogReaderState * xlogreader
void XLogRecStoreStats(XLogStats *stats, XLogReaderState *record)
void wal_segment_close(XLogReaderState *state)
void wal_segment_open(XLogReaderState *state, XLogSegNo nextSegNo, TimeLineID *tli_p)
int read_local_xlog_page_no_wait(XLogReaderState *state, XLogRecPtr targetPagePtr, int reqLen, XLogRecPtr targetRecPtr, char *cur_page)