3 # contrib/pg_upgrade/test.sh
5 # Test driver for pg_upgrade. Initializes a new database cluster,
6 # runs the regression tests (to put in some data), runs pg_dumpall,
7 # runs pg_upgrade, runs pg_dumpall again, compares the dumps.
9 # Portions Copyright (c) 1996-2011, PostgreSQL Global Development Group
10 # Portions Copyright (c) 1994, Regents of the University of California
18 temp_root=$PWD/tmp_check
20 if [ "$1" = '--install' ]; then
21 temp_install=$temp_root/install
22 bindir=$temp_install/$bindir
23 libdir=$temp_install/$libdir
25 "$MAKE" -s -C ../.. install DESTDIR="$temp_install"
26 "$MAKE" -s -C ../pg_upgrade_support install DESTDIR="$temp_install"
27 "$MAKE" -s -C . install DESTDIR="$temp_install"
29 # platform-specific magic to find the shared libraries; see pg_regress.c
30 LD_LIBRARY_PATH=$libdir:$LD_LIBRARY_PATH
31 export LD_LIBRARY_PATH
32 DYLD_LIBRARY_PATH=$libdir:$DYLD_LIBRARY_PATH
33 export DYLD_LIBRARY_PATH
34 LIBPATH=$libdir:$LIBPATH
38 # We need to make it use psql from our temporary installation,
39 # because otherwise the installcheck run below would try to
40 # use psql from the proper installation directory, which might
41 # be outdated or missing.
42 EXTRA_REGRESS_OPTS=--psqldir=$bindir
43 export EXTRA_REGRESS_OPTS
46 : ${oldbindir=$bindir}
49 oldsrc=`cd "$oldsrc" && pwd`
50 newsrc=`cd ../.. && pwd`
55 PGDATA=$temp_root/data
57 rm -rf "$PGDATA" "$PGDATA".old
66 $oldbindir/pg_ctl start -l "$logdir/postmaster1.log" -w
67 if "$MAKE" -C "$oldsrc" installcheck; then
68 pg_dumpall >"$temp_root"/dump1.sql || pg_dumpall1_status=$?
69 if [ "$newsrc" != "$oldsrc" ]; then
70 oldpgversion=`psql -A -t -d regression -c "SHOW server_version_num"`
74 fix_sql="UPDATE pg_proc SET probin = replace(probin::text, '$oldsrc', '$newsrc')::bytea WHERE probin LIKE '$oldsrc%'; DROP FUNCTION public.myfunc(integer);"
77 fix_sql="SET bytea_output TO escape; UPDATE pg_proc SET probin = replace(probin::text, '$oldsrc', '$newsrc')::bytea WHERE probin LIKE '$oldsrc%';"
80 fix_sql="UPDATE pg_proc SET probin = replace(probin, '$oldsrc', '$newsrc') WHERE probin LIKE '$oldsrc%';"
83 psql -d regression -c "$fix_sql;" || psql_fix_sql_status=$?
85 mv "$temp_root"/dump1.sql "$temp_root"/dump1.sql.orig
86 sed "s;$oldsrc;$newsrc;g" "$temp_root"/dump1.sql.orig >"$temp_root"/dump1.sql
89 make_installcheck_status=$?
91 $oldbindir/pg_ctl -m fast stop
92 if [ -n "$make_installcheck_status" ]; then
95 if [ -n "$psql_fix_sql_status" ]; then
98 if [ -n "$pg_dumpall1_status" ]; then
99 echo "pg_dumpall of pre-upgrade database cluster failed"
103 mv "${PGDATA}" "${PGDATA}.old"
107 pg_upgrade -d "${PGDATA}.old" -D "${PGDATA}" -b "$oldbindir" -B "$bindir"
109 pg_ctl start -l "$logdir/postmaster2.log" -w
110 pg_dumpall >"$temp_root"/dump2.sql || pg_dumpall2_status=$?
112 if [ -n "$pg_dumpall2_status" ]; then
113 echo "pg_dumpall of post-upgrade database cluster failed"
117 if diff -q "$temp_root"/dump1.sql "$temp_root"/dump2.sql; then
121 echo "dumps were not identical"