Skip to content

Commit f8ffcd4

Browse files
committed
Fix run of pgpro_upgrade with data_directory in the postgresql.conf
1 parent 0c79d63 commit f8ffcd4

File tree

1 file changed

+17
-17
lines changed

1 file changed

+17
-17
lines changed

src/pgpro-upgrade/pgpro_upgrade

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -30,26 +30,26 @@ esac
3030
# Check the catalog version
3131
CATALOG_VERSION_NO=2016081311
3232
MAJORVER=9.6
33+
if [ ! -f "${PGDATA}/global/pg_control" -a -f "${PGDATA}/postgresql.conf" ]; then
34+
# looks like we have Debian with separate directory for configs
35+
SAVE_PGDATA="$PGDATA"
36+
PGDATA=`sed -n "/data_directory/{s/^data_directory = '//
37+
s/'.*$//
38+
p}" ${PGDATA}/postgresql.conf`
39+
if [ -z "$PGDATA" -o ! -f "${PGDATA}/global/pg_control" ]; then
40+
echo "Cannot find valid database in $PGDATA" 1>&2;
41+
exit 1
42+
fi
43+
fi
3344
CATVER=`${PGBIN}pg_controldata|sed -n '/Catalog version number:/s/^.*: *//p'`
3445
if [ "$CATVER" != $CATALOG_VERSION_NO ]; then
3546
if [ -n "$check" ]; then
3647
echo "Database needs upgrade"
3748
exit 1
3849
fi
39-
if [ ! -f "${PGDATA}/global/pg_control" ]; then
40-
# looks like we have Debian with separate directory for configs
41-
SAVE_PGDATA="$PGDATA"
42-
PGDATA=`sed -n "/data_directory/{s/^data_directory = '//
43-
s/'.*$//
44-
p}" /etc/postgresql/9.6/main/postgresql.conf`
45-
if [ -z "$PGDATA" -o ! -f "${PGDATA}/global/pg_control" ]; then
46-
echo "Cannot find valid database in $PGDATA" 1>&2;
47-
exit 1
48-
fi
49-
if [ -f "$PGDATA/postmaster.pid" ]; then
50-
echo "postmaster.pid exists. Is another backend running on $PGDATA" 1>&2;
51-
exit 1;
52-
fi
50+
if [ -f "$PGDATA/postmaster.pid" ]; then
51+
echo "postmaster.pid exists. Is another backend running on $PGDATA" 1>&2;
52+
exit 1;
5353
fi
5454
# Fix pg_control file
5555
"${PGBIN}pg_controldata" -c
@@ -60,11 +60,11 @@ if [ "$CATVER" != $CATALOG_VERSION_NO ]; then
6060
(cd $i; mv PG_${MAJORVER}_$CATVER PG_${MAJORVER}_$CATALOG_VERSION_NO)
6161
done
6262
)
63-
if [ -n "$SAVE_PGDATA" ]; then
64-
PGDATA="$SAVE_PGDATA"
65-
fi
6663
fi
6764

65+
if [ -n "$SAVE_PGDATA" ]; then
66+
PGDATA="$SAVE_PGDATA"
67+
fi
6868

6969
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
7070
if [ -d "$dir/pgpro-upgrade" ]; then

0 commit comments

Comments
 (0)