LCOV - code coverage report
Current view: top level - src/backend/utils/misc - pg_controldata.c (source / functions) Hit Total Coverage
Test: PostgreSQL 13beta1 Lines: 0 148 0.0 %
Date: 2020-06-05 19:06:29 Functions: 0 4 0.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /*-------------------------------------------------------------------------
       2             :  *
       3             :  * pg_controldata.c
       4             :  *
       5             :  * Routines to expose the contents of the control data file via
       6             :  * a set of SQL functions.
       7             :  *
       8             :  * Portions Copyright (c) 1996-2020, PostgreSQL Global Development Group
       9             :  * Portions Copyright (c) 1994, Regents of the University of California
      10             :  *
      11             :  * IDENTIFICATION
      12             :  *    src/backend/utils/misc/pg_controldata.c
      13             :  *-------------------------------------------------------------------------
      14             :  */
      15             : 
      16             : #include "postgres.h"
      17             : 
      18             : #include "access/htup_details.h"
      19             : #include "access/transam.h"
      20             : #include "access/xlog.h"
      21             : #include "access/xlog_internal.h"
      22             : #include "catalog/pg_control.h"
      23             : #include "catalog/pg_type.h"
      24             : #include "common/controldata_utils.h"
      25             : #include "funcapi.h"
      26             : #include "miscadmin.h"
      27             : #include "utils/builtins.h"
      28             : #include "utils/pg_lsn.h"
      29             : #include "utils/timestamp.h"
      30             : 
      31             : Datum
      32           0 : pg_control_system(PG_FUNCTION_ARGS)
      33             : {
      34             :     Datum       values[4];
      35             :     bool        nulls[4];
      36             :     TupleDesc   tupdesc;
      37             :     HeapTuple   htup;
      38             :     ControlFileData *ControlFile;
      39             :     bool        crc_ok;
      40             : 
      41             :     /*
      42             :      * Construct a tuple descriptor for the result row.  This must match this
      43             :      * function's pg_proc entry!
      44             :      */
      45           0 :     tupdesc = CreateTemplateTupleDesc(4);
      46           0 :     TupleDescInitEntry(tupdesc, (AttrNumber) 1, "pg_control_version",
      47             :                        INT4OID, -1, 0);
      48           0 :     TupleDescInitEntry(tupdesc, (AttrNumber) 2, "catalog_version_no",
      49             :                        INT4OID, -1, 0);
      50           0 :     TupleDescInitEntry(tupdesc, (AttrNumber) 3, "system_identifier",
      51             :                        INT8OID, -1, 0);
      52           0 :     TupleDescInitEntry(tupdesc, (AttrNumber) 4, "pg_control_last_modified",
      53             :                        TIMESTAMPTZOID, -1, 0);
      54           0 :     tupdesc = BlessTupleDesc(tupdesc);
      55             : 
      56             :     /* read the control file */
      57           0 :     ControlFile = get_controlfile(DataDir, &crc_ok);
      58           0 :     if (!crc_ok)
      59           0 :         ereport(ERROR,
      60             :                 (errmsg("calculated CRC checksum does not match value stored in file")));
      61             : 
      62           0 :     values[0] = Int32GetDatum(ControlFile->pg_control_version);
      63           0 :     nulls[0] = false;
      64             : 
      65           0 :     values[1] = Int32GetDatum(ControlFile->catalog_version_no);
      66           0 :     nulls[1] = false;
      67             : 
      68           0 :     values[2] = Int64GetDatum(ControlFile->system_identifier);
      69           0 :     nulls[2] = false;
      70             : 
      71           0 :     values[3] = TimestampTzGetDatum(time_t_to_timestamptz(ControlFile->time));
      72           0 :     nulls[3] = false;
      73             : 
      74           0 :     htup = heap_form_tuple(tupdesc, values, nulls);
      75             : 
      76           0 :     PG_RETURN_DATUM(HeapTupleGetDatum(htup));
      77             : }
      78             : 
      79             : Datum
      80           0 : pg_control_checkpoint(PG_FUNCTION_ARGS)
      81             : {
      82             :     Datum       values[19];
      83             :     bool        nulls[19];
      84             :     TupleDesc   tupdesc;
      85             :     HeapTuple   htup;
      86             :     ControlFileData *ControlFile;
      87             :     XLogSegNo   segno;
      88             :     char        xlogfilename[MAXFNAMELEN];
      89             :     bool        crc_ok;
      90             : 
      91             :     /*
      92             :      * Construct a tuple descriptor for the result row.  This must match this
      93             :      * function's pg_proc entry!
      94             :      */
      95           0 :     tupdesc = CreateTemplateTupleDesc(18);
      96           0 :     TupleDescInitEntry(tupdesc, (AttrNumber) 1, "checkpoint_lsn",
      97             :                        LSNOID, -1, 0);
      98           0 :     TupleDescInitEntry(tupdesc, (AttrNumber) 2, "redo_lsn",
      99             :                        LSNOID, -1, 0);
     100           0 :     TupleDescInitEntry(tupdesc, (AttrNumber) 3, "redo_wal_file",
     101             :                        TEXTOID, -1, 0);
     102           0 :     TupleDescInitEntry(tupdesc, (AttrNumber) 4, "timeline_id",
     103             :                        INT4OID, -1, 0);
     104           0 :     TupleDescInitEntry(tupdesc, (AttrNumber) 5, "prev_timeline_id",
     105             :                        INT4OID, -1, 0);
     106           0 :     TupleDescInitEntry(tupdesc, (AttrNumber) 6, "full_page_writes",
     107             :                        BOOLOID, -1, 0);
     108           0 :     TupleDescInitEntry(tupdesc, (AttrNumber) 7, "next_xid",
     109             :                        TEXTOID, -1, 0);
     110           0 :     TupleDescInitEntry(tupdesc, (AttrNumber) 8, "next_oid",
     111             :                        OIDOID, -1, 0);
     112           0 :     TupleDescInitEntry(tupdesc, (AttrNumber) 9, "next_multixact_id",
     113             :                        XIDOID, -1, 0);
     114           0 :     TupleDescInitEntry(tupdesc, (AttrNumber) 10, "next_multi_offset",
     115             :                        XIDOID, -1, 0);
     116           0 :     TupleDescInitEntry(tupdesc, (AttrNumber) 11, "oldest_xid",
     117             :                        XIDOID, -1, 0);
     118           0 :     TupleDescInitEntry(tupdesc, (AttrNumber) 12, "oldest_xid_dbid",
     119             :                        OIDOID, -1, 0);
     120           0 :     TupleDescInitEntry(tupdesc, (AttrNumber) 13, "oldest_active_xid",
     121             :                        XIDOID, -1, 0);
     122           0 :     TupleDescInitEntry(tupdesc, (AttrNumber) 14, "oldest_multi_xid",
     123             :                        XIDOID, -1, 0);
     124           0 :     TupleDescInitEntry(tupdesc, (AttrNumber) 15, "oldest_multi_dbid",
     125             :                        OIDOID, -1, 0);
     126           0 :     TupleDescInitEntry(tupdesc, (AttrNumber) 16, "oldest_commit_ts_xid",
     127             :                        XIDOID, -1, 0);
     128           0 :     TupleDescInitEntry(tupdesc, (AttrNumber) 17, "newest_commit_ts_xid",
     129             :                        XIDOID, -1, 0);
     130           0 :     TupleDescInitEntry(tupdesc, (AttrNumber) 18, "checkpoint_time",
     131             :                        TIMESTAMPTZOID, -1, 0);
     132           0 :     tupdesc = BlessTupleDesc(tupdesc);
     133             : 
     134             :     /* Read the control file. */
     135           0 :     ControlFile = get_controlfile(DataDir, &crc_ok);
     136           0 :     if (!crc_ok)
     137           0 :         ereport(ERROR,
     138             :                 (errmsg("calculated CRC checksum does not match value stored in file")));
     139             : 
     140             :     /*
     141             :      * Calculate name of the WAL file containing the latest checkpoint's REDO
     142             :      * start point.
     143             :      */
     144           0 :     XLByteToSeg(ControlFile->checkPointCopy.redo, segno, wal_segment_size);
     145           0 :     XLogFileName(xlogfilename, ControlFile->checkPointCopy.ThisTimeLineID,
     146             :                  segno, wal_segment_size);
     147             : 
     148             :     /* Populate the values and null arrays */
     149           0 :     values[0] = LSNGetDatum(ControlFile->checkPoint);
     150           0 :     nulls[0] = false;
     151             : 
     152           0 :     values[1] = LSNGetDatum(ControlFile->checkPointCopy.redo);
     153           0 :     nulls[1] = false;
     154             : 
     155           0 :     values[2] = CStringGetTextDatum(xlogfilename);
     156           0 :     nulls[2] = false;
     157             : 
     158           0 :     values[3] = Int32GetDatum(ControlFile->checkPointCopy.ThisTimeLineID);
     159           0 :     nulls[3] = false;
     160             : 
     161           0 :     values[4] = Int32GetDatum(ControlFile->checkPointCopy.PrevTimeLineID);
     162           0 :     nulls[4] = false;
     163             : 
     164           0 :     values[5] = BoolGetDatum(ControlFile->checkPointCopy.fullPageWrites);
     165           0 :     nulls[5] = false;
     166             : 
     167           0 :     values[6] = CStringGetTextDatum(psprintf("%u:%u",
     168             :                                              EpochFromFullTransactionId(ControlFile->checkPointCopy.nextFullXid),
     169             :                                              XidFromFullTransactionId(ControlFile->checkPointCopy.nextFullXid)));
     170           0 :     nulls[6] = false;
     171             : 
     172           0 :     values[7] = ObjectIdGetDatum(ControlFile->checkPointCopy.nextOid);
     173           0 :     nulls[7] = false;
     174             : 
     175           0 :     values[8] = TransactionIdGetDatum(ControlFile->checkPointCopy.nextMulti);
     176           0 :     nulls[8] = false;
     177             : 
     178           0 :     values[9] = TransactionIdGetDatum(ControlFile->checkPointCopy.nextMultiOffset);
     179           0 :     nulls[9] = false;
     180             : 
     181           0 :     values[10] = TransactionIdGetDatum(ControlFile->checkPointCopy.oldestXid);
     182           0 :     nulls[10] = false;
     183             : 
     184           0 :     values[11] = ObjectIdGetDatum(ControlFile->checkPointCopy.oldestXidDB);
     185           0 :     nulls[11] = false;
     186             : 
     187           0 :     values[12] = TransactionIdGetDatum(ControlFile->checkPointCopy.oldestActiveXid);
     188           0 :     nulls[12] = false;
     189             : 
     190           0 :     values[13] = TransactionIdGetDatum(ControlFile->checkPointCopy.oldestMulti);
     191           0 :     nulls[13] = false;
     192             : 
     193           0 :     values[14] = ObjectIdGetDatum(ControlFile->checkPointCopy.oldestMultiDB);
     194           0 :     nulls[14] = false;
     195             : 
     196           0 :     values[15] = TransactionIdGetDatum(ControlFile->checkPointCopy.oldestCommitTsXid);
     197           0 :     nulls[15] = false;
     198             : 
     199           0 :     values[16] = TransactionIdGetDatum(ControlFile->checkPointCopy.newestCommitTsXid);
     200           0 :     nulls[16] = false;
     201             : 
     202           0 :     values[17] = TimestampTzGetDatum(time_t_to_timestamptz(ControlFile->checkPointCopy.time));
     203           0 :     nulls[17] = false;
     204             : 
     205           0 :     htup = heap_form_tuple(tupdesc, values, nulls);
     206             : 
     207           0 :     PG_RETURN_DATUM(HeapTupleGetDatum(htup));
     208             : }
     209             : 
     210             : Datum
     211           0 : pg_control_recovery(PG_FUNCTION_ARGS)
     212             : {
     213             :     Datum       values[5];
     214             :     bool        nulls[5];
     215             :     TupleDesc   tupdesc;
     216             :     HeapTuple   htup;
     217             :     ControlFileData *ControlFile;
     218             :     bool        crc_ok;
     219             : 
     220             :     /*
     221             :      * Construct a tuple descriptor for the result row.  This must match this
     222             :      * function's pg_proc entry!
     223             :      */
     224           0 :     tupdesc = CreateTemplateTupleDesc(5);
     225           0 :     TupleDescInitEntry(tupdesc, (AttrNumber) 1, "min_recovery_end_lsn",
     226             :                        LSNOID, -1, 0);
     227           0 :     TupleDescInitEntry(tupdesc, (AttrNumber) 2, "min_recovery_end_timeline",
     228             :                        INT4OID, -1, 0);
     229           0 :     TupleDescInitEntry(tupdesc, (AttrNumber) 3, "backup_start_lsn",
     230             :                        LSNOID, -1, 0);
     231           0 :     TupleDescInitEntry(tupdesc, (AttrNumber) 4, "backup_end_lsn",
     232             :                        LSNOID, -1, 0);
     233           0 :     TupleDescInitEntry(tupdesc, (AttrNumber) 5, "end_of_backup_record_required",
     234             :                        BOOLOID, -1, 0);
     235           0 :     tupdesc = BlessTupleDesc(tupdesc);
     236             : 
     237             :     /* read the control file */
     238           0 :     ControlFile = get_controlfile(DataDir, &crc_ok);
     239           0 :     if (!crc_ok)
     240           0 :         ereport(ERROR,
     241             :                 (errmsg("calculated CRC checksum does not match value stored in file")));
     242             : 
     243           0 :     values[0] = LSNGetDatum(ControlFile->minRecoveryPoint);
     244           0 :     nulls[0] = false;
     245             : 
     246           0 :     values[1] = Int32GetDatum(ControlFile->minRecoveryPointTLI);
     247           0 :     nulls[1] = false;
     248             : 
     249           0 :     values[2] = LSNGetDatum(ControlFile->backupStartPoint);
     250           0 :     nulls[2] = false;
     251             : 
     252           0 :     values[3] = LSNGetDatum(ControlFile->backupEndPoint);
     253           0 :     nulls[3] = false;
     254             : 
     255           0 :     values[4] = BoolGetDatum(ControlFile->backupEndRequired);
     256           0 :     nulls[4] = false;
     257             : 
     258           0 :     htup = heap_form_tuple(tupdesc, values, nulls);
     259             : 
     260           0 :     PG_RETURN_DATUM(HeapTupleGetDatum(htup));
     261             : }
     262             : 
     263             : Datum
     264           0 : pg_control_init(PG_FUNCTION_ARGS)
     265             : {
     266             :     Datum       values[11];
     267             :     bool        nulls[11];
     268             :     TupleDesc   tupdesc;
     269             :     HeapTuple   htup;
     270             :     ControlFileData *ControlFile;
     271             :     bool        crc_ok;
     272             : 
     273             :     /*
     274             :      * Construct a tuple descriptor for the result row.  This must match this
     275             :      * function's pg_proc entry!
     276             :      */
     277           0 :     tupdesc = CreateTemplateTupleDesc(11);
     278           0 :     TupleDescInitEntry(tupdesc, (AttrNumber) 1, "max_data_alignment",
     279             :                        INT4OID, -1, 0);
     280           0 :     TupleDescInitEntry(tupdesc, (AttrNumber) 2, "database_block_size",
     281             :                        INT4OID, -1, 0);
     282           0 :     TupleDescInitEntry(tupdesc, (AttrNumber) 3, "blocks_per_segment",
     283             :                        INT4OID, -1, 0);
     284           0 :     TupleDescInitEntry(tupdesc, (AttrNumber) 4, "wal_block_size",
     285             :                        INT4OID, -1, 0);
     286           0 :     TupleDescInitEntry(tupdesc, (AttrNumber) 5, "bytes_per_wal_segment",
     287             :                        INT4OID, -1, 0);
     288           0 :     TupleDescInitEntry(tupdesc, (AttrNumber) 6, "max_identifier_length",
     289             :                        INT4OID, -1, 0);
     290           0 :     TupleDescInitEntry(tupdesc, (AttrNumber) 7, "max_index_columns",
     291             :                        INT4OID, -1, 0);
     292           0 :     TupleDescInitEntry(tupdesc, (AttrNumber) 8, "max_toast_chunk_size",
     293             :                        INT4OID, -1, 0);
     294           0 :     TupleDescInitEntry(tupdesc, (AttrNumber) 9, "large_object_chunk_size",
     295             :                        INT4OID, -1, 0);
     296           0 :     TupleDescInitEntry(tupdesc, (AttrNumber) 10, "float8_pass_by_value",
     297             :                        BOOLOID, -1, 0);
     298           0 :     TupleDescInitEntry(tupdesc, (AttrNumber) 11, "data_page_checksum_version",
     299             :                        INT4OID, -1, 0);
     300           0 :     tupdesc = BlessTupleDesc(tupdesc);
     301             : 
     302             :     /* read the control file */
     303           0 :     ControlFile = get_controlfile(DataDir, &crc_ok);
     304           0 :     if (!crc_ok)
     305           0 :         ereport(ERROR,
     306             :                 (errmsg("calculated CRC checksum does not match value stored in file")));
     307             : 
     308           0 :     values[0] = Int32GetDatum(ControlFile->maxAlign);
     309           0 :     nulls[0] = false;
     310             : 
     311           0 :     values[1] = Int32GetDatum(ControlFile->blcksz);
     312           0 :     nulls[1] = false;
     313             : 
     314           0 :     values[2] = Int32GetDatum(ControlFile->relseg_size);
     315           0 :     nulls[2] = false;
     316             : 
     317           0 :     values[3] = Int32GetDatum(ControlFile->xlog_blcksz);
     318           0 :     nulls[3] = false;
     319             : 
     320           0 :     values[4] = Int32GetDatum(ControlFile->xlog_seg_size);
     321           0 :     nulls[4] = false;
     322             : 
     323           0 :     values[5] = Int32GetDatum(ControlFile->nameDataLen);
     324           0 :     nulls[5] = false;
     325             : 
     326           0 :     values[6] = Int32GetDatum(ControlFile->indexMaxKeys);
     327           0 :     nulls[6] = false;
     328             : 
     329           0 :     values[7] = Int32GetDatum(ControlFile->toast_max_chunk_size);
     330           0 :     nulls[7] = false;
     331             : 
     332           0 :     values[8] = Int32GetDatum(ControlFile->loblksize);
     333           0 :     nulls[8] = false;
     334             : 
     335           0 :     values[9] = BoolGetDatum(ControlFile->float8ByVal);
     336           0 :     nulls[9] = false;
     337             : 
     338           0 :     values[10] = Int32GetDatum(ControlFile->data_checksum_version);
     339           0 :     nulls[10] = false;
     340             : 
     341           0 :     htup = heap_form_tuple(tupdesc, values, nulls);
     342             : 
     343           0 :     PG_RETURN_DATUM(HeapTupleGetDatum(htup));
     344             : }

Generated by: LCOV version 1.13