Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit0c38315

Browse files
committed
Update for new pg_control format.
1 parent4d14fe0 commit0c38315

File tree

3 files changed

+124
-99
lines changed

3 files changed

+124
-99
lines changed

‎contrib/pg_controldata/Makefile

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,21 @@
11
#
2-
# $Header: /cvsroot/pgsql/contrib/pg_controldata/Attic/Makefile,v 1.2 2001/02/25 15:57:45 petere Exp $
2+
# $Header: /cvsroot/pgsql/contrib/pg_controldata/Attic/Makefile,v 1.3 2001/03/13 01:17:40 tgl Exp $
33
#
44

55
subdir = contrib/pg_controldata
66
top_builddir = ../..
77
include$(top_builddir)/src/Makefile.global
88

9-
overrideCPPFLAGS := -I$(libpq_srcdir)$(CPPFLAGS)
10-
11-
OBJS= pg_controldata.o
9+
OBJS= pg_controldata.o pg_crc.o
1210

1311
all: pg_controldata
1412

1513
pg_controldata:$(OBJS)
1614
$(CC)$(CFLAGS)$(OBJS)$(LDFLAGS)$(LIBS) -o$@
1715

16+
pg_crc.c:$(top_builddir)/src/backend/utils/hash/pg_crc.c
17+
rm -f$@&&$(LN_S)$<.
18+
1819
install: all installdirs
1920
$(INSTALL_PROGRAM) pg_controldata$(X)$(bindir)
2021
$(INSTALL_DATA) README.pg_controldata$(docdir)/contrib
@@ -26,7 +27,7 @@ uninstall:
2627
rm -f$(bindir)/pg_controldata$(X)$(docdir)/contrib/README.pg_controldata
2728

2829
cleandistcleanmaintainer-clean:
29-
rm -f pg_controldata$(X)$(OBJS)
30+
rm -f pg_controldata$(X)$(OBJS) pg_crc.c
3031

3132
dependdep:
3233
$(CC) -MM -MG$(CFLAGS)*.c> depend

‎contrib/pg_controldata/README.pg_controldata

Lines changed: 22 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,31 @@ I had a need to read such things as the backend locale and the catalog
22
version number from the current database, and couldn't find any existing
33
program to do that.
44

5-
The attached utility producesthisoutput:
5+
The attached utility produces output like this:
66

7-
linda:~$ pg_controldata
8-
Log file id: 0
9-
Log file segment: 5
10-
Last modified: Wed Feb 7 19:35:47 2001
7+
$ pg_controldata
8+
pg_control version number: 71
9+
Catalog version number: 200101061
10+
Database state: IN_PRODUCTION
11+
pg_control last modified: Sat Mar 10 00:07:55 2001
12+
Current log file id: 0
13+
Next log file segment: 9
14+
Latest checkpoint location: 0/88CAA20
15+
Prior checkpoint location: 0/70A5D48
16+
Latest checkpoint's REDO location: 0/88CAA20
17+
Latest checkpoint's UNDO location: 0/0
18+
Latest checkpoint's StartUpID: 22
19+
Latest checkpoint's NextXID: 4711
20+
Latest checkpoint's NextOID: 444704
21+
Time of latest checkpoint: Sat Mar 10 00:07:52 2001
1122
Database block size: 8192
1223
Blocks per segment of large relation: 131072
13-
Catalog version number: 200101061
14-
LC_COLLATE: en_GB
15-
LC_CTYPE: en_GB
16-
Log archive directory:
24+
LC_COLLATE: C
25+
LC_CTYPE: C
26+
27+
28+
To access the pg_control file, the program must be run as the Postgres user,
29+
and PGDATA must be set correctly in its environment.
1730

1831
--
1932
Oliver Elphick <olly@lfix.co.uk>

‎contrib/pg_controldata/pg_controldata.c

