PostgreSQL Source Code  git master
pg_controldata.c File Reference
#include "postgres.h"
#include "access/htup_details.h"
#include "access/transam.h"
#include "access/xlog.h"
#include "access/xlog_internal.h"
#include "catalog/pg_control.h"
#include "catalog/pg_type.h"
#include "common/controldata_utils.h"
#include "funcapi.h"
#include "miscadmin.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

◆ pg_control_checkpoint()

Datum pg_control_checkpoint ( PG_FUNCTION_ARGS  )

Definition at line 80 of file pg_controldata.c.

81 {
82  Datum values[18];
83  bool nulls[18];
84  TupleDesc tupdesc;
85  HeapTuple htup;
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  tupdesc = CreateTemplateTupleDesc(18);
96  TupleDescInitEntry(tupdesc, (AttrNumber) 1, "checkpoint_lsn",
97  PG_LSNOID, -1, 0);
98  TupleDescInitEntry(tupdesc, (AttrNumber) 2, "redo_lsn",
99  PG_LSNOID, -1, 0);
100  TupleDescInitEntry(tupdesc, (AttrNumber) 3, "redo_wal_file",
101  TEXTOID, -1, 0);
102  TupleDescInitEntry(tupdesc, (AttrNumber) 4, "timeline_id",
103  INT4OID, -1, 0);
104  TupleDescInitEntry(tupdesc, (AttrNumber) 5, "prev_timeline_id",
105  INT4OID, -1, 0);
106  TupleDescInitEntry(tupdesc, (AttrNumber) 6, "full_page_writes",
107  BOOLOID, -1, 0);
108  TupleDescInitEntry(tupdesc, (AttrNumber) 7, "next_xid",
109  TEXTOID, -1, 0);
110  TupleDescInitEntry(tupdesc, (AttrNumber) 8, "next_oid",
111  OIDOID, -1, 0);
112  TupleDescInitEntry(tupdesc, (AttrNumber) 9, "next_multixact_id",
113  XIDOID, -1, 0);
114  TupleDescInitEntry(tupdesc, (AttrNumber) 10, "next_multi_offset",
115  XIDOID, -1, 0);
116  TupleDescInitEntry(tupdesc, (AttrNumber) 11, "oldest_xid",
117  XIDOID, -1, 0);
118  TupleDescInitEntry(tupdesc, (AttrNumber) 12, "oldest_xid_dbid",
119  OIDOID, -1, 0);
120  TupleDescInitEntry(tupdesc, (AttrNumber) 13, "oldest_active_xid",
121  XIDOID, -1, 0);
122  TupleDescInitEntry(tupdesc, (AttrNumber) 14, "oldest_multi_xid",
123  XIDOID, -1, 0);
124  TupleDescInitEntry(tupdesc, (AttrNumber) 15, "oldest_multi_dbid",
125  OIDOID, -1, 0);
126  TupleDescInitEntry(tupdesc, (AttrNumber) 16, "oldest_commit_ts_xid",
127  XIDOID, -1, 0);
128  TupleDescInitEntry(tupdesc, (AttrNumber) 17, "newest_commit_ts_xid",
129  XIDOID, -1, 0);
130  TupleDescInitEntry(tupdesc, (AttrNumber) 18, "checkpoint_time",
131  TIMESTAMPTZOID, -1, 0);
132  tupdesc = BlessTupleDesc(tupdesc);
133 
134  /* Read the control file. */
135  ControlFile = get_controlfile(DataDir, &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  */
146  segno, wal_segment_size);
147 
148  /* Populate the values and null arrays */
150  nulls[0] = false;
151 
153  nulls[1] = false;
154 
155  values[2] = CStringGetTextDatum(xlogfilename);
156  nulls[2] = false;
157 
159  nulls[3] = false;
160 
162  nulls[4] = false;
163 
165  nulls[5] = false;
166 
167  values[6] = CStringGetTextDatum(psprintf("%u:%u",
170  nulls[6] = false;
171 
173  nulls[7] = false;
174 
176  nulls[8] = false;
177 
179  nulls[9] = false;
180 
182  nulls[10] = false;
183 
185  nulls[11] = false;
186 
188  nulls[12] = false;
189 
191  nulls[13] = false;
192 
194  nulls[14] = false;
195 
197  nulls[15] = false;
198 
200  nulls[16] = false;
201 
203  nulls[17] = false;
204 
205  htup = heap_form_tuple(tupdesc, values, nulls);
206 
208 }
int16 AttrNumber
Definition: attnum.h:21
TimestampTz time_t_to_timestamptz(pg_time_t tm)
Definition: timestamp.c:1740
static Datum values[MAXATTR]
Definition: bootstrap.c:156
#define CStringGetTextDatum(s)
Definition: builtins.h:85
ControlFileData * get_controlfile(const char *DataDir, bool *crc_ok_p)
int errmsg(const char *fmt,...)
Definition: elog.c:906
#define ERROR
Definition: elog.h:35
#define ereport(elevel,...)
Definition: elog.h:145
TupleDesc BlessTupleDesc(TupleDesc tupdesc)
Definition: execTuples.c:2071
#define PG_RETURN_DATUM(x)
Definition: fmgr.h:353
static Datum HeapTupleGetDatum(const HeapTupleData *tuple)
Definition: funcapi.h:230
char * DataDir
Definition: globals.c:66
HeapTuple heap_form_tuple(TupleDesc tupleDescriptor, Datum *values, bool *isnull)
Definition: heaptuple.c:1020
static Datum LSNGetDatum(XLogRecPtr X)
Definition: pg_lsn.h:28
static Datum TransactionIdGetDatum(TransactionId X)
Definition: postgres.h:620
uintptr_t Datum
Definition: postgres.h:412
static Datum BoolGetDatum(bool X)
Definition: postgres.h:450
static Datum ObjectIdGetDatum(Oid X)
Definition: postgres.h:600
static Datum Int32GetDatum(int32 X)
Definition: postgres.h:560
char * psprintf(const char *fmt,...)
Definition: psprintf.c:46
Oid oldestMultiDB
Definition: pg_control.h:50
MultiXactId oldestMulti
Definition: pg_control.h:49
MultiXactOffset nextMultiOffset
Definition: pg_control.h:46
TransactionId newestCommitTsXid
Definition: pg_control.h:54
TransactionId oldestXid
Definition: pg_control.h:47
TimeLineID PrevTimeLineID
Definition: pg_control.h:40
TimeLineID ThisTimeLineID
Definition: pg_control.h:39
Oid nextOid
Definition: pg_control.h:44
TransactionId oldestActiveXid
Definition: pg_control.h:63
bool fullPageWrites
Definition: pg_control.h:42
MultiXactId nextMulti
Definition: pg_control.h:45
FullTransactionId nextXid
Definition: pg_control.h:43
TransactionId oldestCommitTsXid
Definition: pg_control.h:52
pg_time_t time
Definition: pg_control.h:51
XLogRecPtr redo
Definition: pg_control.h:37
Oid oldestXidDB
Definition: pg_control.h:48
CheckPoint checkPointCopy
Definition: pg_control.h:133
XLogRecPtr checkPoint
Definition: pg_control.h:131
#define EpochFromFullTransactionId(x)
Definition: transam.h:47
#define XidFromFullTransactionId(x)
Definition: transam.h:48
TupleDesc CreateTemplateTupleDesc(int natts)
Definition: tupdesc.c:45
void TupleDescInitEntry(TupleDesc desc, AttrNumber attributeNumber, const char *attributeName, Oid oidtypeid, int32 typmod, int attdim)
Definition: tupdesc.c:583
static Datum TimestampTzGetDatum(TimestampTz X)
Definition: timestamp.h:52
int wal_segment_size
Definition: xlog.c:146
static ControlFileData * ControlFile
Definition: xlog.c:570
#define MAXFNAMELEN
#define XLByteToSeg(xlrp, logSegNo, wal_segsz_bytes)
static void XLogFileName(char *fname, TimeLineID tli, XLogSegNo logSegNo, int wal_segsz_bytes)
uint64 XLogSegNo
Definition: xlogdefs.h:48

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

◆ pg_control_init()

Datum pg_control_init ( PG_FUNCTION_ARGS  )

Definition at line 264 of file pg_controldata.c.

265 {
266  Datum values[11];
267  bool nulls[11];
268  TupleDesc tupdesc;
269  HeapTuple htup;
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  tupdesc = CreateTemplateTupleDesc(11);
278  TupleDescInitEntry(tupdesc, (AttrNumber) 1, "max_data_alignment",
279  INT4OID, -1, 0);
280  TupleDescInitEntry(tupdesc, (AttrNumber) 2, "database_block_size",
281  INT4OID, -1, 0);
282  TupleDescInitEntry(tupdesc, (AttrNumber) 3, "blocks_per_segment",
283  INT4OID, -1, 0);
284  TupleDescInitEntry(tupdesc, (AttrNumber) 4, "wal_block_size",
285  INT4OID, -1, 0);
286  TupleDescInitEntry(tupdesc, (AttrNumber) 5, "bytes_per_wal_segment",
287  INT4OID, -1, 0);
288  TupleDescInitEntry(tupdesc, (AttrNumber) 6, "max_identifier_length",
289  INT4OID, -1, 0);
290  TupleDescInitEntry(tupdesc, (AttrNumber) 7, "max_index_columns",
291  INT4OID, -1, 0);
292  TupleDescInitEntry(tupdesc, (AttrNumber) 8, "max_toast_chunk_size",
293  INT4OID, -1, 0);
294  TupleDescInitEntry(tupdesc, (AttrNumber) 9, "large_object_chunk_size",
295  INT4OID, -1, 0);
296  TupleDescInitEntry(tupdesc, (AttrNumber) 10, "float8_pass_by_value",
297  BOOLOID, -1, 0);
298  TupleDescInitEntry(tupdesc, (AttrNumber) 11, "data_page_checksum_version",
299  INT4OID, -1, 0);
300  tupdesc = BlessTupleDesc(tupdesc);
301 
302  /* read the control file */
303  ControlFile = get_controlfile(DataDir, &crc_ok);
304  if (!crc_ok)
305  ereport(ERROR,
306  (errmsg("calculated CRC checksum does not match value stored in file")));
307 
309  nulls[0] = false;
310 
312  nulls[1] = false;
313 
315  nulls[2] = false;
316 
318  nulls[3] = false;
319 
321  nulls[4] = false;
322 
324  nulls[5] = false;
325 
327  nulls[6] = false;
328 
330  nulls[7] = false;
331 
333  nulls[8] = false;
334 
336  nulls[9] = false;
337 
339  nulls[10] = false;
340 
341  htup = heap_form_tuple(tupdesc, values, nulls);
342 
344 }
uint32 xlog_seg_size
Definition: pg_control.h:209
uint32 nameDataLen
Definition: pg_control.h:211
uint32 data_checksum_version
Definition: pg_control.h:220
uint32 indexMaxKeys
Definition: pg_control.h:212
uint32 relseg_size
Definition: pg_control.h:206
uint32 xlog_blcksz
Definition: pg_control.h:208
uint32 loblksize
Definition: pg_control.h:215
uint32 toast_max_chunk_size
Definition: pg_control.h:214

References ControlFileData::blcksz, BlessTupleDesc(), BoolGetDatum(), ControlFile, CreateTemplateTupleDesc(), ControlFileData::data_checksum_version, DataDir, ereport, errmsg(), ERROR, ControlFileData::float8ByVal, get_controlfile(), heap_form_tuple(), HeapTupleGetDatum(), ControlFileData::indexMaxKeys, Int32GetDatum(), 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.

◆ pg_control_recovery()

Datum pg_control_recovery ( PG_FUNCTION_ARGS  )

Definition at line 211 of file pg_controldata.c.

212 {
213  Datum values[5];
214  bool nulls[5];
215  TupleDesc tupdesc;
216  HeapTuple htup;
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  tupdesc = CreateTemplateTupleDesc(5);
225  TupleDescInitEntry(tupdesc, (AttrNumber) 1, "min_recovery_end_lsn",
226  PG_LSNOID, -1, 0);
227  TupleDescInitEntry(tupdesc, (AttrNumber) 2, "min_recovery_end_timeline",
228  INT4OID, -1, 0);
229  TupleDescInitEntry(tupdesc, (AttrNumber) 3, "backup_start_lsn",
230  PG_LSNOID, -1, 0);
231  TupleDescInitEntry(tupdesc, (AttrNumber) 4, "backup_end_lsn",
232  PG_LSNOID, -1, 0);
233  TupleDescInitEntry(tupdesc, (AttrNumber) 5, "end_of_backup_record_required",
234  BOOLOID, -1, 0);
235  tupdesc = BlessTupleDesc(tupdesc);
236 
237  /* read the control file */
238  ControlFile = get_controlfile(DataDir, &crc_ok);
239  if (!crc_ok)
240  ereport(ERROR,
241  (errmsg("calculated CRC checksum does not match value stored in file")));
242 
244  nulls[0] = false;
245 
247  nulls[1] = false;
248 
250  nulls[2] = false;
251 
253  nulls[3] = false;
254 
256  nulls[4] = false;
257 
258  htup = heap_form_tuple(tupdesc, values, nulls);
259 
261 }
XLogRecPtr backupStartPoint
Definition: pg_control.h:168
bool backupEndRequired
Definition: pg_control.h:170
XLogRecPtr backupEndPoint
Definition: pg_control.h:169
XLogRecPtr minRecoveryPoint
Definition: pg_control.h:166
TimeLineID minRecoveryPointTLI
Definition: pg_control.h:167

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

◆ pg_control_system()

Datum pg_control_system ( PG_FUNCTION_ARGS  )

Definition at line 32 of file pg_controldata.c.

33 {
34  Datum values[4];
35  bool nulls[4];
36  TupleDesc tupdesc;
37  HeapTuple htup;
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  tupdesc = CreateTemplateTupleDesc(4);
46  TupleDescInitEntry(tupdesc, (AttrNumber) 1, "pg_control_version",
47  INT4OID, -1, 0);
48  TupleDescInitEntry(tupdesc, (AttrNumber) 2, "catalog_version_no",
49  INT4OID, -1, 0);
50  TupleDescInitEntry(tupdesc, (AttrNumber) 3, "system_identifier",
51  INT8OID, -1, 0);
52  TupleDescInitEntry(tupdesc, (AttrNumber) 4, "pg_control_last_modified",
53  TIMESTAMPTZOID, -1, 0);
54  tupdesc = BlessTupleDesc(tupdesc);
55 
56  /* read the control file */
58  if (!crc_ok)
59  ereport(ERROR,
60  (errmsg("calculated CRC checksum does not match value stored in file")));
61 
63  nulls[0] = false;
64 
66  nulls[1] = false;
67 
69  nulls[2] = false;
70 
72  nulls[3] = false;
73 
74  htup = heap_form_tuple(tupdesc, values, nulls);
75 
77 }
Datum Int64GetDatum(int64 X)
Definition: fmgr.c:1683
uint32 pg_control_version
Definition: pg_control.h:123
pg_time_t time
Definition: pg_control.h:130
uint64 system_identifier
Definition: pg_control.h:108
uint32 catalog_version_no
Definition: pg_control.h:124

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