LCOV - code coverage report
Current view: top level - src/backend/access/rmgrdesc - xlogdesc.c (source / functions) Hit Total Coverage
Test: PostgreSQL 15devel Lines: 40 85 47.1 %
Date: 2021-12-04 21:09:12 Functions: 2 2 100.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /*-------------------------------------------------------------------------
       2             :  *
       3             :  * xlogdesc.c
       4             :  *    rmgr descriptor routines for access/transam/xlog.c
       5             :  *
       6             :  * Portions Copyright (c) 1996-2021, PostgreSQL Global Development Group
       7             :  * Portions Copyright (c) 1994, Regents of the University of California
       8             :  *
       9             :  *
      10             :  * IDENTIFICATION
      11             :  *    src/backend/access/rmgrdesc/xlogdesc.c
      12             :  *
      13             :  *-------------------------------------------------------------------------
      14             :  */
      15             : #include "postgres.h"
      16             : 
      17             : #include "access/transam.h"
      18             : #include "access/xlog.h"
      19             : #include "access/xlog_internal.h"
      20             : #include "catalog/pg_control.h"
      21             : #include "utils/guc.h"
      22             : #include "utils/timestamp.h"
      23             : 
      24             : /*
      25             :  * GUC support
      26             :  */
      27             : const struct config_enum_entry wal_level_options[] = {
      28             :     {"minimal", WAL_LEVEL_MINIMAL, false},
      29             :     {"replica", WAL_LEVEL_REPLICA, false},
      30             :     {"archive", WAL_LEVEL_REPLICA, true}, /* deprecated */
      31             :     {"hot_standby", WAL_LEVEL_REPLICA, true}, /* deprecated */
      32             :     {"logical", WAL_LEVEL_LOGICAL, false},
      33             :     {NULL, 0, false}
      34             : };
      35             : 
      36             : void
      37           8 : xlog_desc(StringInfo buf, XLogReaderState *record)
      38             : {
      39           8 :     char       *rec = XLogRecGetData(record);
      40           8 :     uint8       info = XLogRecGetInfo(record) & ~XLR_INFO_MASK;
      41             : 
      42           8 :     if (info == XLOG_CHECKPOINT_SHUTDOWN ||
      43             :         info == XLOG_CHECKPOINT_ONLINE)
      44           0 :     {
      45           0 :         CheckPoint *checkpoint = (CheckPoint *) rec;
      46             : 
      47           0 :         appendStringInfo(buf, "redo %X/%X; "
      48             :                          "tli %u; prev tli %u; fpw %s; xid %u:%u; oid %u; multi %u; offset %u; "
      49             :                          "oldest xid %u in DB %u; oldest multi %u in DB %u; "
      50             :                          "oldest/newest commit timestamp xid: %u/%u; "
      51             :                          "oldest running xid %u; %s",
      52           0 :                          LSN_FORMAT_ARGS(checkpoint->redo),
      53             :                          checkpoint->ThisTimeLineID,
      54             :                          checkpoint->PrevTimeLineID,
      55           0 :                          checkpoint->fullPageWrites ? "true" : "false",
      56           0 :                          EpochFromFullTransactionId(checkpoint->nextXid),
      57           0 :                          XidFromFullTransactionId(checkpoint->nextXid),
      58             :                          checkpoint->nextOid,
      59             :                          checkpoint->nextMulti,
      60             :                          checkpoint->nextMultiOffset,
      61             :                          checkpoint->oldestXid,
      62             :                          checkpoint->oldestXidDB,
      63             :                          checkpoint->oldestMulti,
      64             :                          checkpoint->oldestMultiDB,
      65             :                          checkpoint->oldestCommitTsXid,
      66             :                          checkpoint->newestCommitTsXid,
      67             :                          checkpoint->oldestActiveXid,
      68             :                          (info == XLOG_CHECKPOINT_SHUTDOWN) ? "shutdown" : "online");
      69             :     }
      70           8 :     else if (info == XLOG_NEXTOID)
      71             :     {
      72             :         Oid         nextOid;
      73             : 
      74           0 :         memcpy(&nextOid, rec, sizeof(Oid));
      75           0 :         appendStringInfo(buf, "%u", nextOid);
      76             :     }
      77           8 :     else if (info == XLOG_RESTORE_POINT)
      78             :     {
      79           0 :         xl_restore_point *xlrec = (xl_restore_point *) rec;
      80             : 
      81           0 :         appendStringInfoString(buf, xlrec->rp_name);
      82             :     }
      83           8 :     else if (info == XLOG_FPI || info == XLOG_FPI_FOR_HINT)
      84             :     {
      85             :         /* no further information to print */
      86             :     }
      87           8 :     else if (info == XLOG_BACKUP_END)
      88             :     {
      89             :         XLogRecPtr  startpoint;
      90             : 
      91           2 :         memcpy(&startpoint, rec, sizeof(XLogRecPtr));
      92           2 :         appendStringInfo(buf, "%X/%X", LSN_FORMAT_ARGS(startpoint));
      93             :     }
      94           6 :     else if (info == XLOG_PARAMETER_CHANGE)
      95             :     {
      96             :         xl_parameter_change xlrec;
      97             :         const char *wal_level_str;
      98             :         const struct config_enum_entry *entry;
      99             : 
     100           4 :         memcpy(&xlrec, rec, sizeof(xl_parameter_change));
     101             : 
     102             :         /* Find a string representation for wal_level */
     103           4 :         wal_level_str = "?";
     104           4 :         for (entry = wal_level_options; entry->name; entry++)
     105             :         {
     106           4 :             if (entry->val == xlrec.wal_level)
     107             :             {
     108           4 :                 wal_level_str = entry->name;
     109           4 :                 break;
     110             :             }
     111             :         }
     112             : 
     113           8 :         appendStringInfo(buf, "max_connections=%d max_worker_processes=%d "
     114             :                          "max_wal_senders=%d max_prepared_xacts=%d "
     115             :                          "max_locks_per_xact=%d wal_level=%s "
     116             :                          "wal_log_hints=%s track_commit_timestamp=%s",
     117             :                          xlrec.MaxConnections,
     118             :                          xlrec.max_worker_processes,
     119             :                          xlrec.max_wal_senders,
     120             :                          xlrec.max_prepared_xacts,
     121             :                          xlrec.max_locks_per_xact,
     122             :                          wal_level_str,
     123           4 :                          xlrec.wal_log_hints ? "on" : "off",
     124           4 :                          xlrec.track_commit_timestamp ? "on" : "off");
     125             :     }
     126           2 :     else if (info == XLOG_FPW_CHANGE)
     127             :     {
     128             :         bool        fpw;
     129             : 
     130           0 :         memcpy(&fpw, rec, sizeof(bool));
     131           0 :         appendStringInfoString(buf, fpw ? "true" : "false");
     132             :     }
     133           2 :     else if (info == XLOG_END_OF_RECOVERY)
     134             :     {
     135             :         xl_end_of_recovery xlrec;
     136             : 
     137           0 :         memcpy(&xlrec, rec, sizeof(xl_end_of_recovery));
     138           0 :         appendStringInfo(buf, "tli %u; prev tli %u; time %s",
     139             :                          xlrec.ThisTimeLineID, xlrec.PrevTimeLineID,
     140             :                          timestamptz_to_str(xlrec.end_time));
     141             :     }
     142           2 :     else if (info == XLOG_OVERWRITE_CONTRECORD)
     143             :     {
     144             :         xl_overwrite_contrecord xlrec;
     145             : 
     146           2 :         memcpy(&xlrec, rec, sizeof(xl_overwrite_contrecord));
     147           2 :         appendStringInfo(buf, "lsn %X/%X; time %s",
     148           2 :                          LSN_FORMAT_ARGS(xlrec.overwritten_lsn),
     149             :                          timestamptz_to_str(xlrec.overwrite_time));
     150             :     }
     151           8 : }
     152             : 
     153             : const char *
     154           8 : xlog_identify(uint8 info)
     155             : {
     156           8 :     const char *id = NULL;
     157             : 
     158           8 :     switch (info & ~XLR_INFO_MASK)
     159             :     {
     160           0 :         case XLOG_CHECKPOINT_SHUTDOWN:
     161           0 :             id = "CHECKPOINT_SHUTDOWN";
     162           0 :             break;
     163           0 :         case XLOG_CHECKPOINT_ONLINE:
     164           0 :             id = "CHECKPOINT_ONLINE";
     165           0 :             break;
     166           0 :         case XLOG_NOOP:
     167           0 :             id = "NOOP";
     168           0 :             break;
     169           0 :         case XLOG_NEXTOID:
     170           0 :             id = "NEXTOID";
     171           0 :             break;
     172           0 :         case XLOG_SWITCH:
     173           0 :             id = "SWITCH";
     174           0 :             break;
     175           2 :         case XLOG_BACKUP_END:
     176           2 :             id = "BACKUP_END";
     177           2 :             break;
     178           4 :         case XLOG_PARAMETER_CHANGE:
     179           4 :             id = "PARAMETER_CHANGE";
     180           4 :             break;
     181           0 :         case XLOG_RESTORE_POINT:
     182           0 :             id = "RESTORE_POINT";
     183           0 :             break;
     184           0 :         case XLOG_FPW_CHANGE:
     185           0 :             id = "FPW_CHANGE";
     186           0 :             break;
     187           0 :         case XLOG_END_OF_RECOVERY:
     188           0 :             id = "END_OF_RECOVERY";
     189           0 :             break;
     190           2 :         case XLOG_OVERWRITE_CONTRECORD:
     191           2 :             id = "OVERWRITE_CONTRECORD";
     192           2 :             break;
     193           0 :         case XLOG_FPI:
     194           0 :             id = "FPI";
     195           0 :             break;
     196           0 :         case XLOG_FPI_FOR_HINT:
     197           0 :             id = "FPI_FOR_HINT";
     198           0 :             break;
     199             :     }
     200             : 
     201           8 :     return id;
     202             : }

Generated by: LCOV version 1.14