Lines changed: 96 additions & 85 deletions
Original file line numberDiff line numberDiff line change
@@ -1,87 +1,54 @@
1-
/* pg_controldata
1+
/*
2+
* pg_controldata
23
*
34
* reads the data from $PGDATA/global/pg_control
45
*
56
* copyright (c) Oliver Elphick <olly@lfix.co.uk>, 2001;
67
* licence: BSD
78
*
8-
*/
9+
* $Header: /cvsroot/pgsql/contrib/pg_controldata/Attic/pg_controldata.c,v 1.2 2001/03/13 01:17:40 tgl Exp $
10+
*/
11+
#include"postgres.h"
912

10-
#include<stdio.h>
11-
#include<stdlib.h>
1213
#include<unistd.h>
1314
#include<time.h>
1415
#include<sys/types.h>
1516
#include<sys/stat.h>
1617
#include<fcntl.h>
1718

19+
#include"catalog/pg_control.h"
1820

19-
typedefunsignedintuint32;
20-
21-
#include"config.h"
22-
#include"access/xlogdefs.h"
23-
24-
/*
25-
* #include "access/xlog.h"
26-
* #include "c.h"
27-
*/
28-
29-
/* The following definitions are extracted from access/xlog.h and its
30-
* recursive includes. There is too much initialisation needed if
31-
* they are included direct. Perhaps someone more knowledgeable can
32-
* fix that.
33-
*/
34-
typedefstructcrc64
35-
{
36-
uint32crc1;
37-
uint32crc2;
38-
}crc64;
39-
40-
#defineLOCALE_NAME_BUFLEN 128
4121

42-
typedefenumDBState
22+
staticconstchar*
23+
dbState(DBStatestate)
4324
{
44-
DB_STARTUP=0,
45-
DB_SHUTDOWNED,
46-
DB_SHUTDOWNING,
47-
DB_IN_RECOVERY,
48-
DB_IN_PRODUCTION
49-
}DBState;
25+
switch (state)
26+
{
27+
caseDB_STARTUP:
28+
return"STARTUP";
29+
caseDB_SHUTDOWNED:
30+
return"SHUTDOWNED";
31+
caseDB_SHUTDOWNING:
32+
return"SHUTDOWNING";
33+
caseDB_IN_RECOVERY:
34+
return"IN_RECOVERY";
35+
caseDB_IN_PRODUCTION:
36+
return"IN_PRODUCTION";
37+
}
38+
return"unrecognized status code";
39+
}
5040

5141

