PostgreSQL Source Code git master
All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
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 "common/controldata_utils.h"
#include "funcapi.h"
#include "miscadmin.h"
#include "storage/lwlock.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 70 of file pg_controldata.c.

71{
72 Datum values[18];
73 bool nulls[18];
74 TupleDesc tupdesc;
75 HeapTuple htup;
77 XLogSegNo segno;
78 char xlogfilename[MAXFNAMELEN];
79 bool crc_ok;
80
81 if (get_call_result_type(fcinfo, NULL, &tupdesc) != TYPEFUNC_COMPOSITE)
82 elog(ERROR, "return type must be a row type");
83
84 /* Read the control file. */
85 LWLockAcquire(ControlFileLock, LW_SHARED);
87 LWLockRelease(ControlFileLock);
88 if (!crc_ok)
90 (errmsg("calculated CRC checksum does not match value stored in file")));
91
92 /*
93 * Calculate name of the WAL file containing the latest checkpoint's REDO
94 * start point.
95 */
98 segno, wal_segment_size);
99
100 /* Populate the values and null arrays */
102 nulls[0] = false;
103
105 nulls[1] = false;
106
107 values[2] = CStringGetTextDatum(xlogfilename);
108 nulls[2] = false;
109
111 nulls[3] = false;
112
114 nulls[4] = false;
115
117 nulls[5] = false;
118
122 nulls[6] = false;
123
125 nulls[7] = false;
126
128 nulls[8] = false;
129
131 nulls[9] = false;
132
134 nulls[10] = false;
135
137 nulls[11] = false;
138
140 nulls[12] = false;
141
143 nulls[13] = false;
144
146 nulls[14] = false;
147
149 nulls[15] = false;
150
152 nulls[16] = false;
153
155 nulls[17] = false;
156
157 htup = heap_form_tuple(tupdesc, values, nulls);
158
160}
TimestampTz time_t_to_timestamptz(pg_time_t tm)
Definition: timestamp.c:1801
static Datum values[MAXATTR]
Definition: bootstrap.c:151
#define CStringGetTextDatum(s)
Definition: builtins.h:97
ControlFileData * get_controlfile(const char *DataDir, bool *crc_ok_p)
int errmsg(const char *fmt,...)
Definition: elog.c:1070
#define ERROR
Definition: elog.h:39
#define elog(elevel,...)
Definition: elog.h:225
#define ereport(elevel,...)
Definition: elog.h:149
#define PG_RETURN_DATUM(x)
Definition: fmgr.h:353
TypeFuncClass get_call_result_type(FunctionCallInfo fcinfo, Oid *resultTypeId, TupleDesc *resultTupleDesc)
Definition: funcapi.c:276
@ TYPEFUNC_COMPOSITE
Definition: funcapi.h:149
static Datum HeapTupleGetDatum(const HeapTupleData *tuple)
Definition: funcapi.h:230
char * DataDir
Definition: globals.c:70
HeapTuple heap_form_tuple(TupleDesc tupleDescriptor, const Datum *values, const bool *isnull)
Definition: heaptuple.c:1117
bool LWLockAcquire(LWLock *lock, LWLockMode mode)
Definition: lwlock.c:1168
void LWLockRelease(LWLock *lock)
Definition: lwlock.c:1781
@ LW_SHARED
Definition: lwlock.h:115
static Datum LSNGetDatum(XLogRecPtr X)
Definition: pg_lsn.h:28
static Datum TransactionIdGetDatum(TransactionId X)
Definition: postgres.h:272
uintptr_t Datum
Definition: postgres.h:64
static Datum BoolGetDatum(bool X)
Definition: postgres.h:102
static Datum ObjectIdGetDatum(Oid X)
Definition: postgres.h:252
static Datum Int32GetDatum(int32 X)
Definition: postgres.h:212
char * psprintf(const char *fmt,...)
Definition: psprintf.c:43
Oid oldestMultiDB
Definition: pg_control.h:51
MultiXactId oldestMulti
Definition: pg_control.h:50
MultiXactOffset nextMultiOffset
Definition: pg_control.h:47
TransactionId newestCommitTsXid
Definition: pg_control.h:55
TransactionId oldestXid
Definition: pg_control.h:48
TimeLineID PrevTimeLineID
Definition: pg_control.h:40
TimeLineID ThisTimeLineID
Definition: pg_control.h:39
Oid nextOid
Definition: pg_control.h:45
TransactionId oldestActiveXid
Definition: pg_control.h:64
bool fullPageWrites
Definition: pg_control.h:42
MultiXactId nextMulti
Definition: pg_control.h:46
FullTransactionId nextXid
Definition: pg_control.h:44
TransactionId oldestCommitTsXid
Definition: pg_control.h:53
pg_time_t time
Definition: pg_control.h:52
XLogRecPtr redo
Definition: pg_control.h:37
Oid oldestXidDB
Definition: pg_control.h:49
CheckPoint checkPointCopy
Definition: pg_control.h:135
XLogRecPtr checkPoint
Definition: pg_control.h:133
#define EpochFromFullTransactionId(x)
Definition: transam.h:47
#define XidFromFullTransactionId(x)
Definition: transam.h:48
static Datum TimestampTzGetDatum(TimestampTz X)
Definition: timestamp.h:52
int wal_segment_size
Definition: xlog.c:143
static ControlFileData * ControlFile
Definition: xlog.c:574
#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 BoolGetDatum(), ControlFileData::checkPoint, ControlFileData::checkPointCopy, ControlFile, CStringGetTextDatum, DataDir, elog, EpochFromFullTransactionId, ereport, errmsg(), ERROR, CheckPoint::fullPageWrites, get_call_result_type(), get_controlfile(), heap_form_tuple(), HeapTupleGetDatum(), Int32GetDatum(), LSNGetDatum(), LW_SHARED, LWLockAcquire(), LWLockRelease(), 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(), TYPEFUNC_COMPOSITE, values, wal_segment_size, XidFromFullTransactionId, XLByteToSeg, and XLogFileName().

◆ pg_control_init()

Datum pg_control_init ( PG_FUNCTION_ARGS  )

Definition at line 204 of file pg_controldata.c.

205{
206 Datum values[11];
207 bool nulls[11];
208 TupleDesc tupdesc;
209 HeapTuple htup;
211 bool crc_ok;
212
213 if (get_call_result_type(fcinfo, NULL, &tupdesc) != TYPEFUNC_COMPOSITE)
214 elog(ERROR, "return type must be a row type");
215
216 /* read the control file */
217 LWLockAcquire(ControlFileLock, LW_SHARED);
219 LWLockRelease(ControlFileLock);
220 if (!crc_ok)
222 (errmsg("calculated CRC checksum does not match value stored in file")));
223
225 nulls[0] = false;
226
228 nulls[1] = false;
229
231 nulls[2] = false;
232
234 nulls[3] = false;
235
237 nulls[4] = false;
238
240 nulls[5] = false;
241
243 nulls[6] = false;
244
246 nulls[7] = false;
247
249 nulls[8] = false;
250
252 nulls[9] = false;
253
255 nulls[10] = false;
256
257 htup = heap_form_tuple(tupdesc, values, nulls);
258
260}
uint32 xlog_seg_size
Definition: pg_control.h:211
uint32 nameDataLen
Definition: pg_control.h:213
uint32 data_checksum_version
Definition: pg_control.h:222
uint32 indexMaxKeys
Definition: pg_control.h:214
uint32 relseg_size
Definition: pg_control.h:208
uint32 xlog_blcksz
Definition: pg_control.h:210
uint32 loblksize
Definition: pg_control.h:217
uint32 toast_max_chunk_size
Definition: pg_control.h:216

References ControlFileData::blcksz, BoolGetDatum(), ControlFile, ControlFileData::data_checksum_version, DataDir, elog, ereport, errmsg(), ERROR, ControlFileData::float8ByVal, get_call_result_type(), get_controlfile(), heap_form_tuple(), HeapTupleGetDatum(), ControlFileData::indexMaxKeys, Int32GetDatum(), ControlFileData::loblksize, LW_SHARED, LWLockAcquire(), LWLockRelease(), ControlFileData::maxAlign, ControlFileData::nameDataLen, PG_RETURN_DATUM, ControlFileData::relseg_size, ControlFileData::toast_max_chunk_size, TYPEFUNC_COMPOSITE, values, ControlFileData::xlog_blcksz, and ControlFileData::xlog_seg_size.

◆ pg_control_recovery()

Datum pg_control_recovery ( PG_FUNCTION_ARGS  )

Definition at line 163 of file pg_controldata.c.

164{
165 Datum values[5];
166 bool nulls[5];
167 TupleDesc tupdesc;
168 HeapTuple htup;
170 bool crc_ok;
171
172 if (get_call_result_type(fcinfo, NULL, &tupdesc) != TYPEFUNC_COMPOSITE)
173 elog(ERROR, "return type must be a row type");
174
175 /* read the control file */
176 LWLockAcquire(ControlFileLock, LW_SHARED);
178 LWLockRelease(ControlFileLock);
179 if (!crc_ok)
181 (errmsg("calculated CRC checksum does not match value stored in file")));
182
184 nulls[0] = false;
185
187 nulls[1] = false;
188
190 nulls[2] = false;
191
193 nulls[3] = false;
194
196 nulls[4] = false;
197
198 htup = heap_form_tuple(tupdesc, values, nulls);
199
201}
XLogRecPtr backupStartPoint
Definition: pg_control.h:170
bool backupEndRequired
Definition: pg_control.h:172
XLogRecPtr backupEndPoint
Definition: pg_control.h:171
XLogRecPtr minRecoveryPoint
Definition: pg_control.h:168
TimeLineID minRecoveryPointTLI
Definition: pg_control.h:169

References ControlFileData::backupEndPoint, ControlFileData::backupEndRequired, ControlFileData::backupStartPoint, BoolGetDatum(), ControlFile, DataDir, elog, ereport, errmsg(), ERROR, get_call_result_type(), get_controlfile(), heap_form_tuple(), HeapTupleGetDatum(), Int32GetDatum(), LSNGetDatum(), LW_SHARED, LWLockAcquire(), LWLockRelease(), ControlFileData::minRecoveryPoint, ControlFileData::minRecoveryPointTLI, PG_RETURN_DATUM, TYPEFUNC_COMPOSITE, 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 if (get_call_result_type(fcinfo, NULL, &tupdesc) != TYPEFUNC_COMPOSITE)
42 elog(ERROR, "return type must be a row type");
43
44 /* read the control file */
45 LWLockAcquire(ControlFileLock, LW_SHARED);
47 LWLockRelease(ControlFileLock);
48 if (!crc_ok)
50 (errmsg("calculated CRC checksum does not match value stored in file")));
51
53 nulls[0] = false;
54
56 nulls[1] = false;
57
59 nulls[2] = false;
60
62 nulls[3] = false;
63
64 htup = heap_form_tuple(tupdesc, values, nulls);
65
67}
Datum Int64GetDatum(int64 X)
Definition: fmgr.c:1807
uint32 pg_control_version
Definition: pg_control.h:125
pg_time_t time
Definition: pg_control.h:132
uint64 system_identifier
Definition: pg_control.h:110
uint32 catalog_version_no
Definition: pg_control.h:126

References ControlFileData::catalog_version_no, ControlFile, DataDir, elog, ereport, errmsg(), ERROR, get_call_result_type(), get_controlfile(), heap_form_tuple(), HeapTupleGetDatum(), Int32GetDatum(), Int64GetDatum(), LW_SHARED, LWLockAcquire(), LWLockRelease(), ControlFileData::pg_control_version, PG_RETURN_DATUM, ControlFileData::system_identifier, ControlFileData::time, time_t_to_timestamptz(), TimestampTzGetDatum(), TYPEFUNC_COMPOSITE, and values.