3 # src/bin/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-2021, PostgreSQL Global Development Group
10 # Portions Copyright (c) 1994, Regents of the University of California
16 # Guard against parallel make issues (see comments in pg_regress.c)
20 # Run a given "initdb" binary and overlay the regression testing
21 # authentication configuration.
23 # To increase coverage of non-standard segment size and group access
24 # without increasing test runtime, run these tests with a custom setting.
25 # Also, specify "-A trust" explicitly to suppress initdb's warning.
26 "$1" -N --wal-segsize 1 -g -A trust
27 if [ -n "$TEMP_CONFIG" -a -r "$TEMP_CONFIG" ]
29 cat "$TEMP_CONFIG" >> "$PGDATA/postgresql.conf"
31 ..
/..
/test
/regress
/pg_regress
--config-auth "$PGDATA"
34 # What flavor of host are we on?
35 # Treat MINGW* (msys1) and MSYS* (msys2) the same.
36 testhost
=`uname -s | sed 's/^MSYS/MINGW/'`
38 # Establish how the server will listen for connections
41 LISTEN_ADDRESSES
="localhost"
42 PG_REGRESS_SOCKET_DIR
=""
47 # Select a socket directory. The algorithm is from the "configure"
48 # script; the outcome mimics pg_regress.c:make_temp_sockdir().
49 if [ x
"$PG_REGRESS_SOCKET_DIR" = x
]; then
52 mktemp -d /tmp/pg_upgrade_check-XXXXXX) 2>/dev/null`
53 if [ ! -d "$dir" ]; then
54 dir
=/tmp
/pg_upgrade_check-$$
-$RANDOM
55 (umask 077 && mkdir
"$dir")
56 if [ ! -d "$dir" ]; then
57 echo "could not create socket temporary directory in \"/tmp\""
62 PG_REGRESS_SOCKET_DIR
=$dir
63 trap 'rm -rf "$PG_REGRESS_SOCKET_DIR"' 0
64 trap 'exit 3' 1 2 13 15
66 PGHOST
=$PG_REGRESS_SOCKET_DIR
70 POSTMASTER_OPTS
="-F -c listen_addresses=\"$LISTEN_ADDRESSES\" -k \"$PG_REGRESS_SOCKET_DIR\""
73 # don't rely on $PWD here, as old shells don't set it
74 temp_root
=`pwd`/tmp_check
78 : ${oldbindir=$bindir}
81 oldsrc
=`cd "$oldsrc" && pwd`
82 newsrc
=`cd ../../.. && pwd`
84 # We need to make pg_regress use psql from the desired installation
85 # (likely a temporary one), because otherwise the installcheck run
86 # below would try to use psql from the proper installation directory
87 # of the target version, which might be outdated or not exist. But
88 # don't override anything else that's already in EXTRA_REGRESS_OPTS.
89 EXTRA_REGRESS_OPTS
="$EXTRA_REGRESS_OPTS --bindir='$oldbindir'"
90 export EXTRA_REGRESS_OPTS
92 # While in normal cases this will already be set up, adding bindir to
93 # path allows test.sh to be invoked with different versions as
94 # described in ./TESTING
98 BASE_PGDATA
="$temp_root/data"
99 PGDATA
="${BASE_PGDATA}.old"
102 # Send installcheck outputs to a private directory. This avoids conflict when
103 # check-world runs pg_upgrade check concurrently with src/test/regress check.
104 # To retrieve interesting files after a run, use pattern tmp_check/*/*.diffs.
105 outputdir
="$temp_root/regress"
106 EXTRA_REGRESS_OPTS
="$EXTRA_REGRESS_OPTS --outputdir=$outputdir"
107 export EXTRA_REGRESS_OPTS
114 # Clear out any environment vars that might cause libpq to connect to
115 # the wrong postmaster (cf pg_regress.c)
117 # Some shells, such as NetBSD's, return non-zero from unset if the variable
118 # is already unset. Since we are operating under 'set -e', this causes the
119 # script to fail. To guard against this, set them all to an empty string first.
120 PGDATABASE
=""; unset PGDATABASE
121 PGUSER
=""; unset PGUSER
122 PGSERVICE
=""; unset PGSERVICE
123 PGSSLMODE
=""; unset PGSSLMODE
124 PGREQUIRESSL
=""; unset PGREQUIRESSL
125 PGCONNECT_TIMEOUT
=""; unset PGCONNECT_TIMEOUT
126 PGHOSTADDR
=""; unset PGHOSTADDR
128 # Select a non-conflicting port number, similarly to pg_regress.c
129 PG_VERSION_NUM
=`grep '#define PG_VERSION_NUM' "$newsrc"/src/include/pg_config.h | awk '{print $3}'`
130 PGPORT
=`expr $PG_VERSION_NUM % 16384 + 49152`
134 while psql
-X postgres
</dev
/null
2>/dev
/null
139 echo port
$PGPORT apparently
in use
142 PGPORT
=`expr $PGPORT + 1`
146 # buildfarm may try to override port via EXTRA_REGRESS_OPTS ...
147 EXTRA_REGRESS_OPTS
="$EXTRA_REGRESS_OPTS --port=$PGPORT"
148 export EXTRA_REGRESS_OPTS
150 standard_initdb
"$oldbindir"/initdb
151 "$oldbindir"/pg_ctl start
-l "$logdir/postmaster1.log" -o "$POSTMASTER_OPTS" -w
153 # Create databases with names covering the ASCII bytes other than NUL, BEL,
154 # LF, or CR. BEL would ring the terminal bell in the course of this test, and
155 # it is not otherwise a special case. PostgreSQL doesn't support the rest.
156 dbname1
=`awk 'BEGIN { for (i= 1; i < 46; i++)
157 if (i != 7 && i != 10 && i != 13) printf "%c", i }' </dev/null`
158 # Exercise backslashes adjacent to double quotes, a Windows special case.
159 dbname1
='\"\'$dbname1'\\"\\\'
160 dbname2=`awk 'BEGIN { for (i = 46; i < 91; i++) printf "%c
", i }' </dev/null`
161 dbname3=`awk 'BEGIN { for (i = 91; i < 128; i++) printf "%c
", i }' </dev/null`
162 createdb "regression
$dbname1" || createdb_status=$?
163 createdb "regression
$dbname2" || createdb_status=$?
164 createdb "regression
$dbname3" || createdb_status=$?
166 if "$MAKE" -C "$oldsrc" installcheck-parallel; then
167 oldpgversion=`psql -X -A -t -d regression -c "SHOW server_version_num
"`
169 # before dumping, get rid of objects not feasible in later versions
170 if [ "$newsrc" != "$oldsrc" ]; then
172 case $oldpgversion in
174 fix_sql="DROP FUNCTION public.myfunc
(integer
);"
178 DROP FUNCTION IF EXISTS
179 public.oldstyle_length
(integer
, text
); -- last
in 9.6
180 DROP FUNCTION IF EXISTS
181 public.putenv
(text
); -- last
in v13
182 DROP OPERATOR IF EXISTS
-- last
in v13
183 public.
#@# (pg_catalog.int8, NONE),
184 public.
#%# (pg_catalog.int8, NONE),
185 public.
!=- (pg_catalog.int8
, NONE
),
186 public.
#@%# (pg_catalog.int8, NONE);"
187 psql
-X -d regression
-c "$fix_sql;" || psql_fix_sql_status
=$?
190 pg_dumpall
--no-sync -f "$temp_root"/dump1.sql || pg_dumpall1_status
=$?
192 if [ "$newsrc" != "$oldsrc" ]; then
193 # update references to old source tree's regress.so etc
195 case $oldpgversion in
197 fix_sql
="UPDATE pg_proc SET probin = replace(probin::text, '$oldsrc', '$newsrc')::bytea WHERE probin LIKE '$oldsrc%';"
200 fix_sql
="UPDATE pg_proc SET probin = replace(probin, '$oldsrc', '$newsrc') WHERE probin LIKE '$oldsrc%';"
203 psql
-X -d regression
-c "$fix_sql;" || psql_fix_sql_status
=$?
205 mv "$temp_root"/dump1.sql
"$temp_root"/dump1.sql.orig
206 sed "s;$oldsrc;$newsrc;g" "$temp_root"/dump1.sql.orig
>"$temp_root"/dump1.sql
209 make_installcheck_status
=$?
211 "$oldbindir"/pg_ctl
-m fast stop
212 if [ -n "$createdb_status" ]; then
215 if [ -n "$make_installcheck_status" ]; then
218 if [ -n "$psql_fix_sql_status" ]; then
221 if [ -n "$pg_dumpall1_status" ]; then
222 echo "pg_dumpall of pre-upgrade database cluster failed"
226 PGDATA
="$BASE_PGDATA"
228 standard_initdb
'initdb'
230 pg_upgrade
$PG_UPGRADE_OPTS -d "${PGDATA}.old" -D "$PGDATA" -b "$oldbindir" -p "$PGPORT" -P "$PGPORT"
232 # make sure all directories and files have group permissions, on Unix hosts
233 # Windows hosts don't support Unix-y permissions.
236 *) if [ `find "$PGDATA" -type f ! -perm 640 | wc -l` -ne 0 ]; then
237 echo "files in PGDATA with permission != 640";
244 *) if [ `find "$PGDATA" -type d ! -perm 750 | wc -l` -ne 0 ]; then
245 echo "directories in PGDATA with permission != 750";
250 pg_ctl start
-l "$logdir/postmaster2.log" -o "$POSTMASTER_OPTS" -w
252 pg_dumpall
--no-sync -f "$temp_root"/dump2.sql || pg_dumpall2_status
=$?
255 if [ -n "$pg_dumpall2_status" ]; then
256 echo "pg_dumpall of post-upgrade database cluster failed"
261 MINGW
*) MSYS2_ARG_CONV_EXCL
=/c cmd
/c delete_old_cluster.bat
;;
262 *) sh .
/delete_old_cluster.sh
;;
265 if diff "$temp_root"/dump1.sql
"$temp_root"/dump2.sql
>/dev
/null
; then
269 echo "Files $temp_root/dump1.sql and $temp_root/dump2.sql differ"
270 echo "dumps were not identical"