Skip to content

Commit 85e91d7

Browse files
committed
Added catalog version checking to pgpro_upgrade. Now correct catversion and major version is hardcoded
1 parent cfb0d4c commit 85e91d7

File tree

3 files changed

+33
-0
lines changed

3 files changed

+33
-0
lines changed

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+
CREATE FUNCTION pg_catalog.pgpro_build() RETURNS TEXT AS '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/pgpro_upgrade

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,37 @@ 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" 2>&1;
43+
exit 1
44+
fi
45+
fi
46+
# Fix pg_control file
47+
"${PGBIN}pg_controldata" -c
48+
# Fix tablespace directories
49+
(cd "$PGDATA/pg_tblspc"
50+
for i in *; do
51+
[ "$i" = "*" ] && break # Glob pattern not expanded
52+
(cd $i; mv PG_${MAJORVER}_$CATVER PG_${MAJORVER}_$CATALOG_VERSION_NO)
53+
done
54+
)
55+
if [ -n "$SAVE_PGDATA" ] then
56+
PGDATA="$SAVE_PGDATA"
57+
fi
58+
fi
59+
60+
3061
for dir in "$PGSHARE" /usr/pgsql-9.6/share /usr/share/postgresql/9.6 /usr/pgsql/9.6/share /usr/share/pgsql /usr/share/postgrespro96 ; do
3162
if [ -d "$dir/pgpro-upgrade" ]; then
3263
DIR="$dir/pgpro-upgrade"

0 commit comments

Comments
 (0)