4
* reads the data from $PGDATA/global/pg_control
6
* copyright (c) Oliver Elphick <olly@lfix.co.uk>, 2001;
9
* $PostgreSQL: pgsql/src/bin/pg_controldata/pg_controldata.c,v 1.20 2004-09-23 00:47:44 neilc Exp $
18
#include "catalog/pg_control.h"
20
#define _(x) gettext((x))
24
usage(const char *progname)
26
printf(_("%s displays control information of a PostgreSQL database cluster.\n\n"), progname);
31
" %s [OPTION] [DATADIR]\n\n"
33
" --help show this help, then exit\n"
34
" --version output version information, then exit\n"
38
printf(_("\nIf no data directory (DATADIR) is specified, "
39
"the environment variable PGDATA\nis used.\n\n"));
40
printf(_("Report bugs to <pgsql-bugs@postgresql.org>.\n"));
45
dbState(DBState state)
50
return _("starting up");
52
return _("shut down");
54
return _("shutting down");
56
return _("in recovery");
57
case DB_IN_PRODUCTION:
58
return _("in production");
60
return _("unrecognized status code");
65
main(int argc, char *argv[])
67
ControlFileData ControlFile;
69
char ControlFilePath[MAXPGPATH];
72
char pgctime_str[128];
73
char ckpttime_str[128];
74
char sysident_str[32];
75
char *strftime_fmt = "%c";
78
set_pglocale_pgservice(argv[0], "pg_controldata");
80
progname = get_progname(argv[0]);
84
if (strcmp(argv[1], "--help") == 0 || strcmp(argv[1], "-?") == 0)
89
if (strcmp(argv[1], "--version") == 0 || strcmp(argv[1], "-V") == 0)
91
puts("pg_controldata (PostgreSQL) " PG_VERSION);
99
DataDir = getenv("PGDATA");
102
fprintf(stderr, _("%s: no data directory specified\n"), progname);
103
fprintf(stderr, _("Try \"%s --help\" for more information.\n"), progname);
107
snprintf(ControlFilePath, MAXPGPATH, "%s/global/pg_control", DataDir);
109
if ((fd = open(ControlFilePath, O_RDONLY)) == -1)
111
fprintf(stderr, _("%s: could not open file \"%s\" for reading: %s\n"),
112
progname, ControlFilePath, strerror(errno));
116
if (read(fd, &ControlFile, sizeof(ControlFileData)) != sizeof(ControlFileData))
118
fprintf(stderr, _("%s: could not read file \"%s\": %s\n"),
119
progname, ControlFilePath, strerror(errno));
127
(char *) &ControlFile + sizeof(crc64),
128
sizeof(ControlFileData) - sizeof(crc64));
131
if (!EQ_CRC64(crc, ControlFile.crc))
132
printf(_("WARNING: Calculated CRC checksum does not match value stored in file.\n"
133
"Either the file is corrupt, or it has a different layout than this program\n"
134
"is expecting. The results below are untrustworthy.\n\n"));
137
* Use variable for format to suppress overly-anal-retentive gcc
140
strftime(pgctime_str, sizeof(pgctime_str), strftime_fmt,
141
localtime(&(ControlFile.time)));
142
strftime(ckpttime_str, sizeof(ckpttime_str), strftime_fmt,
143
localtime(&(ControlFile.checkPointCopy.time)));
146
* Format system_identifier separately to keep platform-dependent
147
* format code out of the translatable message string.
149
snprintf(sysident_str, sizeof(sysident_str), UINT64_FORMAT,
150
ControlFile.system_identifier);
152
printf(_("pg_control version number: %u\n"), ControlFile.pg_control_version);
153
printf(_("Catalog version number: %u\n"), ControlFile.catalog_version_no);
154
printf(_("Database system identifier: %s\n"), sysident_str);
155
printf(_("Database cluster state: %s\n"), dbState(ControlFile.state));
156
printf(_("pg_control last modified: %s\n"), pgctime_str);
157
printf(_("Current log file ID: %u\n"), ControlFile.logId);
158
printf(_("Next log file segment: %u\n"), ControlFile.logSeg);
159
printf(_("Latest checkpoint location: %X/%X\n"),
160
ControlFile.checkPoint.xlogid, ControlFile.checkPoint.xrecoff);
161
printf(_("Prior checkpoint location: %X/%X\n"),
162
ControlFile.prevCheckPoint.xlogid, ControlFile.prevCheckPoint.xrecoff);
163
printf(_("Latest checkpoint's REDO location: %X/%X\n"),
164
ControlFile.checkPointCopy.redo.xlogid, ControlFile.checkPointCopy.redo.xrecoff);
165
printf(_("Latest checkpoint's UNDO location: %X/%X\n"),
166
ControlFile.checkPointCopy.undo.xlogid, ControlFile.checkPointCopy.undo.xrecoff);
167
printf(_("Latest checkpoint's TimeLineID: %u\n"), ControlFile.checkPointCopy.ThisTimeLineID);
168
printf(_("Latest checkpoint's NextXID: %u\n"), ControlFile.checkPointCopy.nextXid);
169
printf(_("Latest checkpoint's NextOID: %u\n"), ControlFile.checkPointCopy.nextOid);
170
printf(_("Time of latest checkpoint: %s\n"), ckpttime_str);
171
printf(_("Database block size: %u\n"), ControlFile.blcksz);
172
printf(_("Blocks per segment of large relation: %u\n"), ControlFile.relseg_size);
173
printf(_("Bytes per WAL segment: %u\n"), ControlFile.xlog_seg_size);
174
printf(_("Maximum length of identifiers: %u\n"), ControlFile.nameDataLen);
175
printf(_("Maximum number of function arguments: %u\n"), ControlFile.funcMaxArgs);
176
printf(_("Date/time type storage: %s\n"),
177
(ControlFile.enableIntTimes ? _("64-bit integers") : _("floating-point numbers")));
178
printf(_("Maximum length of locale name: %u\n"), ControlFile.localeBuflen);
179
printf(_("LC_COLLATE: %s\n"), ControlFile.lc_collate);
180
printf(_("LC_CTYPE: %s\n"), ControlFile.lc_ctype);