PostgreSQL Source Code  git master
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros
pg_controldata.c File Reference
#include "postgres.h"
#include "funcapi.h"
#include "miscadmin.h"
#include "access/htup_details.h"
#include "access/xlog_internal.h"
#include "catalog/pg_control.h"
#include "catalog/pg_type.h"
#include "common/controldata_utils.h"
#include "utils/builtins.h"
#include "utils/pg_lsn.h"
#include "utils/timestamp.h"
Include dependency graph for pg_controldata.c:

Go to the source code of this file.

Functions

Datum pg_control_system (PG_FUNCTION_ARGS)
 
Datum pg_control_checkpoint (PG_FUNCTION_ARGS)
 
Datum pg_control_recovery (PG_FUNCTION_ARGS)
 
Datum pg_control_init (PG_FUNCTION_ARGS)
 

Function Documentation

Datum pg_control_checkpoint ( PG_FUNCTION_ARGS  )

Definition at line 78 of file pg_controldata.c.

References BlessTupleDesc(), BoolGetDatum, BOOLOID, ControlFileData::checkPoint, ControlFileData::checkPointCopy, ControlFile, CreateTemplateTupleDesc(), CStringGetTextDatum, DataDir, ereport, errmsg(), ERROR, CheckPoint::fullPageWrites, get_controlfile(), heap_form_tuple(), HeapTupleGetDatum, Int32GetDatum, INT4OID, LSNGetDatum, LSNOID, MAXFNAMELEN, CheckPoint::newestCommitTsXid, CheckPoint::nextMulti, CheckPoint::nextMultiOffset, CheckPoint::nextOid, CheckPoint::nextXid, CheckPoint::nextXidEpoch, ObjectIdGetDatum, OIDOID, CheckPoint::oldestActiveXid, CheckPoint::oldestCommitTsXid, CheckPoint::oldestMulti, CheckPoint::oldestMultiDB, CheckPoint::oldestXid, CheckPoint::oldestXidDB, PG_RETURN_DATUM, ControlFileData::prevCheckPoint, CheckPoint::PrevTimeLineID, psprintf(), CheckPoint::redo, TEXTOID, CheckPoint::ThisTimeLineID, CheckPoint::time, time_t_to_timestamptz(), TimestampTzGetDatum, TIMESTAMPTZOID, TransactionIdGetDatum, TupleDescInitEntry(), values, wal_segment_size, XIDOID, XLByteToSeg, and XLogFileName.

