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 <time.h>
#include "access/xlog.h"
#include "access/xlog_internal.h"
#include "catalog/pg_control.h"
#include "common/controldata_utils.h"
#include "pg_getopt.h"
Include dependency graph for pg_controldata.c:

Go to the source code of this file.

Macros

#define FRONTEND   1
 

Functions

static void usage (const char *progname)
 
static const char * dbState (DBState state)
 
static const char * wal_level_str (WalLevel wal_level)
 
int main (int argc, char *argv[])
 

Macro Definition Documentation

#define FRONTEND   1

Definition at line 17 of file pg_controldata.c.

Function Documentation

static const char* dbState ( DBState  state)
static

Definition at line 47 of file pg_controldata.c.

References _, DB_IN_ARCHIVE_RECOVERY, DB_IN_CRASH_RECOVERY, DB_IN_PRODUCTION, DB_SHUTDOWNED, DB_SHUTDOWNED_IN_RECOVERY, DB_SHUTDOWNING, and DB_STARTUP.

Referenced by main().

48 {
49  switch (state)
50  {
51  case DB_STARTUP:
52  return _("starting up");
53  case DB_SHUTDOWNED:
54  return _("shut down");
56  return _("shut down in recovery");
57  case DB_SHUTDOWNING:
58  return _("shutting down");
60  return _("in crash recovery");
62  return _("in archive recovery");
63  case DB_IN_PRODUCTION:
64  return _("in production");
65  }
66  return _("unrecognized status code");
67 }
Definition: regguts.h:298
#define _(x)
Definition: elog.c:84
int main ( int  argc,
char *  argv[] 
)

Definition at line 86 of file pg_controldata.c.

References _, ControlFileData::backupEndPoint, ControlFileData::backupEndRequired, ControlFileData::backupStartPoint, ControlFileData::blcksz, ControlFileData::catalog_version_no, ControlFileData::checkPoint, ControlFileData::checkPointCopy, ControlFile, ControlFileData::data_checksum_version, DataDir, dbState(), ControlFileData::float4ByVal, ControlFileData::float8ByVal, CheckPoint::fullPageWrites, get_controlfile(), get_progname(), getopt(), i, ControlFileData::indexMaxKeys, IsValidWalSegSize, ControlFileData::loblksize, ControlFileData::max_locks_per_xact, ControlFileData::max_prepared_xacts, ControlFileData::max_worker_processes, ControlFileData::maxAlign, ControlFileData::MaxConnections, MAXFNAMELEN, ControlFileData::minRecoveryPoint, ControlFileData::minRecoveryPointTLI, MOCK_AUTH_NONCE_LEN, ControlFileData::mock_authentication_nonce, ControlFileData::nameDataLen, CheckPoint::newestCommitTsXid, CheckPoint::nextMulti, CheckPoint::nextMultiOffset, CheckPoint::nextOid, CheckPoint::nextXid, CheckPoint::nextXidEpoch, CheckPoint::oldestActiveXid, CheckPoint::oldestCommitTsXid, CheckPoint::oldestMulti, CheckPoint::oldestMultiDB, CheckPoint::oldestXid, CheckPoint::oldestXidDB, optarg, optind, ControlFileData::pg_control_version, PG_TEXTDOMAIN, ControlFileData::prevCheckPoint, CheckPoint::PrevTimeLineID, progname, CheckPoint::redo, ControlFileData::relseg_size, set_pglocale_pgservice(), snprintf(), ControlFileData::state, ControlFileData::system_identifier, CheckPoint::ThisTimeLineID, CheckPoint::time, ControlFileData::time, ControlFileData::toast_max_chunk_size, ControlFileData::track_commit_timestamp, UINT64_FORMAT, ControlFileData::unloggedLSN, usage(), ControlFileData::wal_level, wal_level_str(), ControlFileData::wal_log_hints, WalSegSz, XLByteToSeg, ControlFileData::xlog_blcksz, ControlFileData::xlog_seg_size, and XLogFileName.

87 {
89  bool crc_ok;
90  char *DataDir = NULL;
91  time_t time_tmp;
92  char pgctime_str[128];
93  char ckpttime_str[128];
94  char sysident_str[32];
95  char mock_auth_nonce_str[MOCK_AUTH_NONCE_LEN * 2 + 1];
96  const char *strftime_fmt = "%c";
97  const char *progname;
98  XLogSegNo segno;
99  char xlogfilename[MAXFNAMELEN];
100  int c;
101  int i;
102  int WalSegSz;
103 
104  set_pglocale_pgservice(argv[0], PG_TEXTDOMAIN("pg_controldata"));
105 
106  progname = get_progname(argv[0]);
107 
108  if (argc > 1)
109  {
110  if (strcmp(argv[1], "--help") == 0 || strcmp(argv[1], "-?") == 0)
111  {
112  usage(progname);
113  exit(0);
114  }
115  if (strcmp(argv[1], "--version") == 0 || strcmp(argv[1], "-V") == 0)
116  {
117  puts("pg_controldata (PostgreSQL) " PG_VERSION);
118  exit(0);
119  }
120  }
121 
122  while ((c = getopt(argc, argv, "D:")) != -1)
123  {
124  switch (c)
125  {
126  case 'D':
127  DataDir = optarg;
128  break;
129 
130  default:
131  fprintf(stderr, _("Try \"%s --help\" for more information.\n"), progname);
132  exit(1);
133  }
134  }
135 
136  if (DataDir == NULL)
137  {
138  if (optind < argc)
139  DataDir = argv[optind++];
140  else
141  DataDir = getenv("PGDATA");
142  }
143 
144  /* Complain if any arguments remain */
145  if (optind < argc)
146  {
147  fprintf(stderr, _("%s: too many command-line arguments (first is \"%s\")\n"),
148  progname, argv[optind]);
149  fprintf(stderr, _("Try \"%s --help\" for more information.\n"),
150  progname);
151  exit(1);
152  }
153 
154  if (DataDir == NULL)
155  {
156  fprintf(stderr, _("%s: no data directory specified\n"), progname);
157  fprintf(stderr, _("Try \"%s --help\" for more information.\n"), progname);
158  exit(1);
159  }
160 
161  /* get a copy of the control file */
162  ControlFile = get_controlfile(DataDir, progname, &crc_ok);
163  if (!crc_ok)
164  printf(_("WARNING: Calculated CRC checksum does not match value stored in file.\n"
165  "Either the file is corrupt, or it has a different layout than this program\n"
166  "is expecting. The results below are untrustworthy.\n\n"));
167 
168  /* set wal segment size */
169  WalSegSz = ControlFile->xlog_seg_size;
170 
171  if (!IsValidWalSegSize(WalSegSz))
172  fprintf(stderr,
173  _("WARNING: WAL segment size specified, %d bytes, is not a power of two between 1MB and 1GB.\n"
174  "The file is corrupt and the results below are untrustworthy.\n"),
175  WalSegSz);
176 
177  /*
178  * This slightly-chintzy coding will work as long as the control file
179  * timestamps are within the range of time_t; that should be the case in
180  * all foreseeable circumstances, so we don't bother importing the
181  * backend's timezone library into pg_controldata.
182  *
183  * Use variable for format to suppress overly-anal-retentive gcc warning
184  * about %c
185  */
186  time_tmp = (time_t) ControlFile->time;
187  strftime(pgctime_str, sizeof(pgctime_str), strftime_fmt,
188  localtime(&time_tmp));
189  time_tmp = (time_t) ControlFile->checkPointCopy.time;
190  strftime(ckpttime_str, sizeof(ckpttime_str), strftime_fmt,
191  localtime(&time_tmp));
192 
193  /*
194  * Calculate name of the WAL file containing the latest checkpoint's REDO
195  * start point.
196  */
197  XLByteToSeg(ControlFile->checkPointCopy.redo, segno, WalSegSz);
198  XLogFileName(xlogfilename, ControlFile->checkPointCopy.ThisTimeLineID,
199  segno, WalSegSz);
200 
201  /*
202  * Format system_identifier and mock_authentication_nonce separately to
203  * keep platform-dependent format code out of the translatable message
204  * string.
205  */
206  snprintf(sysident_str, sizeof(sysident_str), UINT64_FORMAT,
207  ControlFile->system_identifier);
208  for (i = 0; i < MOCK_AUTH_NONCE_LEN; i++)
209  snprintf(&mock_auth_nonce_str[i * 2], 3, "%02x",
210  (unsigned char) ControlFile->mock_authentication_nonce[i]);
211 
212  printf(_("pg_control version number: %u\n"),
213  ControlFile->pg_control_version);
214  printf(_("Catalog version number: %u\n"),
215  ControlFile->catalog_version_no);
216  printf(_("Database system identifier: %s\n"),
217  sysident_str);
218  printf(_("Database cluster state: %s\n"),
219  dbState(ControlFile->state));
220  printf(_("pg_control last modified: %s\n"),
221  pgctime_str);
222  printf(_("Latest checkpoint location: %X/%X\n"),
223  (uint32) (ControlFile->checkPoint >> 32),
224  (uint32) ControlFile->checkPoint);
225  printf(_("Prior checkpoint location: %X/%X\n"),
226  (uint32) (ControlFile->prevCheckPoint >> 32),
227  (uint32) ControlFile->prevCheckPoint);
228  printf(_("Latest checkpoint's REDO location: %X/%X\n"),
229  (uint32) (ControlFile->checkPointCopy.redo >> 32),
230  (uint32) ControlFile->checkPointCopy.redo);
231  printf(_("Latest checkpoint's REDO WAL file: %s\n"),
232  xlogfilename);
233  printf(_("Latest checkpoint's TimeLineID: %u\n"),
234  ControlFile->checkPointCopy.ThisTimeLineID);
235  printf(_("Latest checkpoint's PrevTimeLineID: %u\n"),
236  ControlFile->checkPointCopy.PrevTimeLineID);
237  printf(_("Latest checkpoint's full_page_writes: %s\n"),
238  ControlFile->checkPointCopy.fullPageWrites ? _("on") : _("off"));
239  printf(_("Latest checkpoint's NextXID: %u:%u\n"),
240  ControlFile->checkPointCopy.nextXidEpoch,
241  ControlFile->checkPointCopy.nextXid);
242  printf(_("Latest checkpoint's NextOID: %u\n"),
243  ControlFile->checkPointCopy.nextOid);
244  printf(_("Latest checkpoint's NextMultiXactId: %u\n"),
245  ControlFile->checkPointCopy.nextMulti);
246  printf(_("Latest checkpoint's NextMultiOffset: %u\n"),
247  ControlFile->checkPointCopy.nextMultiOffset);
248  printf(_("Latest checkpoint's oldestXID: %u\n"),
249  ControlFile->checkPointCopy.oldestXid);
250  printf(_("Latest checkpoint's oldestXID's DB: %u\n"),
251  ControlFile->checkPointCopy.oldestXidDB);
252  printf(_("Latest checkpoint's oldestActiveXID: %u\n"),
253  ControlFile->checkPointCopy.oldestActiveXid);
254  printf(_("Latest checkpoint's oldestMultiXid: %u\n"),
255  ControlFile->checkPointCopy.oldestMulti);
256  printf(_("Latest checkpoint's oldestMulti's DB: %u\n"),
257  ControlFile->checkPointCopy.oldestMultiDB);
258  printf(_("Latest checkpoint's oldestCommitTsXid:%u\n"),
259  ControlFile->checkPointCopy.oldestCommitTsXid);
260  printf(_("Latest checkpoint's newestCommitTsXid:%u\n"),
261  ControlFile->checkPointCopy.newestCommitTsXid);
262  printf(_("Time of latest checkpoint: %s\n"),
263  ckpttime_str);
264  printf(_("Fake LSN counter for unlogged rels: %X/%X\n"),
265  (uint32) (ControlFile->unloggedLSN >> 32),
266  (uint32) ControlFile->unloggedLSN);
267  printf(_("Minimum recovery ending location: %X/%X\n"),
268  (uint32) (ControlFile->minRecoveryPoint >> 32),
269  (uint32) ControlFile->minRecoveryPoint);
270  printf(_("Min recovery ending loc's timeline: %u\n"),
271  ControlFile->minRecoveryPointTLI);
272  printf(_("Backup start location: %X/%X\n"),
273  (uint32) (ControlFile->backupStartPoint >> 32),
274  (uint32) ControlFile->backupStartPoint);
275  printf(_("Backup end location: %X/%X\n"),
276  (uint32) (ControlFile->backupEndPoint >> 32),
277  (uint32) ControlFile->backupEndPoint);
278  printf(_("End-of-backup record required: %s\n"),
279  ControlFile->backupEndRequired ? _("yes") : _("no"));
280  printf(_("wal_level setting: %s\n"),
281  wal_level_str(ControlFile->wal_level));
282  printf(_("wal_log_hints setting: %s\n"),
283  ControlFile->wal_log_hints ? _("on") : _("off"));
284  printf(_("max_connections setting: %d\n"),
285  ControlFile->MaxConnections);
286  printf(_("max_worker_processes setting: %d\n"),
287  ControlFile->max_worker_processes);
288  printf(_("max_prepared_xacts setting: %d\n"),
289  ControlFile->max_prepared_xacts);
290  printf(_("max_locks_per_xact setting: %d\n"),
291  ControlFile->max_locks_per_xact);
292  printf(_("track_commit_timestamp setting: %s\n"),
293  ControlFile->track_commit_timestamp ? _("on") : _("off"));
294  printf(_("Maximum data alignment: %u\n"),
295  ControlFile->maxAlign);
296  /* we don't print floatFormat since can't say much useful about it */
297  printf(_("Database block size: %u\n"),
298  ControlFile->blcksz);
299  printf(_("Blocks per segment of large relation: %u\n"),
300  ControlFile->relseg_size);
301  printf(_("WAL block size: %u\n"),
302  ControlFile->xlog_blcksz);
303  printf(_("Bytes per WAL segment: %u\n"),
304  ControlFile->xlog_seg_size);
305  printf(_("Maximum length of identifiers: %u\n"),
306  ControlFile->nameDataLen);
307  printf(_("Maximum columns in an index: %u\n"),
308  ControlFile->indexMaxKeys);
309  printf(_("Maximum size of a TOAST chunk: %u\n"),
310  ControlFile->toast_max_chunk_size);
311  printf(_("Size of a large-object chunk: %u\n"),
312  ControlFile->loblksize);
313  /* This is no longer configurable, but users may still expect to see it: */
314  printf(_("Date/time type storage: %s\n"),
315  _("64-bit integers"));
316  printf(_("Float4 argument passing: %s\n"),
317  (ControlFile->float4ByVal ? _("by value") : _("by reference")));
318  printf(_("Float8 argument passing: %s\n"),
319  (ControlFile->float8ByVal ? _("by value") : _("by reference")));
320  printf(_("Data page checksum version: %u\n"),
321  ControlFile->data_checksum_version);
322  printf(_("Mock authentication nonce: %s\n"),
323  mock_auth_nonce_str);
324  return 0;
325 }
#define IsValidWalSegSize(size)
Definition: xlog_internal.h:97
int max_locks_per_xact
Definition: pg_control.h:182
static const char * wal_level_str(WalLevel wal_level)
int max_prepared_xacts
Definition: pg_control.h:181
pg_time_t time
Definition: pg_control.h:128
TimeLineID minRecoveryPointTLI
Definition: pg_control.h:168
const char * get_progname(const char *argv0)
Definition: path.c:453
int max_worker_processes
Definition: pg_control.h:180
TransactionId oldestActiveXid
Definition: pg_control.h:63
ControlFileData * get_controlfile(const char *DataDir, const char *progname, bool *crc_ok_p)
static void usage(const char *progname)
uint32 nameDataLen
Definition: pg_control.h:211
MultiXactId oldestMulti
Definition: pg_control.h:49
TimeLineID PrevTimeLineID
Definition: pg_control.h:39
uint32 pg_control_version
Definition: pg_control.h:121
int snprintf(char *str, size_t count, const char *fmt,...) pg_attribute_printf(3
CheckPoint checkPointCopy
Definition: pg_control.h:132
uint32 xlog_blcksz
Definition: pg_control.h:208
TransactionId oldestXid
Definition: pg_control.h:47
const char * progname
Definition: pg_standby.c:37
TransactionId nextXid
Definition: pg_control.h:43
pg_time_t time
Definition: pg_control.h:51
int getopt(int nargc, char *const *nargv, const char *ostr)
Definition: getopt.c:72
#define MOCK_AUTH_NONCE_LEN
Definition: pg_control.h:27
bool backupEndRequired
Definition: pg_control.h:171
MultiXactOffset nextMultiOffset
Definition: pg_control.h:46
TransactionId oldestCommitTsXid
Definition: pg_control.h:52
uint32 xlog_seg_size
Definition: pg_control.h:209
int optind
Definition: getopt.c:51
uint64 system_identifier
Definition: pg_control.h:106
uint32 nextXidEpoch
Definition: pg_control.h:42
uint32 data_checksum_version
Definition: pg_control.h:222
char * c
XLogRecPtr unloggedLSN
Definition: pg_control.h:134
uint64 XLogSegNo
Definition: xlogdefs.h:34
unsigned int uint32
Definition: c.h:258
uint32 loblksize
Definition: pg_control.h:215
uint32 indexMaxKeys
Definition: pg_control.h:212
#define MAXFNAMELEN
TransactionId newestCommitTsXid
Definition: pg_control.h:54
#define PG_TEXTDOMAIN(domain)
Definition: c.h:1018
char mock_authentication_nonce[MOCK_AUTH_NONCE_LEN]
Definition: pg_control.h:229
Oid oldestMultiDB
Definition: pg_control.h:50
XLogRecPtr prevCheckPoint
Definition: pg_control.h:130
uint32 toast_max_chunk_size
Definition: pg_control.h:214
static ControlFileData * ControlFile
Definition: xlog.c:715
Oid nextOid
Definition: pg_control.h:44
XLogRecPtr backupEndPoint
Definition: pg_control.h:170
bool fullPageWrites
Definition: pg_control.h:41
bool track_commit_timestamp
Definition: pg_control.h:183
Oid oldestXidDB
Definition: pg_control.h:48
#define XLogFileName(fname, tli, logSegNo, wal_segsz_bytes)
MultiXactId nextMulti
Definition: pg_control.h:45
uint32 catalog_version_no
Definition: pg_control.h:122
int WalSegSz
Definition: pg_standby.c:39
TimeLineID ThisTimeLineID
Definition: pg_control.h:38
void set_pglocale_pgservice(const char *argv0, const char *app)
Definition: exec.c:550
char * optarg
Definition: getopt.c:53
int i
char * DataDir
Definition: globals.c:60
#define _(x)
Definition: elog.c:84
#define UINT64_FORMAT
Definition: c.h:301
static const char * dbState(DBState state)
XLogRecPtr backupStartPoint
Definition: pg_control.h:169
uint32 relseg_size
Definition: pg_control.h:206
XLogRecPtr checkPoint
Definition: pg_control.h:129
XLogRecPtr redo
Definition: pg_control.h:36
XLogRecPtr minRecoveryPoint
Definition: pg_control.h:167
#define XLByteToSeg(xlrp, logSegNo, wal_segsz_bytes)
static void usage ( const char *  progname)
static

Definition at line 31 of file pg_controldata.c.

References _.

Referenced by main().

32 {
33  printf(_("%s displays control information of a PostgreSQL database cluster.\n\n"), progname);
34  printf(_("Usage:\n"));
35  printf(_(" %s [OPTION] [DATADIR]\n"), progname);
36  printf(_("\nOptions:\n"));
37  printf(_(" [-D] DATADIR data directory\n"));
38  printf(_(" -V, --version output version information, then exit\n"));
39  printf(_(" -?, --help show this help, then exit\n"));
40  printf(_("\nIf no data directory (DATADIR) is specified, "
41  "the environment variable PGDATA\nis used.\n\n"));
42  printf(_("Report bugs to <pgsql-bugs@postgresql.org>.\n"));
43 }
const char * progname
Definition: pg_standby.c:37
#define _(x)
Definition: elog.c:84
static const char* wal_level_str ( WalLevel  wal_level)
static

Definition at line 70 of file pg_controldata.c.

References _, WAL_LEVEL_LOGICAL, WAL_LEVEL_MINIMAL, and WAL_LEVEL_REPLICA.

Referenced by main(), and xlog_desc().

71 {
72  switch (wal_level)
73  {
74  case WAL_LEVEL_MINIMAL:
75  return "minimal";
76  case WAL_LEVEL_REPLICA:
77  return "replica";
78  case WAL_LEVEL_LOGICAL:
79  return "logical";
80  }
81  return _("unrecognized wal_level");
82 }
int wal_level
Definition: xlog.c:104
#define _(x)
Definition: elog.c:84