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