22# Utilities needed
33# 1. sh
44# 3. sed
5+ LC_MESSAGES=C
6+ export LC_MESSAGES
57if [-z " $PGDATA " ]; then
68echo " PGDATA environment variable is not set. Stop." 1>&2
79exit 2
3032# Check the catalog version
3133CATALOG_VERSION_NO=2016081311
3234MAJORVER=9.6
35+ if [! -f " ${PGDATA} /global/pg_control" -a -f " ${PGDATA} /postgresql.conf" ]; 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}" ${PGDATA} /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+ fi
3346CATVER=` ${PGBIN} pg_controldata| sed -n' /Catalog version number:/s/^.*: *//p' `
3447if [" $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
48+ if [-n " $check " ]; then
49+ echo " Database needs upgrade"
50+ exit 1
51+ fi
52+ if [-f " $PGDATA /postmaster.pid" ]; then
53+ echo " postmaster.pid exists. Is another backend running on$PGDATA " 1>&2 ;
54+ exit 1;
4955fi
5056# Fix pg_control file
5157" ${PGBIN} pg_controldata" -c
@@ -56,11 +62,11 @@ if [ "$CATVER" != $CATALOG_VERSION_NO ]; then
5662(cd$i ; mv PG_${MAJORVER} _$CATVER PG_${MAJORVER} _$CATALOG_VERSION_NO )
5763done
5864)
59- if [-n " $SAVE_PGDATA " ]; then
60- PGDATA=" $SAVE_PGDATA "
61- fi
6265fi
6366
67+ if [-n " $SAVE_PGDATA " ]; then
68+ PGDATA=" $SAVE_PGDATA "
69+ fi
6470
6571for 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
6672if [-d " $dir /pgpro-upgrade" ]; then