79 {
80  Datum values[19];
81  bool nulls[19];
82  TupleDesc tupdesc;
83  HeapTuple htup;
85  XLogSegNo segno;
86  char xlogfilename[MAXFNAMELEN];
87  bool crc_ok;
88 
89  /*
90  * Construct a tuple descriptor for the result row. This must match this
91  * function's pg_proc entry!
92  */
93  tupdesc = CreateTemplateTupleDesc(19, false);
94  TupleDescInitEntry(tupdesc, (AttrNumber) 1, "checkpoint_lsn",
95  LSNOID, -1, 0);
96  TupleDescInitEntry(tupdesc, (AttrNumber) 2, "prior_lsn",
97  LSNOID, -1, 0);
98  TupleDescInitEntry(tupdesc, (AttrNumber) 3, "redo_lsn",
99  LSNOID, -1, 0);
100  TupleDescInitEntry(tupdesc, (AttrNumber) 4, "redo_wal_file",
101  TEXTOID, -1, 0);
102  TupleDescInitEntry(tupdesc, (AttrNumber) 5, "timeline_id",
103  INT4OID, -1, 0);
104  TupleDescInitEntry(tupdesc, (AttrNumber) 6, "prev_timeline_id",
105  INT4OID, -1, 0);
106  TupleDescInitEntry(tupdesc, (AttrNumber) 7, "full_page_writes",
107  BOOLOID, -1, 0);
108  TupleDescInitEntry(tupdesc, (AttrNumber) 8, "next_xid",
109  TEXTOID, -1, 0);
110  TupleDescInitEntry(tupdesc, (AttrNumber) 9, "next_oid",
111  OIDOID, -1, 0);
112  TupleDescInitEntry(tupdesc, (AttrNumber) 10, "next_multixact_id",
113  XIDOID, -1, 0);
114  TupleDescInitEntry(tupdesc, (AttrNumber) 11, "next_multi_offset",
115  XIDOID, -1, 0);
116  TupleDescInitEntry(tupdesc, (AttrNumber) 12, "oldest_xid",
117  XIDOID, -1, 0);
118  TupleDescInitEntry(tupdesc, (AttrNumber) 13, "oldest_xid_dbid",
119  OIDOID, -1, 0);
120  TupleDescInitEntry(tupdesc, (AttrNumber) 14, "oldest_active_xid",
121  XIDOID, -1, 0);
122  TupleDescInitEntry(tupdesc, (AttrNumber) 15, "oldest_multi_xid",
123  XIDOID, -1, 0);
124  TupleDescInitEntry(tupdesc, (AttrNumber) 16, "oldest_multi_dbid",
125  OIDOID, -1, 0);
126  TupleDescInitEntry(tupdesc, (AttrNumber) 17, "oldest_commit_ts_xid",
127  XIDOID, -1, 0);
128  TupleDescInitEntry(tupdesc, (AttrNumber) 18, "newest_commit_ts_xid",
129  XIDOID, -1, 0);
130  TupleDescInitEntry(tupdesc, (AttrNumber) 19, "checkpoint_time",
131  TIMESTAMPTZOID, -1, 0);
132  tupdesc = BlessTupleDesc(tupdesc);
133 
134  /* Read the control file. */
135  ControlFile = get_controlfile(DataDir, NULL, &crc_ok);
136  if (!crc_ok)
137  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  XLByteToSeg(ControlFile->checkPointCopy.redo, segno, wal_segment_size);
145  XLogFileName(xlogfilename, ControlFile->checkPointCopy.ThisTimeLineID,
146  segno, wal_segment_size);
147 
148  /* Populate the values and null arrays */
149  values[0] = LSNGetDatum(ControlFile->checkPoint);
150  nulls[0] = false;
151 
152  values[1] = LSNGetDatum(ControlFile->prevCheckPoint);
153  nulls[1] = false;
154 
155  values[2] = LSNGetDatum(ControlFile->checkPointCopy.redo);
156  nulls[2] = false;
157 
158  values[3] = CStringGetTextDatum(xlogfilename);
159  nulls[3] = false;
160 
161  values[4] = Int32GetDatum(ControlFile->checkPointCopy.ThisTimeLineID);
162  nulls[4] = false;
163 
164  values[5] = Int32GetDatum(ControlFile->checkPointCopy.PrevTimeLineID);
165  nulls[5] = false;
166 
167  values[6] = BoolGetDatum(ControlFile->checkPointCopy.fullPageWrites);
168  nulls[6] = false;
169 
170  values[7] = CStringGetTextDatum(psprintf("%u:%u",
171  ControlFile->checkPointCopy.nextXidEpoch,
172  ControlFile->checkPointCopy.nextXid));
173  nulls[7] = false;
174 
175  values[8] = ObjectIdGetDatum(ControlFile->checkPointCopy.nextOid);
176  nulls[8] = false;
177 
178  values[9] = TransactionIdGetDatum(ControlFile->checkPointCopy.nextMulti);
179  nulls[9] = false;
180 
181  values[10] = TransactionIdGetDatum(ControlFile->checkPointCopy.nextMultiOffset);
182  nulls[10] = false;
183 
184  values[11] = TransactionIdGetDatum(ControlFile->checkPointCopy.oldestXid);
185  nulls[11] = false;
186 
187  values[12] = ObjectIdGetDatum(ControlFile->checkPointCopy.oldestXidDB);
188  nulls[12] = false;
189 
190  values[13] = TransactionIdGetDatum(ControlFile->checkPointCopy.oldestActiveXid);
191  nulls[13] = false;
192 
193  values[14] = TransactionIdGetDatum(ControlFile->checkPointCopy.oldestMulti);
194  nulls[14] = false;
195 
196  values[15] = ObjectIdGetDatum(ControlFile->checkPointCopy.oldestMultiDB);
197  nulls[15] = false;
198 
199  values[16] = TransactionIdGetDatum(ControlFile->checkPointCopy.oldestCommitTsXid);
200  nulls[16] = false;
201 
202  values[17] = TransactionIdGetDatum(ControlFile->checkPointCopy.newestCommitTsXid);
203  nulls[17] = false;
204 
205  values[18] = TimestampTzGetDatum(
207  nulls[18] = false;
208 
209  htup = heap_form_tuple(tupdesc, values, nulls);
210 
212 }
#define TIMESTAMPTZOID
Definition: pg_type.h:525
int wal_segment_size
Definition: xlog.c:113
#define OIDOID
Definition: pg_type.h:328
#define TEXTOID
Definition: pg_type.h:324
TransactionId oldestActiveXid
Definition: pg_control.h:63
ControlFileData * get_controlfile(const char *DataDir, const char *progname, bool *crc_ok_p)
char * psprintf(const char *fmt,...)
Definition: psprintf.c:46
MultiXactId oldestMulti
Definition: pg_control.h:49
#define INT4OID
Definition: pg_type.h:316
TimeLineID PrevTimeLineID
Definition: pg_control.h:39
#define LSNGetDatum(X)
Definition: pg_lsn.h:22
#define XIDOID
Definition: pg_type.h:336
HeapTuple heap_form_tuple(TupleDesc tupleDescriptor, Datum *values, bool *isnull)
Definition: heaptuple.c:695
CheckPoint checkPointCopy
Definition: pg_control.h:132
TransactionId oldestXid
Definition: pg_control.h:47
TransactionId nextXid
Definition: pg_control.h:43
pg_time_t time
Definition: pg_control.h:51
MultiXactOffset nextMultiOffset
Definition: pg_control.h:46
#define LSNOID
Definition: pg_type.h:609
TransactionId oldestCommitTsXid
Definition: pg_control.h:52
#define ObjectIdGetDatum(X)
Definition: postgres.h:513
#define ERROR
Definition: elog.h:43
#define TimestampTzGetDatum(X)
Definition: timestamp.h:32
uint32 nextXidEpoch
Definition: pg_control.h:42
TupleDesc BlessTupleDesc(TupleDesc tupdesc)
Definition: execTuples.c:1032
uint64 XLogSegNo
Definition: xlogdefs.h:34
void TupleDescInitEntry(TupleDesc desc, AttrNumber attributeNumber, const char *attributeName, Oid oidtypeid, int32 typmod, int attdim)
Definition: tupdesc.c:505
#define ereport(elevel, rest)
Definition: elog.h:122
#define MAXFNAMELEN
TransactionId newestCommitTsXid
Definition: pg_control.h:54
#define TransactionIdGetDatum(X)
Definition: postgres.h:527
uintptr_t Datum
Definition: postgres.h:372
#define PG_RETURN_DATUM(x)
Definition: fmgr.h:313
Oid oldestMultiDB
Definition: pg_control.h:50
XLogRecPtr prevCheckPoint
Definition: pg_control.h:130
TimestampTz time_t_to_timestamptz(pg_time_t tm)
Definition: timestamp.c:1670
static ControlFileData * ControlFile
Definition: xlog.c:715
#define BoolGetDatum(X)
Definition: postgres.h:408
Oid nextOid
Definition: pg_control.h:44
bool fullPageWrites
Definition: pg_control.h:41
Oid oldestXidDB
Definition: pg_control.h:48
#define XLogFileName(fname, tli, logSegNo, wal_segsz_bytes)
MultiXactId nextMulti
Definition: pg_control.h:45
#define HeapTupleGetDatum(tuple)
Definition: funcapi.h:222
#define BOOLOID
Definition: pg_type.h:288
TupleDesc CreateTemplateTupleDesc(int natts, bool hasoid)
Definition: tupdesc.c:43
static Datum values[MAXATTR]
Definition: bootstrap.c:164
#define Int32GetDatum(X)
Definition: postgres.h:485
TimeLineID ThisTimeLineID
Definition: pg_control.h:38
int errmsg(const char *fmt,...)
Definition: elog.c:797
#define CStringGetTextDatum(s)
Definition: builtins.h:91
char * DataDir
Definition: globals.c:60
int16 AttrNumber
Definition: attnum.h:21
XLogRecPtr checkPoint
Definition: pg_control.h:129
XLogRecPtr redo
Definition: pg_control.h:36
#define XLByteToSeg(xlrp, logSegNo, wal_segsz_bytes)
Datum pg_control_init ( PG_FUNCTION_ARGS  )

Definition at line 268 of file pg_controldata.c.

References ControlFileData::blcksz, BlessTupleDesc(), BoolGetDatum, BOOLOID, ControlFile, CreateTemplateTupleDesc(), ControlFileData::data_checksum_version, DataDir, ereport, errmsg(), ERROR, ControlFileData::float4ByVal, ControlFileData::float8ByVal, get_controlfile(), heap_form_tuple(), HeapTupleGetDatum, ControlFileData::indexMaxKeys, Int32GetDatum, INT4OID, ControlFileData::loblksize, ControlFileData::maxAlign, ControlFileData::nameDataLen, PG_RETURN_DATUM, ControlFileData::relseg_size, ControlFileData::toast_max_chunk_size, TupleDescInitEntry(), values, ControlFileData::xlog_blcksz, and ControlFileData::xlog_seg_size.

269 {
270  Datum values[12];
271  bool nulls[12];
272  TupleDesc tupdesc;
273  HeapTuple htup;
275  bool crc_ok;
276 
277  /*
278  * Construct a tuple descriptor for the result row. This must match this
279  * function's pg_proc entry!
280  */
281  tupdesc = CreateTemplateTupleDesc(12, false);
282  TupleDescInitEntry(tupdesc, (AttrNumber) 1, "max_data_alignment",
283  INT4OID, -1, 0);
284  TupleDescInitEntry(tupdesc, (AttrNumber) 2, "database_block_size",
285  INT4OID, -1, 0);
286  TupleDescInitEntry(tupdesc, (AttrNumber) 3, "blocks_per_segment",
287  INT4OID, -1, 0);
288  TupleDescInitEntry(tupdesc, (AttrNumber) 4, "wal_block_size",
289  INT4OID, -1, 0);
290  TupleDescInitEntry(tupdesc, (AttrNumber) 5, "bytes_per_wal_segment",
291  INT4OID, -1, 0);
292  TupleDescInitEntry(tupdesc, (AttrNumber) 6, "max_identifier_length",
293  INT4OID, -1, 0);
294  TupleDescInitEntry(tupdesc, (AttrNumber) 7, "max_index_columns",
295  INT4OID, -1, 0);
296  TupleDescInitEntry(tupdesc, (AttrNumber) 8, "max_toast_chunk_size",
297  INT4OID, -1, 0);
298  TupleDescInitEntry(tupdesc, (AttrNumber) 9, "large_object_chunk_size",
299  INT4OID, -1, 0);
300  TupleDescInitEntry(tupdesc, (AttrNumber) 10, "float4_pass_by_value",
301  BOOLOID, -1, 0);
302  TupleDescInitEntry(tupdesc, (AttrNumber) 11, "float8_pass_by_value",
303  BOOLOID, -1, 0);
304  TupleDescInitEntry(tupdesc, (AttrNumber) 12, "data_page_checksum_version",
305  INT4OID, -1, 0);
306  tupdesc = BlessTupleDesc(tupdesc);
307 
308  /* read the control file */
309  ControlFile = get_controlfile(DataDir, NULL, &crc_ok);
310  if (!crc_ok)
311  ereport(ERROR,
312  (errmsg("calculated CRC checksum does not match value stored in file")));
313 
314  values[0] = Int32GetDatum(ControlFile->maxAlign);
315  nulls[0] = false;
316 
317  values[1] = Int32GetDatum(ControlFile->blcksz);
318  nulls[1] = false;
319 
320  values[2] = Int32GetDatum(ControlFile->relseg_size);
321  nulls[2] = false;
322 
323  values[3] = Int32GetDatum(ControlFile->xlog_blcksz);
324  nulls[3] = false;
325 
326  values[4] = Int32GetDatum(ControlFile->xlog_seg_size);
327  nulls[4] = false;
328 
329  values[5] = Int32GetDatum(ControlFile->nameDataLen);
330  nulls[5] = false;
331 
332  values[6] = Int32GetDatum(ControlFile->indexMaxKeys);
333  nulls[6] = false;
334 
335  values[7] = Int32GetDatum(ControlFile->toast_max_chunk_size);
336  nulls[7] = false;
337 
338  values[8] = Int32GetDatum(ControlFile->loblksize);
339  nulls[8] = false;
340 
341  values[9] = BoolGetDatum(ControlFile->float4ByVal);
342  nulls[9] = false;
343 
344  values[10] = BoolGetDatum(ControlFile->float8ByVal);
345  nulls[10] = false;
346 
347  values[11] = Int32GetDatum(ControlFile->data_checksum_version);
348  nulls[11] = false;
349 
350  htup = heap_form_tuple(tupdesc, values, nulls);
351 
353 }
ControlFileData * get_controlfile(const char *DataDir, const char *progname, bool *crc_ok_p)
uint32 nameDataLen
Definition: pg_control.h:211
#define INT4OID
Definition: pg_type.h:316
HeapTuple heap_form_tuple(TupleDesc tupleDescriptor, Datum *values, bool *isnull)
Definition: heaptuple.c:695
uint32 xlog_blcksz
Definition: pg_control.h:208
uint32 xlog_seg_size
Definition: pg_control.h:209
#define ERROR
Definition: elog.h:43
TupleDesc BlessTupleDesc(TupleDesc tupdesc)
Definition: execTuples.c:1032
uint32 data_checksum_version
Definition: pg_control.h:222
uint32 loblksize
Definition: pg_control.h:215
void TupleDescInitEntry(TupleDesc desc, AttrNumber attributeNumber, const char *attributeName, Oid oidtypeid, int32 typmod, int attdim)
Definition: tupdesc.c:505
#define ereport(elevel, rest)
Definition: elog.h:122
uint32 indexMaxKeys
Definition: pg_control.h:212
uintptr_t Datum
Definition: postgres.h:372
#define PG_RETURN_DATUM(x)
Definition: fmgr.h:313
uint32 toast_max_chunk_size
Definition: pg_control.h:214
static ControlFileData * ControlFile
Definition: xlog.c:715
#define BoolGetDatum(X)
Definition: postgres.h:408
#define HeapTupleGetDatum(tuple)
Definition: funcapi.h:222
#define BOOLOID
Definition: pg_type.h:288
TupleDesc CreateTemplateTupleDesc(int natts, bool hasoid)
Definition: tupdesc.c:43
static Datum values[MAXATTR]
Definition: bootstrap.c:164
#define Int32GetDatum(X)
Definition: postgres.h:485
int errmsg(const char *fmt,...)
Definition: elog.c:797
char * DataDir
Definition: globals.c:60
int16 AttrNumber
Definition: attnum.h:21
uint32 relseg_size
Definition: pg_control.h:206
Datum pg_control_recovery ( PG_FUNCTION_ARGS  )

Definition at line 215 of file pg_controldata.c.

References ControlFileData::backupEndPoint, ControlFileData::backupEndRequired, ControlFileData::backupStartPoint, BlessTupleDesc(), BoolGetDatum, BOOLOID, ControlFile, CreateTemplateTupleDesc(), DataDir, ereport, errmsg(), ERROR, get_controlfile(), heap_form_tuple(), HeapTupleGetDatum, Int32GetDatum, INT4OID, LSNGetDatum, LSNOID, ControlFileData::minRecoveryPoint, ControlFileData::minRecoveryPointTLI, PG_RETURN_DATUM, TupleDescInitEntry(), and values.

216 {
217  Datum values[5];
218  bool nulls[5];
219  TupleDesc tupdesc;
220  HeapTuple htup;
222  bool crc_ok;
223 
224  /*
225  * Construct a tuple descriptor for the result row. This must match this
226  * function's pg_proc entry!
227  */
228  tupdesc = CreateTemplateTupleDesc(5, false);
229  TupleDescInitEntry(tupdesc, (AttrNumber) 1, "min_recovery_end_lsn",
230  LSNOID, -1, 0);
231  TupleDescInitEntry(tupdesc, (AttrNumber) 2, "min_recovery_end_timeline",
232  INT4OID, -1, 0);
233  TupleDescInitEntry(tupdesc, (AttrNumber) 3, "backup_start_lsn",
234  LSNOID, -1, 0);
235  TupleDescInitEntry(tupdesc, (AttrNumber) 4, "backup_end_lsn",
236  LSNOID, -1, 0);
237  TupleDescInitEntry(tupdesc, (AttrNumber) 5, "end_of_backup_record_required",
238  BOOLOID, -1, 0);
239  tupdesc = BlessTupleDesc(tupdesc);
240 
241  /* read the control file */
242  ControlFile = get_controlfile(DataDir, NULL, &crc_ok);
243  if (!crc_ok)
244  ereport(ERROR,
245  (errmsg("calculated CRC checksum does not match value stored in file")));
246 
247  values[0] = LSNGetDatum(ControlFile->minRecoveryPoint);
248  nulls[0] = false;
249 
250  values[1] = Int32GetDatum(ControlFile->minRecoveryPointTLI);
251  nulls[1] = false;
252 
253  values[2] = LSNGetDatum(ControlFile->backupStartPoint);
254  nulls[2] = false;
255 
256  values[3] = LSNGetDatum(ControlFile->backupEndPoint);
257  nulls[3] = false;
258 
259  values[4] = BoolGetDatum(ControlFile->backupEndRequired);
260  nulls[4] = false;
261 
262  htup = heap_form_tuple(tupdesc, values, nulls);
263 
265 }
TimeLineID minRecoveryPointTLI
Definition: pg_control.h:168
ControlFileData * get_controlfile(const char *DataDir, const char *progname, bool *crc_ok_p)
#define INT4OID
Definition: pg_type.h:316
#define LSNGetDatum(X)
Definition: pg_lsn.h:22
HeapTuple heap_form_tuple(TupleDesc tupleDescriptor, Datum *values, bool *isnull)
Definition: heaptuple.c:695
bool backupEndRequired
Definition: pg_control.h:171
#define LSNOID
Definition: pg_type.h:609
#define ERROR
Definition: elog.h:43
TupleDesc BlessTupleDesc(TupleDesc tupdesc)
Definition: execTuples.c:1032
void TupleDescInitEntry(TupleDesc desc, AttrNumber attributeNumber, const char *attributeName, Oid oidtypeid, int32 typmod, int attdim)
Definition: tupdesc.c:505
#define ereport(elevel, rest)
Definition: elog.h:122
uintptr_t Datum
Definition: postgres.h:372
#define PG_RETURN_DATUM(x)
Definition: fmgr.h:313
static ControlFileData * ControlFile
Definition: xlog.c:715
#define BoolGetDatum(X)
Definition: postgres.h:408
XLogRecPtr backupEndPoint
Definition: pg_control.h:170
#define HeapTupleGetDatum(tuple)
Definition: funcapi.h:222
#define BOOLOID
Definition: pg_type.h:288
TupleDesc CreateTemplateTupleDesc(int natts, bool hasoid)
Definition: tupdesc.c:43
static Datum values[MAXATTR]
Definition: bootstrap.c:164
#define Int32GetDatum(X)
Definition: postgres.h:485
int errmsg(const char *fmt,...)
Definition: elog.c:797
char * DataDir
Definition: globals.c:60
int16 AttrNumber
Definition: attnum.h:21
XLogRecPtr backupStartPoint
Definition: pg_control.h:169
XLogRecPtr minRecoveryPoint
Definition: pg_control.h:167
Datum pg_control_system ( PG_FUNCTION_ARGS  )

Definition at line 30 of file pg_controldata.c.

References BlessTupleDesc(), ControlFileData::catalog_version_no, ControlFile, CreateTemplateTupleDesc(), DataDir, ereport, errmsg(), ERROR, get_controlfile(), heap_form_tuple(), HeapTupleGetDatum, Int32GetDatum, INT4OID, Int64GetDatum(), INT8OID, ControlFileData::pg_control_version, PG_RETURN_DATUM, ControlFileData::system_identifier, ControlFileData::time, time_t_to_timestamptz(), TimestampTzGetDatum, TIMESTAMPTZOID, TupleDescInitEntry(), and values.

31 {
32  Datum values[4];
33  bool nulls[4];
34  TupleDesc tupdesc;
35  HeapTuple htup;
37  bool crc_ok;
38 
39  /*
40  * Construct a tuple descriptor for the result row. This must match this
41  * function's pg_proc entry!
42  */
43  tupdesc = CreateTemplateTupleDesc(4, false);
44  TupleDescInitEntry(tupdesc, (AttrNumber) 1, "pg_control_version",
45  INT4OID, -1, 0);
46  TupleDescInitEntry(tupdesc, (AttrNumber) 2, "catalog_version_no",
47  INT4OID, -1, 0);
48  TupleDescInitEntry(tupdesc, (AttrNumber) 3, "system_identifier",
49  INT8OID, -1, 0);
50  TupleDescInitEntry(tupdesc, (AttrNumber) 4, "pg_control_last_modified",
51  TIMESTAMPTZOID, -1, 0);
52  tupdesc = BlessTupleDesc(tupdesc);
53 
54  /* read the control file */
55  ControlFile = get_controlfile(DataDir, NULL, &crc_ok);
56  if (!crc_ok)
57  ereport(ERROR,
58  (errmsg("calculated CRC checksum does not match value stored in file")));
59 
60  values[0] = Int32GetDatum(ControlFile->pg_control_version);
61  nulls[0] = false;
62 
63  values[1] = Int32GetDatum(ControlFile->catalog_version_no);
64  nulls[1] = false;
65 
66  values[2] = Int64GetDatum(ControlFile->system_identifier);
67  nulls[2] = false;
68 
69  values[3] = TimestampTzGetDatum(time_t_to_timestamptz(ControlFile->time));
70  nulls[3] = false;
71 
72  htup = heap_form_tuple(tupdesc, values, nulls);
73 
75 }
#define TIMESTAMPTZOID
Definition: pg_type.h:525
pg_time_t time
Definition: pg_control.h:128
ControlFileData * get_controlfile(const char *DataDir, const char *progname, bool *crc_ok_p)
#define INT4OID
Definition: pg_type.h:316
uint32 pg_control_version
Definition: pg_control.h:121
HeapTuple heap_form_tuple(TupleDesc tupleDescriptor, Datum *values, bool *isnull)
Definition: heaptuple.c:695
#define ERROR
Definition: elog.h:43
uint64 system_identifier
Definition: pg_control.h:106
#define TimestampTzGetDatum(X)
Definition: timestamp.h:32
TupleDesc BlessTupleDesc(TupleDesc tupdesc)
Definition: execTuples.c:1032
Datum Int64GetDatum(int64 X)
Definition: fmgr.c:1791
void TupleDescInitEntry(TupleDesc desc, AttrNumber attributeNumber, const char *attributeName, Oid oidtypeid, int32 typmod, int attdim)
Definition: tupdesc.c:505
#define ereport(elevel, rest)
Definition: elog.h:122
uintptr_t Datum
Definition: postgres.h:372
#define PG_RETURN_DATUM(x)
Definition: fmgr.h:313
TimestampTz time_t_to_timestamptz(pg_time_t tm)
Definition: timestamp.c:1670
static ControlFileData * ControlFile
Definition: xlog.c:715
#define INT8OID
Definition: pg_type.h:304
uint32 catalog_version_no
Definition: pg_control.h:122
#define HeapTupleGetDatum(tuple)
Definition: funcapi.h:222
TupleDesc CreateTemplateTupleDesc(int natts, bool hasoid)
Definition: tupdesc.c:43
static Datum values[MAXATTR]
Definition: bootstrap.c:164
#define Int32GetDatum(X)
Definition: postgres.h:485
int errmsg(const char *fmt,...)
Definition: elog.c:797
char * DataDir
Definition: globals.c:60
int16 AttrNumber
Definition: attnum.h:21