52-
typedefstructControlFileData
42+
int
43+
main()
5344
{
54-
crc64crc;
55-
uint32logId;/* current log file id */
56-
uint32logSeg;/* current log file segment (1-based) */
57-
struct
58-
XLogRecPtrcheckPoint;/* last check point record ptr */
59-
time_ttime;/* time stamp of last modification */
60-
DBStatestate;/* see enum above */
61-
62-
/*
63-
* this data is used to make sure that configuration of this DB is
64-
* compatible with the backend executable
65-
*/
66-
uint32blcksz;/* block size for this DB */
67-
uint32relseg_size;/* blocks per segment of large relation */
68-
uint32catalog_version_no;/* internal version number */
69-
/* active locales --- "C" if compiled without USE_LOCALE: */
70-
charlc_collate[LOCALE_NAME_BUFLEN];
71-
charlc_ctype[LOCALE_NAME_BUFLEN];
72-
73-
/*
74-
* important directory locations
75-
*/
76-
chararchdir[MAXPGPATH];/* where to move offline log files */
77-
}ControlFileData;
78-
79-
intmain() {
8045
ControlFileDataControlFile;
8146
intfd;
8247
charControlFilePath[MAXPGPATH];
8348
char*DataDir;
84-
chartmdt[32];
49+
crc64crc;
50+
charpgctime_str[32];
51+
charckpttime_str[32];
8552

8653
DataDir=getenv("PGDATA");
8754
if (DataDir==NULL ) {
@@ -91,33 +58,77 @@ int main() {
9158

9259
snprintf(ControlFilePath,MAXPGPATH,"%s/global/pg_control",DataDir);
9360

94-
if ((fd=open(ControlFilePath,O_RDONLY))==-1) {
61+
if ((fd=open(ControlFilePath,O_RDONLY))==-1)
62+
{
9563
perror("Failed to open $PGDATA/global/pg_control for reading");
9664
exit(2);
9765
}
9866

99-
read(fd,&ControlFile,sizeof(ControlFileData));
100-
strftime(tmdt,32,"%c",localtime(&(ControlFile.time)));
101-
102-
printf("Log file id: %u\n"
103-
"Log file segment: %u\n"
104-
"Last modified: %s\n"
105-
"Database block size: %u\n"
106-
"Blocks per segment of large relation: %u\n"
107-
"Catalog version number: %u\n"
108-
"LC_COLLATE: %s\n"
109-
"LC_CTYPE: %s\n"
110-
"Log archive directory: %s\n",
111-
ControlFile.logId,
112-
ControlFile.logSeg,
113-
tmdt,
114-
ControlFile.blcksz,
115-
ControlFile.relseg_size,
116-
ControlFile.catalog_version_no,
117-
ControlFile.lc_collate,
118-
ControlFile.lc_ctype,
119-
ControlFile.archdir);
120-
67+
if (read(fd,&ControlFile,sizeof(ControlFileData))!=sizeof(ControlFileData))
68+
{
69+
perror("Failed to read $PGDATA/global/pg_control");
70+
exit(2);
71+
}
72+
close(fd);
73+
74+
/* Check the CRC. */
75+
INIT_CRC64(crc);
76+
COMP_CRC64(crc,
77+
(char*)&ControlFile+sizeof(crc64),
78+
sizeof(ControlFileData)-sizeof(crc64));
79+
FIN_CRC64(crc);
80+
81+
if (!EQ_CRC64(crc,ControlFile.crc))
82+
printf("WARNING: Calculated CRC checksum does not match value stored in file.\n"
83+
"Either the file is corrupt, or it has a different layout than this program\n"
84+
"is expecting. The results below are untrustworthy.\n\n");
85+
86+
strftime(pgctime_str,32,"%c",
87+
localtime(&(ControlFile.time)));
88+
strftime(ckpttime_str,32,"%c",
89+
localtime(&(ControlFile.checkPointCopy.time)));
90+
91+
printf("pg_control version number: %u\n"
92+
"Catalog version number: %u\n"
93+
"Database state: %s\n"
94+
"pg_control last modified: %s\n"
95+
"Current log file id: %u\n"
96+
"Next log file segment: %u\n"
97+
"Latest checkpoint location: %X/%X\n"
98+
"Prior checkpoint location: %X/%X\n"
99+
"Latest checkpoint's REDO location: %X/%X\n"
100+
"Latest checkpoint's UNDO location: %X/%X\n"
101+
"Latest checkpoint's StartUpID: %u\n"
102+
"Latest checkpoint's NextXID: %u\n"
103+
"Latest checkpoint's NextOID: %u\n"
104+
"Time of latest checkpoint: %s\n"
105+
"Database block size: %u\n"
106+
"Blocks per segment of large relation: %u\n"
107+
"LC_COLLATE: %s\n"
108+
"LC_CTYPE: %s\n",
109+
110+
ControlFile.pg_control_version,
111+
ControlFile.catalog_version_no,
112+
dbState(ControlFile.state),
113+
pgctime_str,
114+
ControlFile.logId,
115+
ControlFile.logSeg,
116+
ControlFile.checkPoint.xlogid,
117+
ControlFile.checkPoint.xrecoff,
118+
ControlFile.prevCheckPoint.xlogid,
119+
ControlFile.prevCheckPoint.xrecoff,
120+
ControlFile.checkPointCopy.redo.xlogid,
121+
ControlFile.checkPointCopy.redo.xrecoff,
122+
ControlFile.checkPointCopy.undo.xlogid,
123+
ControlFile.checkPointCopy.undo.xrecoff,
124+
ControlFile.checkPointCopy.ThisStartUpID,
125+
ControlFile.checkPointCopy.nextXid,
126+
ControlFile.checkPointCopy.nextOid,
127+
ckpttime_str,
128+
ControlFile.blcksz,
129+
ControlFile.relseg_size,
130+
ControlFile.lc_collate,
131+
ControlFile.lc_ctype);
132+
121133
return (0);
122134
}
123-

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp