forked from snaga/xlogdump
-
Notifications
You must be signed in to change notification settings - Fork 0
/
xlogdump_rmgr.c
1371 lines (1187 loc) · 35.2 KB
/
xlogdump_rmgr.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
* xlogdump_rmgr.c
*
* a collection of functions which print xlog records generated
* by each resource manager.
*/
#include "xlogdump_rmgr.h"
#include "xlogdump.h"
#include <time.h>
#include "postgres.h"
#include "access/clog.h"
#include "access/gist_private.h"
#include "access/htup.h"
#include "access/multixact.h"
#include "access/nbtree.h"
#include "access/xact.h"
#include "catalog/pg_control.h"
#include "commands/dbcommands.h"
#if PG_VERSION_NUM >=90000
#include "utils/relmapper.h"
#endif
#include "xlogdump_oid2name.h"
#include "xlogdump_statement.h"
/*
* See access/tramsam/rmgr.c for more details.
*/
const char * const RM_names[RM_MAX_ID+1] = {
"XLOG", /* 0 */
"Transaction", /* 1 */
"Storage", /* 2 */
"CLOG", /* 3 */
"Database", /* 4 */
"Tablespace", /* 5 */
"MultiXact", /* 6 */
#if PG_VERSION_NUM >=90000
"RelMap", /* 7 */
"Standby", /* 8 */
#else
"Reserved 7", /* 7 */
"Reserved 8", /* 8 */
#endif
"Heap2", /* 9 */
"Heap", /* 10 */
"Btree", /* 11 */
"Hash", /* 12 */
"Gin", /* 13 */
"Gist", /* 14 */
"Sequence", /* 15 */
#if PG_VERSION_NUM >=90200
"SPGist" /* 16 */
#endif
};
/* copy from utils/timestamp.h */
#define SECS_PER_DAY 86400
#ifdef HAVE_INT64_TIMESTAMP
#define USECS_PER_DAY INT64CONST(86400000000)
#endif
/* copy from utils/datetime.h */
#define UNIX_EPOCH_JDATE 2440588 /* == date2j(1970, 1, 1) */
#define POSTGRES_EPOCH_JDATE 2451545 /* == date2j(2000, 1, 1) */
static bool dump_enabled = true;
struct xlogdump_rmgr_stats_t {
int xlog_checkpoint;
int xlog_switch;
int xlog_backup_end;
int xact_commit;
int xact_abort;
int heap_insert;
int heap_delete;
int heap_update;
int heap_hot_update;
int heap_move;
int heap_newpage;
int heap_lock;
int heap_inplace;
int heap_init_page;
};
static struct xlogdump_rmgr_stats_t rmgr_stats;
static pg_time_t _timestamptz_to_time_t(TimestampTz);
static char *str_time(time_t);
static bool dump_xlog_btree_insert_meta(XLogRecord *);
/* GIST stuffs */
static void decodePageUpdateRecord(PageUpdateRecord *, XLogRecord *);
static void decodePageSplitRecord(PageSplitRecord *, XLogRecord *);
void
print_xlog_rmgr_stats(int rmid)
{
switch (rmid)
{
case RM_XLOG_ID:
printf(" checkpoint: %d, switch: %d, backup end: %d\n",
rmgr_stats.xlog_checkpoint,
rmgr_stats.xlog_switch,
rmgr_stats.xlog_backup_end);
break;
case RM_XACT_ID:
printf(" commit: %d, abort: %d\n",
rmgr_stats.xact_commit,
rmgr_stats.xact_abort);
break;
case RM_HEAP_ID:
printf(" ins: %d, upd/hot_upd: %d/%d, del: %d\n",
rmgr_stats.heap_insert,
rmgr_stats.heap_update,
rmgr_stats.heap_hot_update,
rmgr_stats.heap_delete);
break;
}
}
/* copy from utils/adt/timestamp.c, and renamed because of the name conflict. */
static pg_time_t
_timestamptz_to_time_t(TimestampTz t)
{
pg_time_t result;
#ifdef HAVE_INT64_TIMESTAMP
result = (pg_time_t) (t / USECS_PER_SEC +
((POSTGRES_EPOCH_JDATE - UNIX_EPOCH_JDATE) * SECS_PER_DAY));
#else
result = (pg_time_t) (t +
((POSTGRES_EPOCH_JDATE - UNIX_EPOCH_JDATE) * SECS_PER_DAY));
#endif
return result;
}
static char *
str_time(time_t tnow)
{
static char buf[32];
strftime(buf, sizeof(buf),
"%Y-%m-%d %H:%M:%S %Z",
localtime(&tnow));
return buf;
}
void
enable_rmgr_dump(bool flag)
{
dump_enabled = flag;
}
/*
* a common part called by each `print_rmgr_*()' to print a xlog record header
* with the detail.
*/
static void
print_rmgr_record(XLogRecPtr cur, XLogRecord *rec, const char *detail)
{
if (!dump_enabled)
return;
PRINT_XLOGRECORD_HEADER(cur, rec);
printf("%s\n", detail);
}
void
print_rmgr_xlog(XLogRecPtr cur, XLogRecord *record, uint8 info, bool hideTimestamps)
{
char buf[1024];
switch (info)
{
case XLOG_CHECKPOINT_SHUTDOWN:
case XLOG_CHECKPOINT_ONLINE:
{
CheckPoint *checkpoint = (CheckPoint*) XLogRecGetData(record);
if(!hideTimestamps)
snprintf(buf, sizeof(buf), "checkpoint: redo %u/%08X; tli %u; nextxid %u;"
" nextoid %u; nextmulti %u; nextoffset %u; %s at %s",
checkpoint->redo.xlogid, checkpoint->redo.xrecoff,
checkpoint->ThisTimeLineID, checkpoint->nextXid,
checkpoint->nextOid,
checkpoint->nextMulti,
checkpoint->nextMultiOffset,
(info == XLOG_CHECKPOINT_SHUTDOWN) ?
"shutdown" : "online",
str_time(checkpoint->time));
else
snprintf(buf, sizeof(buf), "checkpoint: redo %u/%08X; tli %u; nextxid %u;"
" nextoid %u; nextmulti %u; nextoffset %u; %s",
checkpoint->redo.xlogid, checkpoint->redo.xrecoff,
checkpoint->ThisTimeLineID, checkpoint->nextXid,
checkpoint->nextOid,
checkpoint->nextMulti,
checkpoint->nextMultiOffset,
(info == XLOG_CHECKPOINT_SHUTDOWN) ?
"shutdown" : "online");
rmgr_stats.xlog_checkpoint++;
break;
}
#if PG_VERSION_NUM >= 80300
case XLOG_NOOP:
{
snprintf(buf, sizeof(buf), "noop:");
break;
}
#endif
case XLOG_NEXTOID:
{
Oid nextOid;
memcpy(&nextOid, XLogRecGetData(record), sizeof(Oid));
snprintf(buf, sizeof(buf), "nextOid: %u", nextOid);
break;
}
case XLOG_SWITCH:
{
snprintf(buf, sizeof(buf), "switch:");
rmgr_stats.xlog_switch++;
break;
}
#if PG_VERSION_NUM >= 90000
case XLOG_BACKUP_END:
{
XLogRecPtr startpoint;
memcpy(&startpoint, XLogRecGetData(record), sizeof(XLogRecPtr));
snprintf(buf, sizeof(buf), "backup end: started at %X/%X.",
startpoint.xlogid, startpoint.xrecoff);
rmgr_stats.xlog_backup_end++;
break;
}
case XLOG_PARAMETER_CHANGE:
{
snprintf(buf, sizeof(buf), "parameter change:");
break;
}
#endif
#if PG_VERSION_NUM >= 90100
case XLOG_RESTORE_POINT:
{
snprintf(buf, sizeof(buf), "restore point:");
break;
}
#endif
#if PG_VERSION_NUM >= 90200
case XLOG_FPW_CHANGE:
{
snprintf(buf, sizeof(buf), "full_page_write changed:");
break;
}
#endif
default:
snprintf(buf, sizeof(buf), "unknown XLOG operation - %d.", info);
break;
}
print_rmgr_record(cur, record, buf);
}
void
print_rmgr_xact(XLogRecPtr cur, XLogRecord *record, uint8 info, bool hideTimestamps)
{
char buf[1024];
memset(buf, 0, sizeof(buf));
switch (info)
{
case XLOG_XACT_COMMIT:
{
xl_xact_commit xlrec;
memcpy(&xlrec, XLogRecGetData(record), sizeof(xlrec));
#if PG_VERSION_NUM >= 90000
snprintf(buf, sizeof(buf), "d/s:%d/%d commit at %s",
xlrec.dbId, xlrec.tsId,
str_time(_timestamptz_to_time_t(xlrec.xact_time)));
#elif PG_VERSION_NUM >= 80300
snprintf(buf, sizeof(buf), "commit at %s",
str_time(_timestamptz_to_time_t(xlrec.xact_time)));
#else
snprintf(buf, sizeof(buf), "commit at %s",
str_time(_timestamptz_to_time_t(xlrec.xtime)));
#endif
}
rmgr_stats.xact_commit++;
break;
case XLOG_XACT_PREPARE:
snprintf(buf, sizeof(buf), "prepare");
break;
case XLOG_XACT_ABORT:
{
xl_xact_abort xlrec;
memcpy(&xlrec, XLogRecGetData(record), sizeof(xlrec));
snprintf(buf, sizeof(buf), "abort at %s",
#if PG_VERSION_NUM >= 80300
str_time(_timestamptz_to_time_t(xlrec.xact_time)));
#else
str_time(_timestamptz_to_time_t(xlrec.xtime)));
#endif
}
rmgr_stats.xact_abort++;
break;
case XLOG_XACT_COMMIT_PREPARED:
{
xl_xact_commit_prepared xlrec;
memcpy(&xlrec, XLogRecGetData(record), sizeof(xlrec));
#if PG_VERSION_NUM >= 90000
snprintf(buf, sizeof(buf), "commit prepared xid:%d, dbid:%d, spcid:%d, commit at %s",
xlrec.xid,
xlrec.crec.dbId, xlrec.crec.tsId,
str_time(_timestamptz_to_time_t(xlrec.crec.xact_time)));
#elif PG_VERSION_NUM >= 80300
snprintf(buf, sizeof(buf), "commit prepared xid:%d, commit at %s",
xlrec.xid,
str_time(_timestamptz_to_time_t(xlrec.crec.xact_time)));
#else
snprintf(buf, sizeof(buf), "commit prepared xid:%d, commit at %s",
xlrec.xid,
str_time(_timestamptz_to_time_t(xlrec.crec.xtime)));
#endif
}
break;
case XLOG_XACT_ABORT_PREPARED:
{
xl_xact_commit_prepared xlrec;
memcpy(&xlrec, XLogRecGetData(record), sizeof(xlrec));
#if PG_VERSION_NUM >= 90000
snprintf(buf, sizeof(buf), "abort prepared xid:%d, dbid:%d, spcid:%d, commit at %s",
xlrec.xid,
xlrec.crec.dbId, xlrec.crec.tsId,
str_time(_timestamptz_to_time_t(xlrec.crec.xact_time)));
#elif PG_VERSION_NUM >= 80300
snprintf(buf, sizeof(buf), "abort prepared xid:%d, commit at %s",
xlrec.xid,
str_time(_timestamptz_to_time_t(xlrec.crec.xact_time)));
#else
snprintf(buf, sizeof(buf), "abort prepared xid:%d, commit at %s",
xlrec.xid,
str_time(_timestamptz_to_time_t(xlrec.crec.xtime)));
#endif
}
break;
#if PG_VERSION_NUM >= 90000
case XLOG_XACT_ASSIGNMENT:
{
xl_xact_assignment xlrec;
memcpy(&xlrec, XLogRecGetData(record), sizeof(xlrec));
snprintf(buf, sizeof(buf), "assignment xtop:%d, nsubxacts:%d",
xlrec.xtop,
xlrec.nsubxacts);
}
break;
#endif
#if PG_VERSION_NUM >= 90200
case XLOG_XACT_COMMIT_COMPACT:
{
xl_xact_commit_compact xlrec;
memcpy(&xlrec, XLogRecGetData(record), sizeof(xlrec));
#ifdef HAVE_INT64_TIMESTAMP
snprintf(buf, sizeof(buf), "commit_compact xact_time:" INT64_FORMAT ", nsubxacts:%d",
xlrec.xact_time,
xlrec.nsubxacts);
#else
snprintf(buf, sizeof(buf), "commit_compact xact_time:%f, nsubxacts:%d",
xlrec.xact_time,
xlrec.nsubxacts);
#endif
}
break;
#endif
default:
snprintf(buf, sizeof(buf), "unknown XACT operation - %d.", info);
break;
}
print_rmgr_record(cur, record, buf);
}
void
print_rmgr_smgr(XLogRecPtr cur, XLogRecord *record, uint8 info)
{
char spaceName[NAMEDATALEN];
char dbName[NAMEDATALEN];
char relName[NAMEDATALEN];
char buf[1024];
switch (info)
{
case XLOG_SMGR_CREATE:
{
xl_smgr_create xlrec;
memcpy(&xlrec, XLogRecGetData(record), sizeof(xlrec));
getSpaceName(xlrec.rnode.spcNode, spaceName, sizeof(spaceName));
getDbName(xlrec.rnode.dbNode, dbName, sizeof(dbName));
getRelName(xlrec.rnode.relNode, relName, sizeof(relName));
snprintf(buf, sizeof(buf), "create rel: s/d/r:%s/%s/%s",
spaceName, dbName, relName);
}
break;
case XLOG_SMGR_TRUNCATE:
{
xl_smgr_truncate xlrec;
memcpy(&xlrec, XLogRecGetData(record), sizeof(xlrec));
getSpaceName(xlrec.rnode.spcNode, spaceName, sizeof(spaceName));
getDbName(xlrec.rnode.dbNode, dbName, sizeof(dbName));
getRelName(xlrec.rnode.relNode, relName, sizeof(relName));
snprintf(buf, sizeof(buf), "truncate rel: s/d/r:%s/%s/%s at block %u",
spaceName, dbName, relName, xlrec.blkno);
}
break;
default:
snprintf(buf, sizeof(buf), "unknown SMGR operation - %d.", info);
break;
}
print_rmgr_record(cur, record, buf);
}
void
print_rmgr_clog(XLogRecPtr cur, XLogRecord *record, uint8 info)
{
char buf[1024];
int pageno;
memcpy(&pageno, XLogRecGetData(record), sizeof(int));
switch (info)
{
case CLOG_ZEROPAGE:
snprintf(buf, sizeof(buf), "zero clog page 0x%04x", pageno);
break;
case CLOG_TRUNCATE:
snprintf(buf, sizeof(buf), "truncate clog page 0x%04x", pageno);
break;
default:
snprintf(buf, sizeof(buf), "unknown CLOG operation - %d.", info);
break;
}
print_rmgr_record(cur, record, buf);
}
void
print_rmgr_dbase(XLogRecPtr cur, XLogRecord *record, uint8 info)
{
char buf[1024];
/* FIXME: need to be implemented. */
switch (info)
{
case XLOG_DBASE_CREATE:
{
xl_dbase_create_rec *xlrec = (xl_dbase_create_rec *)XLogRecGetData(record);
snprintf(buf, sizeof(buf), "dbase_create: db_id:%d, tablespace_id:%d, src_db_id:%d, src_tablespace_id:%d",
xlrec->db_id,
xlrec->tablespace_id,
xlrec->src_db_id,
xlrec->src_tablespace_id);
}
break;
case XLOG_DBASE_DROP:
{
xl_dbase_drop_rec *xlrec = (xl_dbase_drop_rec *)XLogRecGetData(record);
snprintf(buf, sizeof(buf), "dbase_drop: db_id:%d, tablespace_id:%d",
xlrec->db_id,
xlrec->tablespace_id);
}
break;
default:
snprintf(buf, sizeof(buf), "unknown DBASE operation - %d.", info);
break;
}
print_rmgr_record(cur, record, buf);
}
void
print_rmgr_tblspc(XLogRecPtr cur, XLogRecord *record, uint8 info)
{
/* FIXME: need to be implemented. */
print_rmgr_record(cur, record, "tblspc");
}
void
print_rmgr_multixact(XLogRecPtr cur, XLogRecord *record, uint8 info)
{
char buf[1024];
switch (info & XLOG_HEAP_OPMASK)
{
case XLOG_MULTIXACT_ZERO_OFF_PAGE:
{
int pageno;
memcpy(&pageno, XLogRecGetData(record), sizeof(int));
snprintf(buf, sizeof(buf), "zero offset page 0x%04x", pageno);
break;
}
case XLOG_MULTIXACT_ZERO_MEM_PAGE:
{
int pageno;
memcpy(&pageno, XLogRecGetData(record), sizeof(int));
snprintf(buf, sizeof(buf), "zero members page 0x%04x", pageno);
break;
}
case XLOG_MULTIXACT_CREATE_ID:
{
xl_multixact_create xlrec;
memcpy(&xlrec, XLogRecGetData(record), sizeof(xlrec));
snprintf(buf, sizeof(buf), "multixact create: %u off %u nxids %u",
xlrec.mid,
xlrec.moff,
xlrec.nxids);
break;
}
default:
snprintf(buf, sizeof(buf), "unknown MULTIXACT operation - %d.", info & XLOG_HEAP_OPMASK);
break;
}
print_rmgr_record(cur, record, buf);
}
#if PG_VERSION_NUM >= 90000
void
print_rmgr_relmap(XLogRecPtr cur, XLogRecord *record, uint8 info)
{
char buf[1024];
switch (info)
{
case XLOG_RELMAP_UPDATE:
{
xl_relmap_update *xlrec = (xl_relmap_update *)XLogRecGetData(record);
snprintf(buf, sizeof(buf), "update: dbid:%d, tsid:%d, nbytes:%d",
xlrec->dbid,
xlrec->tsid,
xlrec->nbytes);
break;
}
default:
snprintf(buf, sizeof(buf), "unknown RELMAP operation - %d.", info);
break;
}
print_rmgr_record(cur, record, buf);
}
void
print_rmgr_standby(XLogRecPtr cur, XLogRecord *record, uint8 info)
{
/* FIXME: need to be implemented. */
print_rmgr_record(cur, record, "standby");
}
#endif
void
print_rmgr_heap2(XLogRecPtr cur, XLogRecord *record, uint8 info)
{
char spaceName[NAMEDATALEN];
char dbName[NAMEDATALEN];
char relName[NAMEDATALEN];
char buf[1024];
switch (info)
{
case XLOG_HEAP2_FREEZE:
{
xl_heap_freeze xlrec;
memcpy(&xlrec, XLogRecGetData(record), sizeof(xlrec));
snprintf(buf, sizeof(buf), "freeze: ts %d db %d rel %d block %d cutoff_xid %d",
xlrec.node.spcNode,
xlrec.node.dbNode,
xlrec.node.relNode,
xlrec.block, xlrec.cutoff_xid
);
}
break;
#if PG_VERSION_NUM >= 80300
case XLOG_HEAP2_CLEAN:
#if PG_VERSION_NUM < 90000
case XLOG_HEAP2_CLEAN_MOVE:
#endif
{
xl_heap_clean xlrec;
int total_off;
int nunused = 0;
memcpy(&xlrec, XLogRecGetData(record), sizeof(xlrec));
getSpaceName(xlrec.node.spcNode, spaceName, sizeof(spaceName));
getDbName(xlrec.node.dbNode, dbName, sizeof(dbName));
getRelName(xlrec.node.relNode, relName, sizeof(relName));
total_off = (record->xl_len - SizeOfHeapClean) / sizeof(OffsetNumber);
if (total_off > xlrec.nredirected + xlrec.ndead)
nunused = total_off - (xlrec.nredirected + xlrec.ndead);
#if PG_VERSION_NUM >= 90000
snprintf(buf, sizeof(buf), "clean%s: s/d/r:%s/%s/%s block:%u redirected/dead/unused:%d/%d/%d removed xid:%d",
"",
#else
snprintf(buf, sizeof(buf), "clean%s: s/d/r:%s/%s/%s block:%u redirected/dead/unused:%d/%d/%d",
info == XLOG_HEAP2_CLEAN_MOVE ? "_move" : "",
#endif
spaceName, dbName, relName,
xlrec.block,
xlrec.nredirected, xlrec.ndead, nunused
#if PG_VERSION_NUM >= 90000
, xlrec.latestRemovedXid
#endif
);
break;
}
break;
#if PG_VERSION_NUM >= 90000
case XLOG_HEAP2_CLEANUP_INFO:
{
xl_heap_cleanup_info xlrec;
memcpy(&xlrec, XLogRecGetData(record), sizeof(xlrec));
getSpaceName(xlrec.node.spcNode, spaceName, sizeof(spaceName));
getDbName(xlrec.node.dbNode, dbName, sizeof(dbName));
getRelName(xlrec.node.relNode, relName, sizeof(relName));
snprintf(buf, sizeof(buf), "cleanup_info: s/d/r:%s/%s/%s removed xid:%d",
spaceName, dbName, relName,
xlrec.latestRemovedXid);
}
break;
#endif
#if PG_VERSION_NUM >= 90200
case XLOG_HEAP2_VISIBLE:
{
snprintf(buf, sizeof(buf), "heap2_visible:");
}
break;
case XLOG_HEAP2_MULTI_INSERT:
{
snprintf(buf, sizeof(buf), "heap2_multi_insert:");
}
break;
#endif
#endif
default:
snprintf(buf, sizeof(buf), "unknown HEAP2 operation - %d.", info);
break;
}
print_rmgr_record(cur, record, buf);
}
void
print_rmgr_heap(XLogRecPtr cur, XLogRecord *record, uint8 info, bool statements)
{
char spaceName[NAMEDATALEN];
char dbName[NAMEDATALEN];
char relName[NAMEDATALEN];
char buf[1024];
switch (info & XLOG_HEAP_OPMASK)
{
case XLOG_HEAP_INSERT:
{
xl_heap_insert xlrec;
memcpy(&xlrec, XLogRecGetData(record), sizeof(xlrec));
getSpaceName(xlrec.target.node.spcNode, spaceName, sizeof(spaceName));
getDbName(xlrec.target.node.dbNode, dbName, sizeof(dbName));
getRelName(xlrec.target.node.relNode, relName, sizeof(relName));
if(statements)
printInsert((xl_heap_insert *) XLogRecGetData(record), record->xl_len - SizeOfHeapInsert - SizeOfHeapHeader, relName);
snprintf(buf, sizeof(buf), "insert%s: s/d/r:%s/%s/%s blk/off:%u/%u",
(info & XLOG_HEAP_INIT_PAGE) ? "(init)" : "",
spaceName, dbName, relName,
ItemPointerGetBlockNumber(&xlrec.target.tid),
ItemPointerGetOffsetNumber(&xlrec.target.tid));
/* If backup block doesn't exist, dump rmgr data. */
if (!(record->xl_info & XLR_BKP_BLOCK_MASK))
{
char buf2[1024];
xl_heap_header *header = (xl_heap_header *)
(XLogRecGetData(record) + SizeOfHeapInsert);
#if PG_VERSION_NUM >= 80300
snprintf(buf2, sizeof(buf2), " header: t_infomask2 %d t_infomask %d t_hoff %d",
header->t_infomask2,
header->t_infomask,
header->t_hoff);
#else
snprintf(buf2, sizeof(buf2), " header: t_infomask %d t_hoff %d",
header->t_infomask,
header->t_hoff);
#endif
strlcat(buf, buf2, sizeof(buf));
}
else
strlcat(buf, " header: none", sizeof(buf));
rmgr_stats.heap_insert++;
break;
}
case XLOG_HEAP_DELETE:
{
xl_heap_delete xlrec;
memcpy(&xlrec, XLogRecGetData(record), sizeof(xlrec));
getSpaceName(xlrec.target.node.spcNode, spaceName, sizeof(spaceName));
getDbName(xlrec.target.node.dbNode, dbName, sizeof(dbName));
getRelName(xlrec.target.node.relNode, relName, sizeof(relName));
if(statements)
printf("DELETE FROM %s WHERE ...", relName);
snprintf(buf, sizeof(buf), "delete%s: s/d/r:%s/%s/%s block %u off %u",
(info & XLOG_HEAP_INIT_PAGE) ? "(init)" : "",
spaceName, dbName, relName,
ItemPointerGetBlockNumber(&xlrec.target.tid),
ItemPointerGetOffsetNumber(&xlrec.target.tid));
rmgr_stats.heap_delete++;
break;
}
case XLOG_HEAP_UPDATE:
#if PG_VERSION_NUM >= 80300
case XLOG_HEAP_HOT_UPDATE:
#endif
{
xl_heap_update xlrec;
memcpy(&xlrec, XLogRecGetData(record), sizeof(xlrec));
getSpaceName(xlrec.target.node.spcNode, spaceName, sizeof(spaceName));
getDbName(xlrec.target.node.dbNode, dbName, sizeof(dbName));
getRelName(xlrec.target.node.relNode, relName, sizeof(relName));
if(statements)
printUpdate((xl_heap_update *) XLogRecGetData(record), record->xl_len - SizeOfHeapUpdate - SizeOfHeapHeader, relName);
snprintf(buf, sizeof(buf), "%supdate%s: s/d/r:%s/%s/%s block %u off %u to block %u off %u",
#if PG_VERSION_NUM >= 80300
(info & XLOG_HEAP_HOT_UPDATE) ? "hot_" : "",
#else
"",
#endif
(info & XLOG_HEAP_INIT_PAGE) ? "(init)" : "",
spaceName, dbName, relName,
ItemPointerGetBlockNumber(&xlrec.target.tid),
ItemPointerGetOffsetNumber(&xlrec.target.tid),
ItemPointerGetBlockNumber(&xlrec.newtid),
ItemPointerGetOffsetNumber(&xlrec.newtid));
if ((info & XLOG_HEAP_OPMASK) == XLOG_HEAP_UPDATE)
rmgr_stats.heap_update++;
else
rmgr_stats.heap_hot_update++;
break;
}
#if PG_VERSION_NUM < 90000
case XLOG_HEAP_MOVE:
{
xl_heap_update xlrec;
memcpy(&xlrec, XLogRecGetData(record), sizeof(xlrec));
getSpaceName(xlrec.target.node.spcNode, spaceName, sizeof(spaceName));
getDbName(xlrec.target.node.dbNode, dbName, sizeof(dbName));
getRelName(xlrec.target.node.relNode, relName, sizeof(relName));
snprintf(buf, sizeof(buf), "move%s: s/d/r:%s/%s/%s block %u off %u to block %u off %u",
(info & XLOG_HEAP_INIT_PAGE) ? "(init)" : "",
spaceName, dbName, relName,
ItemPointerGetBlockNumber(&xlrec.target.tid),
ItemPointerGetOffsetNumber(&xlrec.target.tid),
ItemPointerGetBlockNumber(&xlrec.newtid),
ItemPointerGetOffsetNumber(&xlrec.newtid));
rmgr_stats.heap_move++;
break;
}
#endif
case XLOG_HEAP_NEWPAGE:
{
xl_heap_newpage xlrec;
memcpy(&xlrec, XLogRecGetData(record), sizeof(xlrec));
getSpaceName(xlrec.node.spcNode, spaceName, sizeof(spaceName));
getDbName(xlrec.node.dbNode, dbName, sizeof(dbName));
getRelName(xlrec.node.relNode, relName, sizeof(relName));
snprintf(buf, sizeof(buf), "newpage: s/d/r:%s/%s/%s block %u",
spaceName, dbName, relName,
xlrec.blkno);
rmgr_stats.heap_newpage++;
break;
}
case XLOG_HEAP_LOCK:
{
xl_heap_lock xlrec;
memcpy(&xlrec, XLogRecGetData(record), sizeof(xlrec));
getSpaceName(xlrec.target.node.spcNode, spaceName, sizeof(spaceName));
getDbName(xlrec.target.node.dbNode, dbName, sizeof(dbName));
getRelName(xlrec.target.node.relNode, relName, sizeof(relName));
snprintf(buf, sizeof(buf), "lock %s: s/d/r:%s/%s/%s block %u off %u",
xlrec.shared_lock ? "shared" : "exclusive",
spaceName, dbName, relName,
ItemPointerGetBlockNumber(&xlrec.target.tid),
ItemPointerGetOffsetNumber(&xlrec.target.tid));
rmgr_stats.heap_lock++;
break;
}
case XLOG_HEAP_INPLACE:
{
xl_heap_inplace xlrec;
memcpy(&xlrec, XLogRecGetData(record), sizeof(xlrec));
getSpaceName(xlrec.target.node.spcNode, spaceName, sizeof(spaceName));
getDbName(xlrec.target.node.dbNode, dbName, sizeof(dbName));
getRelName(xlrec.target.node.relNode, relName, sizeof(relName));
snprintf(buf, sizeof(buf), "inplace: s/d/r:%s/%s/%s block %u off %u",
spaceName, dbName, relName,
ItemPointerGetBlockNumber(&xlrec.target.tid),
ItemPointerGetOffsetNumber(&xlrec.target.tid));
rmgr_stats.heap_inplace++;
break;
}
case XLOG_HEAP_INIT_PAGE:
{
snprintf(buf, sizeof(buf), "init page");
rmgr_stats.heap_init_page++;
break;
}
default:
snprintf(buf, sizeof(buf), "unknown HEAP operation - %d.", (info & XLOG_HEAP_OPMASK));
break;
}
print_rmgr_record(cur, record, buf);
}
static bool
dump_xlog_btree_insert_meta(XLogRecord *record)
{
char spaceName[NAMEDATALEN];
char dbName[NAMEDATALEN];
char relName[NAMEDATALEN];
xl_btree_insert *xlrec = (xl_btree_insert *) XLogRecGetData(record);
char *datapos;
int datalen;
xl_btree_metadata md;
BlockNumber downlink;
/* copied from btree_xlog_insert(nbtxlog.c:191) */
datapos = (char *) xlrec + SizeOfBtreeInsert;
datalen = record->xl_len - SizeOfBtreeInsert;
if ( getSpaceName(xlrec->target.node.spcNode, spaceName, sizeof(spaceName))==NULL ||
getDbName(xlrec->target.node.dbNode, dbName, sizeof(dbName))==NULL ||
getRelName(xlrec->target.node.relNode, relName, sizeof(relName))==NULL )
return false;
/* downlink */
memcpy(&downlink, datapos, sizeof(BlockNumber));
datapos += sizeof(BlockNumber);
datalen -= sizeof(BlockNumber);
/* xl_insert_meta */
memcpy(&md, datapos, sizeof(xl_btree_metadata));
datapos += sizeof(xl_btree_metadata);
datalen -= sizeof(xl_btree_metadata);
printf("insert_meta: index %s/%s/%s tid %u/%u downlink %u froot %u/%u\n",
spaceName, dbName, relName,
BlockIdGetBlockNumber(&xlrec->target.tid.ip_blkid),
xlrec->target.tid.ip_posid,
downlink,
md.fastroot, md.fastlevel
);
return true;
}
void
print_rmgr_btree(XLogRecPtr cur, XLogRecord *record, uint8 info)
{
char spaceName[NAMEDATALEN];
char dbName[NAMEDATALEN];
char relName[NAMEDATALEN];
char buf[1024];
switch (info)
{
case XLOG_BTREE_INSERT_LEAF:
{
xl_btree_insert xlrec;
memcpy(&xlrec, XLogRecGetData(record), sizeof(xlrec));
getSpaceName(xlrec.target.node.spcNode, spaceName, sizeof(spaceName));
getDbName(xlrec.target.node.dbNode, dbName, sizeof(dbName));
getRelName(xlrec.target.node.relNode, relName, sizeof(relName));
snprintf(buf, sizeof(buf), "insert_leaf: s/d/r:%s/%s/%s tid %u/%u",
spaceName, dbName, relName,
BlockIdGetBlockNumber(&xlrec.target.tid.ip_blkid),
xlrec.target.tid.ip_posid);
break;
}
case XLOG_BTREE_INSERT_UPPER:
{
xl_btree_insert xlrec;
memcpy(&xlrec, XLogRecGetData(record), sizeof(xlrec));
getSpaceName(xlrec.target.node.spcNode, spaceName, sizeof(spaceName));
getDbName(xlrec.target.node.dbNode, dbName, sizeof(dbName));
getRelName(xlrec.target.node.relNode, relName, sizeof(relName));
snprintf(buf, sizeof(buf), "insert_upper: s/d/r:%s/%s/%s tid %u/%u",
spaceName, dbName, relName,
BlockIdGetBlockNumber(&xlrec.target.tid.ip_blkid),
xlrec.target.tid.ip_posid);
break;
}
case XLOG_BTREE_INSERT_META:
dump_xlog_btree_insert_meta(record);
/* FIXME: need to check the result code. */
break;
case XLOG_BTREE_SPLIT_L:
case XLOG_BTREE_SPLIT_L_ROOT:
{
char *datapos = XLogRecGetData(record);
xl_btree_split xlrec;
OffsetNumber newitemoff;
char buf2[1024];
memcpy(&xlrec, XLogRecGetData(record), sizeof(xlrec));
datapos += SizeOfBtreeSplit;
#if PG_VERSION_NUM >= 80300
getSpaceName(xlrec.node.spcNode, spaceName, sizeof(spaceName));
getDbName(xlrec.node.dbNode, dbName, sizeof(dbName));
getRelName(xlrec.node.relNode, relName, sizeof(relName));
#endif