Skip to content

Commit 9d0760f

Browse files
pg_waldump improvements
1. add neon resource manager in waldump 2. print end lsn
1 parent bf87d3c commit 9d0760f

File tree

2 files changed

+175
-12
lines changed

2 files changed

+175
-12
lines changed

src/bin/pg_waldump/pg_waldump.c

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -629,19 +629,21 @@ XLogDumpDisplayRecord(XLogDumpConfig *config, XLogReaderState *record)
629629
XLogRecGetLen(record, &rec_len, &fpi_len);
630630

631631
if(private->input_filename)
632-
printf("rmgr: %-11s len (rec/tot): %6u/%6u, tx: %10u, offset: %X/%08X, prev %X/%08X, ",
633-
desc->rm_name,
634-
rec_len, XLogRecGetTotalLen(record),
635-
XLogRecGetXid(record),
636-
LSN_FORMAT_ARGS(record->ReadRecPtr),
637-
LSN_FORMAT_ARGS(xl_prev));
632+
printf("rmgr: %-11s len (rec/tot): %6u/%6u, tx: %10u, offset: %X/%08X, end: %X/%08X, prev %X/%08X, ",
633+
desc->rm_name,
634+
rec_len, XLogRecGetTotalLen(record),
635+
XLogRecGetXid(record),
636+
LSN_FORMAT_ARGS(record->ReadRecPtr),
637+
LSN_FORMAT_ARGS(record->EndRecPtr),
638+
LSN_FORMAT_ARGS(xl_prev));
638639
else
639-
printf("rmgr: %-11s len (rec/tot): %6u/%6u, tx: %10u, lsn: %X/%08X, prev %X/%08X, ",
640-
desc->rm_name,
641-
rec_len, XLogRecGetTotalLen(record),
642-
XLogRecGetXid(record),
643-
LSN_FORMAT_ARGS(record->ReadRecPtr),
644-
LSN_FORMAT_ARGS(xl_prev));
640+
printf("rmgr: %-11s len (rec/tot): %6u/%6u, tx: %10u, lsn: %X/%08X, end: %X/%08X, prev %X/%08X, ",
641+
desc->rm_name,
642+
rec_len, XLogRecGetTotalLen(record),
643+
XLogRecGetXid(record),
644+
LSN_FORMAT_ARGS(record->ReadRecPtr),
645+
LSN_FORMAT_ARGS(record->EndRecPtr),
646+
LSN_FORMAT_ARGS(xl_prev));
645647

646648

647649
id = desc->rm_identify(info);
@@ -1444,6 +1446,7 @@ main(int argc, char **argv)
14441446
}
14451447
xlogreader_state->force_record_reassemble = true;
14461448
}
1449+
14471450
if(single_file)
14481451
{
14491452
if(config.ignore_format_errors)
@@ -1546,12 +1549,14 @@ main(int argc, char **argv)
15461549
else
15471550
XLogDumpDisplayRecord(&config, xlogreader_state);
15481551
}
1552+
15491553
if (save_records_file)
15501554
{
15511555
write_pq_message(save_records_file, 'A', record->xl_tot_len + sizeof(XLogRecPtr));
15521556
write_pq_int64(save_records_file, xlogreader_state->ReadRecPtr);
15531557
fwrite(xlogreader_state->readRecordBuf, record->xl_tot_len, 1, save_records_file);
15541558
}
1559+
15551560
/* save full pages if requested */
15561561
if (config.save_fullpage_path != NULL)
15571562
XLogRecordSaveFPWs(xlogreader_state, config.save_fullpage_path);
@@ -1576,6 +1581,7 @@ main(int argc, char **argv)
15761581
}
15771582
fclose(save_records_file);
15781583
}
1584+
15791585
if (config.stats == true && !config.quiet)
15801586
XLogDumpDisplayStats(&config, &stats);
15811587

src/bin/pg_waldump/rmgrdesc.c

Lines changed: 157 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
#include "postgres.h"
1010

