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

Commitf91f7e5

Browse files
committed
Merge branch 'PGPRO9_6_TASK941' into PGPRO9_6
2 parents54332c5 +bcb0f7d commitf91f7e5

File tree

9 files changed

+174
-8
lines changed

9 files changed

+174
-8
lines changed

‎configure

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2764,7 +2764,7 @@ else
27642764
fi
27652765

27662766

2767-
PGPRO_VERSION="$PACKAGE_VERSION.2"
2767+
PGPRO_VERSION="$PACKAGE_VERSION.1"
27682768
PGPRO_PACKAGE_NAME="PostgresPro"
27692769
PGPRO_EDITION="standard"
27702770

‎configure.in

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ AC_DEFINE_UNQUOTED(PG_MAJORVERSION, "$PG_MAJORVERSION", [PostgreSQL major versio
3838
PGAC_ARG_REQ(with, extra-version, [STRING], [append STRING to version],
3939
[PG_VERSION="$PACKAGE_VERSION$withval"],
4040
[PG_VERSION="$PACKAGE_VERSION"])
41-
PGPRO_VERSION="$PACKAGE_VERSION.2"
41+
PGPRO_VERSION="$PACKAGE_VERSION.1"
4242
PGPRO_PACKAGE_NAME="PostgresPro"
4343
PGPRO_EDITION="standard"
4444
AC_SUBST(PGPRO_PACKAGE_NAME)

‎src/bin/pg_controldata/pg_controldata.c

Lines changed: 95 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,10 @@
2525
#include"catalog/pg_control.h"
2626
#include"common/controldata_utils.h"
2727
#include"pg_getopt.h"
28+
#include"catalog/catversion.h"
2829

30+
staticvoid
31+
WriteControlFile(ControlFileDataControlFile,constchar*progname,constchar*DataDir);
2932

3033
staticvoid
3134
usage(constchar*progname)
@@ -35,6 +38,8 @@ usage(const char *progname)
3538
printf(_(" %s [OPTION] [DATADIR]\n"),progname);
3639
printf(_("\nOptions:\n"));
3740
printf(_(" [-D] DATADIR data directory\n"));
41+
printf(_(" [-c] update catversion in pg_control to the verision of the current binary\n"));
42+
printf(_(" [-m] check if catversion in pg_control matches catverision of the current binary. Return 0 on match, 1 otherwise.\n"));
3843
printf(_(" -V, --version output version information, then exit\n"));
3944
printf(_(" -?, --help show this help, then exit\n"));
4045
printf(_("\nIf no data directory (DATADIR) is specified, "
@@ -96,6 +101,8 @@ main(int argc, char *argv[])
96101
XLogSegNosegno;
97102
charxlogfilename[MAXFNAMELEN];
98103
intc;
104+
boolreset_catversion= false;
105+
boolcheck_catversion_match= false;
99106

100107
set_pglocale_pgservice(argv[0],PG_TEXTDOMAIN("pg_controldata"));
101108

@@ -115,14 +122,19 @@ main(int argc, char *argv[])
115122
}
116123
}
117124

118-
while ((c=getopt(argc,argv,"D:"))!=-1)
125+
while ((c=getopt(argc,argv,"D:cm"))!=-1)
119126
{
120127
switch (c)
121128
{
122129
case'D':
123130
DataDir=optarg;
124131
break;
125-
132+
case'c':
133+
reset_catversion= true;
134+
break;
135+
case'm':
136+
check_catversion_match= true;
137+
break;
126138
default:
127139
fprintf(stderr,_("Try \"%s --help\" for more information.\n"),progname);
128140
exit(1);
@@ -157,6 +169,22 @@ main(int argc, char *argv[])
157169
/* get a copy of the control file */
158170
ControlFile=get_controlfile(DataDir,progname);
159171

172+
if (check_catversion_match)
173+
{
174+
if (ControlFile->catalog_version_no==CATALOG_VERSION_NO)
175+
return0;
176+
else
177+
return1;
178+
}
179+
180+
if (reset_catversion)
181+
{
182+
ControlFile->catalog_version_no=CATALOG_VERSION_NO;
183+
WriteControlFile(*ControlFile,progname,DataDir);
184+
printf(_("Catalog version updated\n"));
185+
return0;
186+
}
187+
160188
/*
161189
* This slightly-chintzy coding will work as long as the control file
162190
* timestamps are within the range of time_t; that should be the case in
@@ -298,3 +326,68 @@ main(int argc, char *argv[])
298326
ControlFile->data_checksum_version);
299327
return0;
300328
}
329+
330+
staticvoid
331+
WriteControlFile(ControlFileDataControlFile,constchar*progname,constchar*DataDir)
332+
{
333+
intfd;
334+
charbuffer[PG_CONTROL_SIZE];/* need not be aligned */
335+
charControlFilePath[MAXPGPATH];
336+
337+
snprintf(ControlFilePath,MAXPGPATH,"%s/global/pg_control",DataDir);
338+
339+
/* Contents are protected with a CRC */
340+
INIT_CRC32C(ControlFile.crc);
341+
COMP_CRC32C(ControlFile.crc,
342+
(char*)&ControlFile,
343+
offsetof(ControlFileData,crc));
344+
FIN_CRC32C(ControlFile.crc);
345+
346+
/*
347+
* We write out PG_CONTROL_SIZE bytes into pg_control, zero-padding the
348+
* excess over sizeof(ControlFileData). This reduces the odds of
349+
* premature-EOF errors when reading pg_control. We'll still fail when we
350+
* check the contents of the file, but hopefully with a more specific
351+
* error than "couldn't read pg_control".
352+
*/
353+
if (sizeof(ControlFileData)>PG_CONTROL_SIZE)
354+
{
355+
fprintf(stderr,
356+
_("%s: internal error -- sizeof(ControlFileData) is too large ... fix PG_CONTROL_SIZE\n"),
357+
progname);
358+
exit(1);
359+
}
360+
361+
memset(buffer,0,PG_CONTROL_SIZE);
362+
memcpy(buffer,&ControlFile,sizeof(ControlFileData));
363+
364+
fd=open(ControlFilePath,
365+
O_RDWR |PG_BINARY,
366+
S_IRUSR |S_IWUSR);
367+
368+
if (fd<0)
369+
{
370+
fprintf(stderr,_("%s: could not open pg_control file: %s\n"),
371+
progname,strerror(errno));
372+
exit(1);
373+
}
374+
375+
errno=0;
376+
if (write(fd,buffer,PG_CONTROL_SIZE)!=PG_CONTROL_SIZE)
377+
{
378+
/* if write didn't set errno, assume problem is no disk space */
379+
if (errno==0)
380+
errno=ENOSPC;
381+
fprintf(stderr,_("%s: could not write pg_control file: %s\n"),
382+
progname,strerror(errno));
383+
exit(1);
384+
}
385+
386+
if (fsync(fd)!=0)
387+
{
388+
fprintf(stderr,_("%s: fsync error: %s\n"),progname,strerror(errno));
389+
exit(1);
390+
}
391+
392+
close(fd);
393+
}

‎src/pgpro-upgrade/004-pgpro_build.sql

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
CREATEFUNCTIONpg_catalog.pgpro_build() RETURNSTEXTAS'pgpro_build' LANGUAGE internal STRICT IMMUTABLE;
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
SELECT COUNT(*) > 0 AS pgpro_build FROM pg_proc WHERE proname = 'pgpro_build' AND pronamespace = 11;

‎src/pgpro-upgrade/Makefile

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,11 @@ include $(top_builddir)/src/Makefile.global
1414
srcdir=$(top_srcdir)/$(subdir)
1515

1616
all:
17-
true
17+
$(PERL)$(srcdir)/setver.pl$(top_srcdir)$(top_builddir)
18+
chmod 0755 pgpro_upgrade
1819

19-
install: installdirs
20-
$(INSTALL_PROGRAM)$(srcdir)/pgpro_upgrade'$(DESTDIR)$(bindir)/pgpro_upgrade'
20+
install: installdirs
21+
$(INSTALL_PROGRAM) pgpro_upgrade'$(DESTDIR)$(bindir)/pgpro_upgrade'
2122
$(INSTALL_DATA)$(srcdir)/*.sql$(srcdir)/*.test'$(DESTDIR)$(datadir)/pgpro-upgrade'
2223
installdirs:
2324
$(MKDIR_P)'$(DESTDIR)$(bindir)'

‎src/pgpro-upgrade/pgpro_upgrade

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,41 @@ case "$PGBIN" in
2727
;;
2828
esac
2929

30+
# Check the catalog version
31+
CATALOG_VERSION_NO=2016081311
32+
MAJORVER=9.6
33+
CATVER=`${PGBIN}pg_controldata|sed -n'/Catalog version number:/s/^.*: *//p'`
34+
if ["$CATVER"!=$CATALOG_VERSION_NO ];then
35+
if [!-f"${PGDATA}/global/pg_control" ];then
36+
# looks like we have Debian with separate directory for configs
37+
SAVE_PGDATA="$PGDATA"
38+
PGDATA=`sed -n"/data_directory/{s/^data_directory = '//
39+
s/'.*$//
40+
p}" /etc/postgresql/9.6/main/postgresql.conf`
41+
if [-z"$PGDATA"-o!-f"${PGDATA}/global/pg_control" ];then
42+
echo"Cannot find valid database in$PGDATA"1>&2;
43+
exit 1
44+
fi
45+
if [-f"$PGDATA/postmaster.pid" ];then
46+
echo"postmaster.pid exists. Is another backend running on$PGDATA"1>&2;
47+
exit 1;
48+
fi
49+
fi
50+
# Fix pg_control file
51+
"${PGBIN}pg_controldata" -c
52+
# Fix tablespace directories
53+
(cd"$PGDATA/pg_tblspc"
54+
foriin*;do
55+
["$i"="*" ]&&break# Glob pattern not expanded
56+
(cd$i; mv PG_${MAJORVER}_$CATVER PG_${MAJORVER}_$CATALOG_VERSION_NO)
57+
done
58+
)
59+
if [-n"$SAVE_PGDATA" ];then
60+
PGDATA="$SAVE_PGDATA"
61+
fi
62+
fi
63+
64+
3065
fordirin"$PGSHARE" /usr/pgsql-9.6/share /usr/share/postgresql/9.6 /usr/pgsql/9.6/share /usr/share/pgsql /usr/share/postgrespro96;do
3166
if [-d"$dir/pgpro-upgrade" ];then
3267
DIR="$dir/pgpro-upgrade"

‎src/pgpro-upgrade/setver.pl

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
#!/usr/bin/perl
2+
use Cwdqw(getcwd abs_path);
3+
my$major_version;
4+
my$catversion;
5+
my$curdir = abs_path(getcwd()."/../..");
6+
my$top_srcdir =$ARGV[0] ||$curdir;
7+
my$top_builddir =$ARGV[1] ||$curdir;
8+
open F,"$top_builddir/src/include/pg_config.h";
9+
while (<F>) {
10+
$major_version =$1if/#define PG_MAJORVERSION "(.*)"/;
11+
}
12+
close F;
13+
open F,"$top_srcdir/src/include/catalog/catversion.h"ordie"catversion.h$!\n";
14+
while (<F>) {
15+
$catversion =$1if/#define CATALOG_VERSION_NO\s+(\S+)/;
16+
}
17+
close F;
18+
if (-f"pgpro_upgrade") {
19+
unlink("pgpro_upgrade.bak")if-f"pgpro_upgrade.bak";
20+
rename("pgpro_upgrade","pgpro_upgrade.bak");
21+
open IN,"pgpro_upgrade.bak"
22+
}else {
23+
open IN,"$top_srcdir/src/pgpro-upgrade/pgpro_upgrade";
24+
}
25+
open OUT,">","pgpro_upgrade";
26+
while (<IN>) {
27+
s/^CATALOG_VERSION_NO=.*$/CATALOG_VERSION_NO=$catversion/;
28+
s/^MAJORVER=.*$/MAJORVER=$major_version/;
29+
print OUT$_;
30+
}
31+
close IN;
32+
close OUT;

‎src/tools/msvc/Solution.pm

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -274,7 +274,6 @@ sub GenerateFiles
274274
"src/include/pg_config_ext.h.win32",
275275
"src/include/pg_config_ext.h");
276276
}
277-
278277
$self->GenerateDefFile(
279278
"src/interfaces/libpq/libpqdll.def",
280279
"src/interfaces/libpq/exports.txt",
@@ -301,6 +300,10 @@ sub GenerateFiles
301300
"perl -I ../catalog Gen_fmgrtab.pl ../../../src/include/catalog/pg_proc.h");
302301
chdir('../../..');
303302
}
303+
print"Generating pgpro_upgrade";
304+
chdir("src/pgpro-upgrade");
305+
system("perl setver.pl ../.. ../..");
306+
chdir("../..");
304307
if (IsNewer(
305308
'src/include/utils/fmgroids.h',
306309
'src/backend/utils/fmgroids.h'))

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp