2011-11-28 04:42:32 +08:00
#!/bin/sh
# contrib/pg_upgrade/test.sh
#
# Test driver for pg_upgrade. Initializes a new database cluster,
# runs the regression tests (to put in some data), runs pg_dumpall,
# runs pg_upgrade, runs pg_dumpall again, compares the dumps.
#
2013-01-02 06:15:01 +08:00
# Portions Copyright (c) 1996-2013, PostgreSQL Global Development Group
2011-11-28 04:42:32 +08:00
# Portions Copyright (c) 1994, Regents of the University of California
set -e
: ${ MAKE =make }
: ${ PGPORT =50432 }
export PGPORT
2012-10-19 04:14:11 +08:00
testhost = ` uname -s`
2012-09-04 10:32:17 +08:00
2013-01-04 07:34:51 +08:00
case $testhost in
MINGW*) LISTEN_ADDRESSES = "localhost" ; ;
*) LISTEN_ADDRESSES = "" ; ;
esac
POSTMASTER_OPTS = " -F -c listen_addresses= $LISTEN_ADDRESSES "
2011-11-28 04:42:32 +08:00
temp_root = $PWD /tmp_check
if [ " $1 " = '--install' ] ; then
temp_install = $temp_root /install
bindir = $temp_install /$bindir
libdir = $temp_install /$libdir
" $MAKE " -s -C ../.. install DESTDIR = " $temp_install "
" $MAKE " -s -C ../pg_upgrade_support install DESTDIR = " $temp_install "
" $MAKE " -s -C . install DESTDIR = " $temp_install "
# platform-specific magic to find the shared libraries; see pg_regress.c
LD_LIBRARY_PATH = $libdir :$LD_LIBRARY_PATH
export LD_LIBRARY_PATH
DYLD_LIBRARY_PATH = $libdir :$DYLD_LIBRARY_PATH
export DYLD_LIBRARY_PATH
LIBPATH = $libdir :$LIBPATH
export LIBPATH
PATH = $libdir :$PATH
# We need to make it use psql from our temporary installation,
# because otherwise the installcheck run below would try to
# use psql from the proper installation directory, which might
2013-01-12 21:28:58 +08:00
# be outdated or missing. But don't override anything else that's
# already in EXTRA_REGRESS_OPTS.
EXTRA_REGRESS_OPTS = " $EXTRA_REGRESS_OPTS --psqldir= $bindir "
2011-11-28 04:42:32 +08:00
export EXTRA_REGRESS_OPTS
fi
: ${ oldbindir = $bindir }
: ${ oldsrc =../.. }
oldsrc = ` cd " $oldsrc " && pwd `
newsrc = ` cd ../.. && pwd `
PATH = $bindir :$PATH
export PATH
PGDATA = $temp_root /data
export PGDATA
rm -rf " $PGDATA " " $PGDATA " .old
2012-11-30 20:54:24 +08:00
unset PGDATABASE
unset PGUSER
unset PGSERVICE
unset PGSSLMODE
unset PGREQUIRESSL
unset PGCONNECT_TIMEOUT
unset PGHOST
unset PGHOSTADDR
2011-11-28 04:42:32 +08:00
logdir = $PWD /log
rm -rf " $logdir "
mkdir " $logdir "
2012-12-04 12:44:18 +08:00
# enable echo so the user can see what is being executed
set -x
2012-09-27 10:38:15 +08:00
$oldbindir /initdb -N
2013-01-04 07:34:51 +08:00
$oldbindir /pg_ctl start -l " $logdir /postmaster1.log " -o " $POSTMASTER_OPTS " -w
2011-11-28 04:42:32 +08:00
if " $MAKE " -C " $oldsrc " installcheck; then
2012-09-06 06:00:31 +08:00
pg_dumpall -f " $temp_root " /dump1.sql || pg_dumpall1_status = $?
2011-11-28 04:42:32 +08:00
if [ " $newsrc " != " $oldsrc " ] ; then
oldpgversion = ` psql -A -t -d regression -c "SHOW server_version_num" `
fix_sql = ""
case $oldpgversion in
804??)
fix_sql = " UPDATE pg_proc SET probin = replace(probin::text, ' $oldsrc ', ' $newsrc ')::bytea WHERE probin LIKE ' $oldsrc %'; DROP FUNCTION public.myfunc(integer); "
; ;
900??)
fix_sql = " SET bytea_output TO escape; UPDATE pg_proc SET probin = replace(probin::text, ' $oldsrc ', ' $newsrc ')::bytea WHERE probin LIKE ' $oldsrc %'; "
; ;
901??)
fix_sql = " UPDATE pg_proc SET probin = replace(probin, ' $oldsrc ', ' $newsrc ') WHERE probin LIKE ' $oldsrc %'; "
; ;
esac
psql -d regression -c " $fix_sql ; " || psql_fix_sql_status = $?
mv " $temp_root " /dump1.sql " $temp_root " /dump1.sql.orig
sed " s; $oldsrc ; $newsrc ;g " " $temp_root " /dump1.sql.orig >" $temp_root " /dump1.sql
fi
else
make_installcheck_status = $?
fi
$oldbindir /pg_ctl -m fast stop
if [ -n " $make_installcheck_status " ] ; then
exit 1
fi
if [ -n " $psql_fix_sql_status " ] ; then
exit 1
fi
if [ -n " $pg_dumpall1_status " ] ; then
echo "pg_dumpall of pre-upgrade database cluster failed"
exit 1
fi
mv " ${ PGDATA } " " ${ PGDATA } .old "
2012-09-27 10:38:15 +08:00
initdb -N
2011-11-28 04:42:32 +08:00
pg_upgrade -d " ${ PGDATA } .old " -D " ${ PGDATA } " -b " $oldbindir " -B " $bindir "
2013-01-04 07:34:51 +08:00
pg_ctl start -l " $logdir /postmaster2.log " -o " $POSTMASTER_OPTS " -w
2012-09-04 10:32:17 +08:00
2012-10-19 04:14:11 +08:00
case $testhost in
MINGW*) cmd /c analyze_new_cluster.bat ; ;
*) sh ./analyze_new_cluster.sh ; ;
esac
2012-09-06 06:00:31 +08:00
pg_dumpall -f " $temp_root " /dump2.sql || pg_dumpall2_status = $?
2011-11-28 04:42:32 +08:00
pg_ctl -m fast stop
2012-12-04 21:17:45 +08:00
# no need to echo commands anymore
set +x
echo
2011-11-28 04:42:32 +08:00
if [ -n " $pg_dumpall2_status " ] ; then
echo "pg_dumpall of post-upgrade database cluster failed"
exit 1
fi
2012-10-19 04:14:11 +08:00
case $testhost in
MINGW*) cmd /c delete_old_cluster.bat ; ;
*) sh ./delete_old_cluster.sh ; ;
esac
2012-09-04 10:32:17 +08:00
2011-11-28 04:42:32 +08:00
if diff -q " $temp_root " /dump1.sql " $temp_root " /dump2.sql; then
echo PASSED
exit 0
else
echo "dumps were not identical"
exit 1
fi