2011-11-27 22:42:32 +02: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.
#
2012-01-01 18:01:58 -05:00
# Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group
2011-11-27 22:42:32 +02:00
# Portions Copyright (c) 1994, Regents of the University of California
set -e
: ${ MAKE =make }
: ${ PGPORT =50432 }
export PGPORT
2014-12-17 22:48:40 -05:00
# Run a given "initdb" binary and overlay the regression testing
# authentication configuration.
standard_initdb( ) {
2021-12-12 16:14:25 -05:00
# Specify "-A trust" explicitly to suppress initdb's warning.
" $1 " -A trust
2015-09-17 11:57:00 -04:00
if [ -n " $TEMP_CONFIG " -a -r " $TEMP_CONFIG " ]
then
cat " $TEMP_CONFIG " >> " $PGDATA /postgresql.conf "
fi
2014-12-17 22:48:40 -05:00
../../src/test/regress/pg_regress --config-auth " $PGDATA "
}
2014-06-14 09:41:13 -04:00
# Establish how the server will listen for connections
2012-10-18 16:15:49 -04:00
testhost = ` uname -s`
2012-09-03 22:32:56 -04:00
2013-01-03 18:34:57 -05:00
case $testhost in
2014-06-14 09:41:13 -04:00
MINGW*)
LISTEN_ADDRESSES = "localhost"
2014-12-17 22:48:40 -05:00
PGHOST = localhost
2014-06-14 09:41:13 -04:00
; ;
*)
LISTEN_ADDRESSES = ""
# Select a socket directory. The algorithm is from the "configure"
# script; the outcome mimics pg_regress.c:make_temp_sockdir().
PGHOST = $PG_REGRESS_SOCK_DIR
if [ " x $PGHOST " = x ] ; then
{
dir = ` ( umask 077 &&
mktemp -d /tmp/pg_upgrade_check-XXXXXX) 2>/dev/null` &&
[ -d " $dir " ]
} ||
{
dir = /tmp/pg_upgrade_check-$$ -$RANDOM
( umask 077 && mkdir " $dir " )
} ||
{
echo "could not create socket temporary directory in \"/tmp\""
exit 1
}
PGHOST = $dir
trap 'rm -rf "$PGHOST"' 0
trap 'exit 3' 1 2 13 15
fi
; ;
2013-01-03 18:34:57 -05:00
esac
2014-06-14 09:41:13 -04:00
POSTMASTER_OPTS = " -F -c listen_addresses= $LISTEN_ADDRESSES -k \" $PGHOST \" "
2014-12-17 22:48:40 -05:00
export PGHOST
2014-03-29 03:12:00 -04:00
2015-07-07 12:49:18 -04:00
# don't rely on $PWD here, as old shells don't set it
temp_root = ` pwd ` /tmp_check
2011-11-27 22:42:32 +02:00
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 08:24:38 -05: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-27 22:42:32 +02:00
export EXTRA_REGRESS_OPTS
fi
: ${ oldbindir = $bindir }
: ${ oldsrc =../.. }
oldsrc = ` cd " $oldsrc " && pwd `
newsrc = ` cd ../.. && pwd `
PATH = $bindir :$PATH
export PATH
2013-03-30 12:54:36 -04:00
BASE_PGDATA = $temp_root /data
PGDATA = " $BASE_PGDATA .old "
2011-11-27 22:42:32 +02:00
export PGDATA
2013-03-30 12:54:36 -04:00
rm -rf " $BASE_PGDATA " " $PGDATA "
2011-11-27 22:42:32 +02:00
2013-10-28 11:45:50 -04:00
# Clear out any environment vars that might cause libpq to connect to
# the wrong postmaster (cf pg_regress.c)
#
# Some shells, such as NetBSD's, return non-zero from unset if the variable
# is already unset. Since we are operating under 'set -e', this causes the
# script to fail. To guard against this, set them all to an empty string first.
PGDATABASE = "" ; unset PGDATABASE
PGUSER = "" ; unset PGUSER
PGSERVICE = "" ; unset PGSERVICE
2014-03-16 21:55:10 -04:00
PGSSLMODE = "" ; unset PGSSLMODE
2013-10-28 11:45:50 -04:00
PGREQUIRESSL = "" ; unset PGREQUIRESSL
PGCONNECT_TIMEOUT = "" ; unset PGCONNECT_TIMEOUT
PGHOSTADDR = "" ; unset PGHOSTADDR
2012-11-30 10:54:46 -05:00
2015-07-07 12:49:18 -04:00
logdir = ` pwd ` /log
2011-11-27 22:42:32 +02:00
rm -rf " $logdir "
mkdir " $logdir "
2014-12-17 22:48:40 -05:00
standard_initdb " $oldbindir " /initdb
2013-01-03 18:34:57 -05:00
$oldbindir /pg_ctl start -l " $logdir /postmaster1.log " -o " $POSTMASTER_OPTS " -w
2016-08-08 10:07:46 -04:00
# Create databases with names covering the ASCII bytes other than NUL, BEL,
# LF, or CR. BEL would ring the terminal bell in the course of this test, and
# it is not otherwise a special case. PostgreSQL doesn't support the rest.
dbname1 = ` awk ' BEGIN { for ( i = 1; i < 46; i++)
if ( i != 7 && i != 10 && i != 13) printf "%c" , i } ' </dev/null`
# Exercise backslashes adjacent to double quotes, a Windows special case.
dbname1 = '\"\' $dbname1 '\\"\\\'
dbname2 = ` awk 'BEGIN { for (i = 46; i < 91; i++) printf "%c", i }' </dev/null`
dbname3 = ` awk 'BEGIN { for (i = 91; i < 128; i++) printf "%c", i }' </dev/null`
createdb " $dbname1 " || createdb_status = $?
createdb " $dbname2 " || createdb_status = $?
createdb " $dbname3 " || createdb_status = $?
2011-11-27 22:42:32 +02:00
if " $MAKE " -C " $oldsrc " installcheck; then
2012-09-05 17:55:47 -04:00
pg_dumpall -f " $temp_root " /dump1.sql || pg_dumpall1_status = $?
2011-11-27 22:42:32 +02: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
2016-08-08 10:07:46 -04:00
if [ -n " $createdb_status " ] ; then
exit 1
fi
2011-11-27 22:42:32 +02:00
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
2013-03-30 12:54:36 -04:00
PGDATA = $BASE_PGDATA
2011-11-27 22:42:32 +02:00
2014-12-17 22:48:40 -05:00
standard_initdb 'initdb'
2011-11-27 22:42:32 +02:00
pg_upgrade -d " ${ PGDATA } .old " -D " ${ PGDATA } " -b " $oldbindir " -B " $bindir "
2013-01-03 18:34:57 -05:00
pg_ctl start -l " $logdir /postmaster2.log " -o " $POSTMASTER_OPTS " -w
2012-09-03 22:32:56 -04:00
2012-10-18 16:15:49 -04:00
case $testhost in
MINGW*) cmd /c analyze_new_cluster.bat ; ;
*) sh ./analyze_new_cluster.sh ; ;
esac
2012-09-05 17:55:47 -04:00
pg_dumpall -f " $temp_root " /dump2.sql || pg_dumpall2_status = $?
2011-11-27 22:42:32 +02:00
pg_ctl -m fast stop
2013-01-03 18:34:57 -05:00
2011-11-27 22:42:32 +02:00
if [ -n " $pg_dumpall2_status " ] ; then
echo "pg_dumpall of post-upgrade database cluster failed"
exit 1
fi
2012-10-18 16:15:49 -04:00
case $testhost in
MINGW*) cmd /c delete_old_cluster.bat ; ;
*) sh ./delete_old_cluster.sh ; ;
esac
2012-09-03 22:32:56 -04:00
2015-07-08 20:44:21 -04:00
if diff " $temp_root " /dump1.sql " $temp_root " /dump2.sql >/dev/null; then
2011-11-27 22:42:32 +02:00
echo PASSED
exit 0
else
2015-07-08 20:44:21 -04:00
echo " Files $temp_root /dump1.sql and $temp_root /dump2.sql differ "
2011-11-27 22:42:32 +02:00
echo "dumps were not identical"
exit 1
fi