1111
#include "access/brin_xlog.h"
12+
#include "access/neon_xlog.h"
1213
#include "access/clog.h"
1314
#include "access/commit_ts.h"
1415
#include "access/generic_xlog.h"
@@ -19,6 +20,7 @@
1920
#include "access/multixact.h"
2021
#include "access/nbtxlog.h"
2122
#include "access/rmgr.h"
23+
#include "access/rmgrdesc_utils.h"
2224
#include "access/spgxlog.h"
2325
#include "access/xact.h"
2426
#include "access/xlog_internal.h"
@@ -45,6 +47,158 @@ static char CustomNumericNames[RM_N_CUSTOM_IDS][CUSTOM_NUMERIC_NAME_LEN] = {0};
4547
static RmgrDescData CustomRmgrDesc[RM_N_CUSTOM_IDS] = {0};
4648
static bool CustomRmgrDescInitialized = false;
4749

50+
/*
51+
* NOTE: "keyname" argument cannot have trailing spaces or punctuation
52+
* characters
53+
*/
54+
static void
55+
infobits_desc(StringInfo buf, uint8 infobits, const char *keyname)
56+
{
57+
appendStringInfo(buf, "%s: [", keyname);
58+
59+
Assert(buf->data[buf->len - 1] != ' ');
60+
61+
if (infobits & XLHL_XMAX_IS_MULTI)
62+
appendStringInfoString(buf, "IS_MULTI, ");
63+
if (infobits & XLHL_XMAX_LOCK_ONLY)
64+
appendStringInfoString(buf, "LOCK_ONLY, ");
65+
if (infobits & XLHL_XMAX_EXCL_LOCK)
66+
appendStringInfoString(buf, "EXCL_LOCK, ");
67+
if (infobits & XLHL_XMAX_KEYSHR_LOCK)
68+
appendStringInfoString(buf, "KEYSHR_LOCK, ");
69+
if (infobits & XLHL_KEYS_UPDATED)
70+
appendStringInfoString(buf, "KEYS_UPDATED, ");
71+
72+
if (buf->data[buf->len - 1] == ' ')
73+
{
74+
/* Truncate-away final unneeded ", " */
75+
Assert(buf->data[buf->len - 2] == ',');
76+
buf->len -= 2;
77+
buf->data[buf->len] = '\0';
78+
}
79+
80+
appendStringInfoString(buf, "]");
81+
}
82+
83+
static void
84+
neon_rm_desc(StringInfo buf, XLogReaderState *record)
85+
{
86+
char *rec = XLogRecGetData(record);
87+
uint8 info = XLogRecGetInfo(record) & ~XLR_INFO_MASK;
88+
89+
info &= XLOG_NEON_OPMASK;
90+
91+
if (info == XLOG_NEON_HEAP_INSERT)
92+
{
93+
xl_neon_heap_insert *xlrec = (xl_neon_heap_insert *) rec;
94+
95+
appendStringInfo(buf, "off: %u, flags: 0x%02X",
96+
xlrec->offnum,
97+
xlrec->flags);
98+
}
99+
else if (info == XLOG_NEON_HEAP_DELETE)
100+
{
101+
xl_neon_heap_delete *xlrec = (xl_neon_heap_delete *) rec;
102+
103+
appendStringInfo(buf, "xmax: %u, off: %u, ",
104+
xlrec->xmax, xlrec->offnum);
105+
infobits_desc(buf, xlrec->infobits_set, "infobits");
106+
appendStringInfo(buf, ", flags: 0x%02X", xlrec->flags);
107+
}
108+
else if (info == XLOG_NEON_HEAP_UPDATE)
109+
{
110+
xl_neon_heap_update *xlrec = (xl_neon_heap_update *) rec;
111+
112+
appendStringInfo(buf, "old_xmax: %u, old_off: %u, ",
113+
xlrec->old_xmax, xlrec->old_offnum);
114+
infobits_desc(buf, xlrec->old_infobits_set, "old_infobits");
115+
appendStringInfo(buf, ", flags: 0x%02X, new_xmax: %u, new_off: %u",
116+
xlrec->flags, xlrec->new_xmax, xlrec->new_offnum);
117+
}
118+
else if (info == XLOG_NEON_HEAP_HOT_UPDATE)
119+
{
120+
xl_neon_heap_update *xlrec = (xl_neon_heap_update *) rec;
121+
122+
appendStringInfo(buf, "old_xmax: %u, old_off: %u, ",
123+
xlrec->old_xmax, xlrec->old_offnum);
124+
infobits_desc(buf, xlrec->old_infobits_set, "old_infobits");
125+
appendStringInfo(buf, ", flags: 0x%02X, new_xmax: %u, new_off: %u",
126+
xlrec->flags, xlrec->new_xmax, xlrec->new_offnum);
127+
}
128+
else if (info == XLOG_NEON_HEAP_LOCK)
129+
{
130+
xl_neon_heap_lock *xlrec = (xl_neon_heap_lock *) rec;
131+
132+
appendStringInfo(buf, "xmax: %u, off: %u, ",
133+
xlrec->xmax, xlrec->offnum);
134+
infobits_desc(buf, xlrec->infobits_set, "infobits");
135+
appendStringInfo(buf, ", flags: 0x%02X", xlrec->flags);
136+
}
137+
else if (info == XLOG_NEON_HEAP_MULTI_INSERT)
138+
{
139+
xl_neon_heap_multi_insert *xlrec = (xl_neon_heap_multi_insert *) rec;
140+
bool isinit = (XLogRecGetInfo(record) & XLOG_NEON_INIT_PAGE) != 0;
141+
142+
appendStringInfo(buf, "ntuples: %d, flags: 0x%02X", xlrec->ntuples,
143+
xlrec->flags);
144+
145+
if (XLogRecHasBlockData(record, 0) && !isinit)
146+
{
147+
appendStringInfoString(buf, ", offsets:");
148+
array_desc(buf, xlrec->offsets, sizeof(OffsetNumber),
149+
xlrec->ntuples, &offset_elem_desc, NULL);
150+
}
151+
}
152+
}
153+
154+
static const char *
155+
neon_rm_identify(uint8 info)
156+
{
157+
const char *id = NULL;
158+
159+
switch (info & ~XLR_INFO_MASK)
160+
{
161+
case XLOG_NEON_HEAP_INSERT:
162+
id = "INSERT";
163+
break;
164+
case XLOG_NEON_HEAP_INSERT | XLOG_NEON_INIT_PAGE:
165+
id = "INSERT+INIT";
166+
break;
167+
case XLOG_NEON_HEAP_DELETE:
168+
id = "DELETE";
169+
break;
170+
case XLOG_NEON_HEAP_UPDATE:
171+
id = "UPDATE";
172+
break;
173+
case XLOG_NEON_HEAP_UPDATE | XLOG_NEON_INIT_PAGE:
174+
id = "UPDATE+INIT";
175+
break;
176+
case XLOG_NEON_HEAP_HOT_UPDATE:
177+
id = "HOT_UPDATE";
178+
break;
179+
case XLOG_NEON_HEAP_HOT_UPDATE | XLOG_HEAP_INIT_PAGE:
180+
id = "HOT_UPDATE+INIT";
181+
break;
182+
case XLOG_NEON_HEAP_LOCK:
183+
id = "LOCK";
184+
break;
185+
case XLOG_NEON_HEAP_MULTI_INSERT:
186+
id = "MULTI_INSERT";
187+
break;
188+
case XLOG_NEON_HEAP_MULTI_INSERT | XLOG_NEON_INIT_PAGE:
189+
id = "MULTI_INSERT+INIT";
190+
break;
191+
}
192+
193+
return id;
194+
}
195+
196+
const static RmgrDescData NeonRmgr = {
197+
.rm_name = "neon",
198+
.rm_desc = neon_rm_desc,
199+
.rm_identify = neon_rm_identify,
200+
};
201+
48202
/*
49203
* No information on custom resource managers; just print the ID.
50204
*/
@@ -80,6 +234,9 @@ initialize_custom_rmgrs(void)
80234
CustomRmgrDesc[i].rm_desc = default_desc;
81235
CustomRmgrDesc[i].rm_identify = default_identify;
82236
}
237+
238+
CustomRmgrDesc[RM_NEON_ID - RM_MIN_CUSTOM_ID] = NeonRmgr;
239+
83240
CustomRmgrDescInitialized = true;
84241
}
85242

0 commit comments

Comments
 (0)