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

Commitb25e60d

Browse files
committed
I had a need to read such things as the backend locale and the catalog
version number from the current database, and couldn't find any existingprogram to do that.linda:~$ pg_controldataLog file id: 0Log file segment: 5Last modified: Wed Feb 7 19:35:47 2001Database block size: 8192Blocks per segment of large relation: 131072Catalog version number: 200101061LC_COLLATE: en_GBLC_CTYPE: en_GBLog archive directory:Oliver Elphick Oliver.Elphick@lfix.co.uk
1 parente74ce0a commitb25e60d

File tree

6 files changed

+182
-0
lines changed

6 files changed

+182
-0
lines changed

‎contrib/README

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,10 @@ oid2name -
8585
maps numeric files to table names
8686
by B Palmer <bpalmer@crimelabs.net>
8787

88+
pg_controldata -
89+
Dump internal database site structures
90+
by Oliver Elphick <olly@lfix.co.uk>
91+
8892
pg_dumplo -
8993
Dump large objects
9094
by Karel Zak <zakkr@zf.jcu.cz>

‎contrib/pg_controldata/Makefile

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
#
2+
# $Header: /cvsroot/pgsql/contrib/pg_controldata/Attic/Makefile,v 1.1 2001/02/23 20:38:35 momjian Exp $
3+
#
4+
5+
subdir = contrib/pg_controldata
6+
top_builddir = ../..
7+
include$(top_builddir)/src/Makefile.global
8+
9+
overrideCPPFLAGS := -I$(libpq_srcdir)$(CPPFLAGS)
10+
11+
OBJS= pg_controldata.o
12+
13+
all: pg_controldata
14+
15+
pg_controldata:$(OBJS)$(libpq_builddir)/libpq.a
16+
$(CC)$(CFLAGS)$(OBJS)$(libpq)$(LDFLAGS)$(LIBS) -o$@
17+
18+
install: all installdirs
19+
$(INSTALL_PROGRAM) pg_controldata$(X)$(bindir)
20+
$(INSTALL_DATA) README.pg_controldata$(docdir)/contrib
21+
22+
installdirs:
23+
$(mkinstalldirs)$(bindir)$(docdir)/contrib
24+
25+
uninstall:
26+
rm -f$(bindir)/pg_controldata$(X)$(docdir)/contrib/README.pg_controldata
27+
28+
cleandistcleanmaintainer-clean:
29+
rm -f pg_controldata$(X)$(OBJS)
30+
31+
dependdep:
32+
$(CC) -MM -MG$(CFLAGS)*.c> depend
33+
34+
ifeq (depend,$(wildcard depend))
35+
include depend
36+
endif
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
I had a need to read such things as the backend locale and the catalog
2+
version number from the current database, and couldn't find any existing
3+
program to do that.
4+
5+
The attached utility produces this output:
6+
7+
linda:~$ pg_controldata
8+
Log file id: 0
9+
Log file segment: 5
10+
Last modified: Wed Feb 7 19:35:47 2001
11+
Database block size: 8192
12+
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:
17+
18+
--
19+
Oliver Elphick <olly@lfix.co.uk>

‎contrib/pg_controldata/pg_controldata

11.5 KB
Binary file not shown.
Lines changed: 123 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,123 @@
1+
/* pg_controldata
2+
*
3+
* reads the data from $PGDATA/global/pg_control
4+
*
5+
* copyright (c) Oliver Elphick <olly@lfix.co.uk>, 2001;
6+
* licence: BSD
7+
*
8+
*/
9+
10+
#include<stdio.h>
11+
#include<stdlib.h>
12+
#include<unistd.h>
13+
#include<time.h>
14+
#include<sys/types.h>
15+
#include<sys/stat.h>
16+
#include<fcntl.h>
17+
18+
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
41+
42+
typedefenumDBState
43+
{
44+
DB_STARTUP=0,
45+
DB_SHUTDOWNED,
46+
DB_SHUTDOWNING,
47+
DB_IN_RECOVERY,
48+
DB_IN_PRODUCTION
49+
}DBState;
50+
51+
52+
typedefstructControlFileData
53+
{
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() {
80+
ControlFileDataControlFile;
81+
intfd;
82+
charControlFilePath[MAXPGPATH];
83+
char*DataDir;
84+
chartmdt[32];
85+
86+
DataDir=getenv("PGDATA");
87+
if (DataDir==NULL ) {
88+
fprintf(stderr,"PGDATA is not defined\n");
89+
exit(1);
90+
}
91+
92+
snprintf(ControlFilePath,MAXPGPATH,"%s/global/pg_control",DataDir);
93+
94+
if ((fd=open(ControlFilePath,O_RDONLY))==-1) {
95+
perror("Failed to open $PGDATA/global/pg_control for reading");
96+
exit(2);
97+
}
98+
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+
121+
return (0);
122+
}
123+
8.17 KB
Binary file not shown.

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp