PostgreSQL Source Code git master
Loading...
Searching...
No Matches
pg_controldata.c
Go to the documentation of this file.
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-2026, 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"
22#include "catalog/pg_control.h"
24#include "funcapi.h"
25#include "miscadmin.h"
26#include "storage/lwlock.h"
27#include "utils/builtins.h"
28#include "utils/pg_lsn.h"
29#include "utils/timestamp.h"
30
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 */
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}
68
71{
72 Datum values[19];
73 bool nulls[19];
74 TupleDesc tupdesc;
75 HeapTuple htup;
77 XLogSegNo segno;
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. */
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
108 nulls[2] = false;
109
111 nulls[3] = false;
112
114 nulls[4] = false;
115
117 nulls[5] = false;
118
120 nulls[6] = false;
121
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
158 nulls[18] = false;
159
160 htup = heap_form_tuple(tupdesc, values, nulls);
161
163}
164
165Datum
167{
168 Datum values[5];
169 bool nulls[5];
170 TupleDesc tupdesc;
171 HeapTuple htup;
173 bool crc_ok;
174
175 if (get_call_result_type(fcinfo, NULL, &tupdesc) != TYPEFUNC_COMPOSITE)
176 elog(ERROR, "return type must be a row type");
177
178 /* read the control file */
182 if (!crc_ok)
184 (errmsg("calculated CRC checksum does not match value stored in file")));
185
187 nulls[0] = false;
188
190 nulls[1] = false;
191
193 nulls[2] = false;
194
196 nulls[3] = false;
197
199 nulls[4] = false;
200
201 htup = heap_form_tuple(tupdesc, values, nulls);
202
204}
205
206Datum
208{
209 Datum values[12];
210 bool nulls[12];
211 TupleDesc tupdesc;
212 HeapTuple htup;
214 bool crc_ok;
215
216 if (get_call_result_type(fcinfo, NULL, &tupdesc) != TYPEFUNC_COMPOSITE)
217 elog(ERROR, "return type must be a row type");
218
219 /* read the control file */
223 if (!crc_ok)
225 (errmsg("calculated CRC checksum does not match value stored in file")));
226
228 nulls[0] = false;
229
231 nulls[1] = false;
232
234 nulls[2] = false;
235
237 nulls[3] = false;
238
240 nulls[4] = false;
241
243 nulls[5] = false;
244
246 nulls[6] = false;
247
249 nulls[7] = false;
250
252 nulls[8] = false;
253
255 nulls[9] = false;
256
258 nulls[10] = false;
259
261 nulls[11] = false;
262
263 htup = heap_form_tuple(tupdesc, values, nulls);
264
266}
TimestampTz time_t_to_timestamptz(pg_time_t tm)
Definition timestamp.c:1828
Datum pg_control_system(PG_FUNCTION_ARGS)
Datum pg_control_init(PG_FUNCTION_ARGS)
Datum pg_control_recovery(PG_FUNCTION_ARGS)
Datum pg_control_checkpoint(PG_FUNCTION_ARGS)
static Datum values[MAXATTR]
Definition bootstrap.c:190
#define CStringGetTextDatum(s)
Definition builtins.h:98
ControlFileData * get_controlfile(const char *DataDir, bool *crc_ok_p)
#define ERROR
Definition elog.h:40
#define elog(elevel,...)
Definition elog.h:228
#define ereport(elevel,...)
Definition elog.h:152
#define PG_RETURN_DATUM(x)
Definition fmgr.h:354
#define PG_FUNCTION_ARGS
Definition fmgr.h:193
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:73
HeapTuple heap_form_tuple(TupleDesc tupleDescriptor, const Datum *values, const bool *isnull)
Definition heaptuple.c:1025
bool LWLockAcquire(LWLock *lock, LWLockMode mode)
Definition lwlock.c:1150
void LWLockRelease(LWLock *lock)
Definition lwlock.c:1767
@ LW_SHARED
Definition lwlock.h:105
static char * errmsg
static Datum LSNGetDatum(XLogRecPtr X)
Definition pg_lsn.h:31
static Datum Int64GetDatum(int64 X)
Definition postgres.h:426
static Datum TransactionIdGetDatum(TransactionId X)
Definition postgres.h:292
static Datum BoolGetDatum(bool X)
Definition postgres.h:112
static Datum ObjectIdGetDatum(Oid X)
Definition postgres.h:252
uint64_t Datum
Definition postgres.h:70
static Datum Int32GetDatum(int32 X)
Definition postgres.h:212
static int fb(int x)
char * psprintf(const char *fmt,...)
Definition psprintf.c:43
Oid oldestMultiDB
Definition pg_control.h:52
MultiXactId oldestMulti
Definition pg_control.h:51
MultiXactOffset nextMultiOffset
Definition pg_control.h:48
TransactionId newestCommitTsXid
Definition pg_control.h:56
TransactionId oldestXid
Definition pg_control.h:49
TimeLineID PrevTimeLineID
Definition pg_control.h:40
TimeLineID ThisTimeLineID
Definition pg_control.h:39
TransactionId oldestActiveXid
Definition pg_control.h:65
bool fullPageWrites
Definition pg_control.h:42
MultiXactId nextMulti
Definition pg_control.h:47
FullTransactionId nextXid
Definition pg_control.h:45
TransactionId oldestCommitTsXid
Definition pg_control.h:54
pg_time_t time
Definition pg_control.h:53
bool logicalDecodingEnabled
Definition pg_control.h:44
XLogRecPtr redo
Definition pg_control.h:37
Oid oldestXidDB
Definition pg_control.h:50
uint32 pg_control_version
Definition pg_control.h:133
uint32 xlog_seg_size
Definition pg_control.h:221
XLogRecPtr backupStartPoint
Definition pg_control.h:178
CheckPoint checkPointCopy
Definition pg_control.h:143
XLogRecPtr backupEndPoint
Definition pg_control.h:179
XLogRecPtr minRecoveryPoint
Definition pg_control.h:176
uint32 data_checksum_version
Definition pg_control.h:232
uint32 indexMaxKeys
Definition pg_control.h:224
pg_time_t time
Definition pg_control.h:140
bool default_char_signedness
Definition pg_control.h:238
XLogRecPtr checkPoint
Definition pg_control.h:141
uint64 system_identifier
Definition pg_control.h:118
uint32 catalog_version_no
Definition pg_control.h:134
TimeLineID minRecoveryPointTLI
Definition pg_control.h:177
uint32 toast_max_chunk_size
Definition pg_control.h:226
#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:150
static ControlFileData * ControlFile
Definition xlog.c:584
#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:52