Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit0276ae4

Browse files
committed
Improve a few things in pg_walinspect
This improves a few things in pg_walinspect:- Return NULL rather than empty strings in pg_get_wal_records_info() forthe block references and the record description if there is noinformation provided by the fallback. This point has been raised byPeter Geoghegan.- Add a check on XLogRecHasAnyBlockRefs() for pg_get_wal_block_info(),to directly skip records that have no block references. This speeds upthe function a bit, depending on the number of records that have noblock references.Author: Bharath RupireddyReviewed-by: Kyotaro Horiguchi, Michael PaquierDiscussion:https://postgr.es/m/CALj2ACWL9RG8sGJHinggRNBTxgRWJTSxCkB+cE6=t3Phh=Ey+A@mail.gmail.com
1 parent850f4b4 commit0276ae4

File tree

1 file changed

+27
-15
lines changed

1 file changed

+27
-15
lines changed

‎contrib/pg_walinspect/pg_walinspect.c

Lines changed: 27 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -186,8 +186,6 @@ GetWALRecordInfo(XLogReaderState *record, Datum *values,
186186
RmgrDatadesc;
187187
uint32fpi_len=0;
188188
StringInfoDatarec_desc;
189-
StringInfoDatarec_blk_ref;
190-
uint32main_data_len;
191189
inti=0;
192190

193191
desc=GetRmgr(XLogRecGetRmid(record));
@@ -199,23 +197,33 @@ GetWALRecordInfo(XLogReaderState *record, Datum *values,
199197
initStringInfo(&rec_desc);
200198
desc.rm_desc(&rec_desc,record);
201199

202-
/* Block references. */
203-
initStringInfo(&rec_blk_ref);
204-
XLogRecGetBlockRefInfo(record, false, true,&rec_blk_ref,&fpi_len);
205-
206-
main_data_len=XLogRecGetDataLen(record);
207-
208200
values[i++]=LSNGetDatum(record->ReadRecPtr);
209201
values[i++]=LSNGetDatum(record->EndRecPtr);
210202
values[i++]=LSNGetDatum(XLogRecGetPrev(record));
211203
values[i++]=TransactionIdGetDatum(XLogRecGetXid(record));
212204
values[i++]=CStringGetTextDatum(desc.rm_name);
213205
values[i++]=CStringGetTextDatum(id);
214206
values[i++]=UInt32GetDatum(XLogRecGetTotalLen(record));
215-
values[i++]=UInt32GetDatum(main_data_len);
207+
values[i++]=UInt32GetDatum(XLogRecGetDataLen(record));
208+
216209
values[i++]=UInt32GetDatum(fpi_len);
217-
values[i++]=CStringGetTextDatum(rec_desc.data);
218-
values[i++]=CStringGetTextDatum(rec_blk_ref.data);
210+
211+
if (rec_desc.len>0)
212+
values[i++]=CStringGetTextDatum(rec_desc.data);
213+
else
214+
nulls[i++]= true;
215+
216+
/* Block references. */
217+
if (XLogRecHasAnyBlockRefs(record))
218+
{
219+
StringInfoDatarec_blk_ref;
220+
221+
initStringInfo(&rec_blk_ref);
222+
XLogRecGetBlockRefInfo(record, false, true,&rec_blk_ref,&fpi_len);
223+
values[i++]=CStringGetTextDatum(rec_blk_ref.data);
224+
}
225+
else
226+
nulls[i++]= true;
219227

220228
Assert(i==ncols);
221229
}
@@ -377,6 +385,11 @@ pg_get_wal_block_info(PG_FUNCTION_ARGS)
377385
while (ReadNextXLogRecord(xlogreader)&&
378386
xlogreader->EndRecPtr <=end_lsn)
379387
{
388+
CHECK_FOR_INTERRUPTS();
389+
390+
if (!XLogRecHasAnyBlockRefs(xlogreader))
391+
continue;
392+
380393
/* Use the tmp context so we can clean up after each tuple is done */
381394
old_cxt=MemoryContextSwitchTo(tmp_cxt);
382395

@@ -385,8 +398,6 @@ pg_get_wal_block_info(PG_FUNCTION_ARGS)
385398
/* clean up and switch back */
386399
MemoryContextSwitchTo(old_cxt);
387400
MemoryContextReset(tmp_cxt);
388-
389-
CHECK_FOR_INTERRUPTS();
390401
}
391402

392403
MemoryContextDelete(tmp_cxt);
@@ -483,8 +494,6 @@ GetWALRecordsInfo(FunctionCallInfo fcinfo, XLogRecPtr start_lsn,
483494
#definePG_GET_WAL_RECORDS_INFO_COLS 11
484495
XLogReaderState*xlogreader;
485496
ReturnSetInfo*rsinfo= (ReturnSetInfo*)fcinfo->resultinfo;
486-
Datumvalues[PG_GET_WAL_RECORDS_INFO_COLS]= {0};
487-
boolnulls[PG_GET_WAL_RECORDS_INFO_COLS]= {0};
488497
MemoryContextold_cxt;
489498
MemoryContexttmp_cxt;
490499

@@ -501,6 +510,9 @@ GetWALRecordsInfo(FunctionCallInfo fcinfo, XLogRecPtr start_lsn,
501510
while (ReadNextXLogRecord(xlogreader)&&
502511
xlogreader->EndRecPtr <=end_lsn)
503512
{
513+
Datumvalues[PG_GET_WAL_RECORDS_INFO_COLS]= {0};
514+
boolnulls[PG_GET_WAL_RECORDS_INFO_COLS]= {0};
515+
504516
/* Use the tmp context so we can clean up after each tuple is done */
505517
old_cxt=MemoryContextSwitchTo(tmp_cxt);
506518

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp