|
| 1 | +#!/bin/sh |
| 2 | + |
| 3 | +# contrib/pg_upgrade/test.sh |
| 4 | +# |
| 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. |
| 8 | +# |
| 9 | +# Portions Copyright (c) 1996-2011, PostgreSQL Global Development Group |
| 10 | +# Portions Copyright (c) 1994, Regents of the University of California |
| 11 | + |
| 12 | +set -e |
| 13 | + |
| 14 | +: ${MAKE=make} |
| 15 | +: ${PGPORT=50432} |
| 16 | +export PGPORT |
| 17 | + |
| 18 | +temp_root=$PWD/tmp_check |
| 19 | + |
| 20 | +if [ "$1" = '--install' ]; then |
| 21 | + temp_install=$temp_root/install |
| 22 | + bindir=$temp_install/$bindir |
| 23 | + libdir=$temp_install/$libdir |
| 24 | + |
| 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" |
| 28 | + |
| 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 |
| 35 | + export LIBPATH |
| 36 | + PATH=$libdir:$PATH |
| 37 | + |
| 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 |
| 44 | +fi |
| 45 | + |
| 46 | +: ${oldbindir=$bindir} |
| 47 | + |
| 48 | +: ${oldsrc=../..} |
| 49 | +oldsrc=`cd "$oldsrc" && pwd` |
| 50 | +newsrc=`cd ../.. && pwd` |
| 51 | + |
| 52 | +PATH=$bindir:$PATH |
| 53 | +export PATH |
| 54 | + |
| 55 | +PGDATA=$temp_root/data |
| 56 | +export PGDATA |
| 57 | +rm -rf "$PGDATA" "$PGDATA".old |
| 58 | + |
| 59 | +logdir=$PWD/log |
| 60 | +rm -rf "$logdir" |
| 61 | +mkdir "$logdir" |
| 62 | + |
| 63 | +set -x |
| 64 | + |
| 65 | +$oldbindir/initdb |
| 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"` |
| 71 | + fix_sql="" |
| 72 | + case $oldpgversion in |
| 73 | + 804??) |
| 74 | + fix_sql="UPDATE pg_proc SET probin = replace(probin::text, '$oldsrc', '$newsrc')::bytea WHERE probin LIKE '$oldsrc%'; DROP FUNCTION public.myfunc(integer);" |
| 75 | + ;; |
| 76 | + 900??) |
| 77 | + fix_sql="SET bytea_output TO escape; UPDATE pg_proc SET probin = replace(probin::text, '$oldsrc', '$newsrc')::bytea WHERE probin LIKE '$oldsrc%';" |
| 78 | + ;; |
| 79 | + 901??) |
| 80 | + fix_sql="UPDATE pg_proc SET probin = replace(probin, '$oldsrc', '$newsrc') WHERE probin LIKE '$oldsrc%';" |
| 81 | + ;; |
| 82 | + esac |
| 83 | + psql -d regression -c "$fix_sql;" || psql_fix_sql_status=$? |
| 84 | + |
| 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 |
| 87 | + fi |
| 88 | +else |
| 89 | + make_installcheck_status=$? |
| 90 | +fi |
| 91 | +$oldbindir/pg_ctl -m fast stop |
| 92 | +if [ -n "$make_installcheck_status" ]; then |
| 93 | + exit 1 |
| 94 | +fi |
| 95 | +if [ -n "$psql_fix_sql_status" ]; then |
| 96 | + exit 1 |
| 97 | +fi |
| 98 | +if [ -n "$pg_dumpall1_status" ]; then |
| 99 | + echo "pg_dumpall of pre-upgrade database cluster failed" |
| 100 | + exit 1 |
| 101 | +fi |
| 102 | + |
| 103 | +mv "${PGDATA}" "${PGDATA}.old" |
| 104 | + |
| 105 | +initdb |
| 106 | + |
| 107 | +pg_upgrade -d "${PGDATA}.old" -D "${PGDATA}" -b "$oldbindir" -B "$bindir" |
| 108 | + |
| 109 | +pg_ctl start -l "$logdir/postmaster2.log" -w |
| 110 | +pg_dumpall >"$temp_root"/dump2.sql || pg_dumpall2_status=$? |
| 111 | +pg_ctl -m fast stop |
| 112 | +if [ -n "$pg_dumpall2_status" ]; then |
| 113 | + echo "pg_dumpall of post-upgrade database cluster failed" |
| 114 | + exit 1 |
| 115 | +fi |
| 116 | + |
| 117 | +if diff -q "$temp_root"/dump1.sql "$temp_root"/dump2.sql; then |
| 118 | + echo PASSED |
| 119 | + exit 0 |
| 120 | +else |
| 121 | + echo "dumps were not identical" |
| 122 | + exit 1 |
| 123 | +fi |
0 commit comments