1/*-------------------------------------------------------------------------
4 * Prints the contents of WAL summary files.
6 * Copyright (c) 2017-2025, PostgreSQL Global Development Group
9 * src/bin/pg_walsummary/pg_walsummary.c
11 *-------------------------------------------------------------------------
52 main(
int argc,
char *argv[])
54 static struct option long_options[] = {
72 /* process command-line options */
74 long_options, &optindex)) != -1)
85 /* getopt_long already emitted a complaint */
125 * Dump details for one relation.
137 /* Dump limit block, if any. */
139 printf(
"TS %u, DB %u, REL %u, FORK %s: limit %u\n",
143 /* If we haven't allocated a block buffer yet, do that now. */
147 /* Try to fill the block buffer. */
152 /* If we filled the block buffer completely, we must enlarge it. */
157 /* Double the size, being careful about overflow. */
163 /* Try to fill the newly-allocated space. */
169 /* Save the new size for later calls. */
173 /* If we don't need to produce any output, skip the rest of this. */
178 * Sort the returned block numbers. If the block reference table was using
179 * the bitmap representation for a given chunk, the block numbers in that
180 * chunk will already be sorted, but when the array-of-offsets
181 * representation is used, we can receive block numbers here out of order.
185 /* Dump block references. */
189 * Find the next range of blocks to print, but if --individual was
190 * specified, then consider each block a separate range.
202 /* Format this range of block numbers as a string. */
203 if (startblock == endblock)
204 printf(
"TS %u, DB %u, REL %u, FORK %s: block %u\n",
208 printf(
"TS %u, DB %u, REL %u, FORK %s: blocks %u..%u\n",
210 forkNames[forknum], startblock, endblock);
215 * Quicksort comparator for block numbers.
259 * Prints help page for the program
261 * progname: the name of the executed program, such as "pg_walsummary"
266 printf(
_(
"%s prints the contents of a WAL summary file.\n\n"),
progname);
270 printf(
_(
" -i, --individual list block numbers individually, not as ranges\n"));
271 printf(
_(
" -q, --quiet don't print anything, just parse the files\n"));
272 printf(
_(
" -V, --version output version information, then exit\n"));
273 printf(
_(
" -?, --help show this help, then exit\n"));
275 printf(
_(
"\nReport bugs to <%s>.\n"), PACKAGE_BUGREPORT);
276 printf(
_(
"%s home page: <%s>\n"), PACKAGE_NAME, PACKAGE_URL);
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)
#define InvalidBlockNumber
#define PG_TEXTDOMAIN(domain)
#define pg_attribute_printf(f, a)
void set_pglocale_pgservice(const char *argv0, const char *app)
#define repalloc_array(pointer, type, count)
#define palloc_array(type, count)
int getopt_long(int argc, char *const argv[], const char *optstring, const struct option *longopts, int *longindex)
static int pg_cmp_u32(uint32 a, uint32 b)
void pg_logging_init(const char *argv0)
void pg_log_generic_v(enum pg_log_level level, enum pg_log_part part, const char *pg_restrict fmt, va_list ap)
#define pg_log_error(...)
#define pg_log_error_hint(...)
void handle_help_version_opts(int argc, char *argv[], const char *fixed_progname, help_handler hlp)
static void walsummary_error_callback(void *callback_arg, char *fmt,...) pg_attribute_printf(2
struct ws_file_info ws_file_info
static void help(const char *progname)
static void dump_one_relation(ws_options *opt, RelFileLocator *rlocator, ForkNumber forknum, BlockNumber limit_block, BlockRefTableReader *reader)
static int compare_block_numbers(const void *a, const void *b)
static void int main(int argc, char *argv[])
static int walsummary_read_callback(void *callback_arg, void *data, int length)
static BlockNumber * block_buffer
static unsigned block_buffer_size
struct ws_options ws_options
const char * get_progname(const char *argv0)
#define qsort(a, b, c, d)
const char *const forkNames[]