Skip to content

Commit fa66b6d

Browse files
committed
Fix tests of pg_upgrade across different major versions
This fixes a set of issues that cause different breakages or annoyances when using pg_upgrade's test.sh to do upgrades across different major versions: - test.sh is completely broken when using v14 as new version because of the removal of testtablespace/ as Makefile rule. Older versions of pg_regress don't support --make-tablespacedir, blocking the creation of the tablespace. In order to fix that, it is simple enough to create those directories in the script itself, but only do that when an old version is involved. This fix is needed on HEAD and REL_14_STABLE. - The script would fail when using PG <= v11 as old version because of WITH OIDS relations not supported in v12. In order to fix this, this steals a method from the buildfarm that uses a DO block to change all the relations marked as WITH OIDS, allowing pg_upgrade to pass. This is more portable than using ALTER TABLE queries on the relations causing issues. This is fixed down to v12, and authored originally by Andrew Dunstan. - Not using --extra-float-digits=0 with v11 as old version causes a lot of diffs in the dumps, making the whole unreadable. This gets only done when using v11 as old version. This is fixed down to v12. The buildfarm code uses that already. Note that the addition of --wal-segsize and --allow-group-access breaks the script when using v10 or older at initdb time as these got added in 11. 10 would be EOL'd next year and nobody has complained about those problems yet, so nothing is done about that. This means that this commit fixes upgrade tests using test.sh with v11 as minimum older version, up to HEAD, and that it is enough to apply this change down to 12. The old and new dumps still generate diffs, still require manual checks, and more could be done to reduce the noise, but this allows the tests to run with a rather minimal amount of them. I have tested this commit and test.sh with v11 as minimum across all the branches where this is applied. Note that this commit has no impact on the normal pg_upgrade test run with a simple "make check". Author: Justin Pryzby, Andrew Dunstan, Michael Paquier Discussion: https://postgr.es/m/20201206180248.GI24052@telsasoft.com Backpatch-through: 12
1 parent 390edee commit fa66b6d

File tree

1 file changed

+59
-7
lines changed

1 file changed

+59
-7
lines changed

src/bin/pg_upgrade/test.sh

Lines changed: 59 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,8 @@ standard_initdb() {
2323
# To increase coverage of non-standard segment size and group access
2424
# without increasing test runtime, run these tests with a custom setting.
2525
# Also, specify "-A trust" explicitly to suppress initdb's warning.
26-
"$1" -N --wal-segsize 1 -g -A trust
26+
# --allow-group-access and --wal-segsize have been added in v11.
27+
"$1" -N --wal-segsize 1 --allow-group-access -A trust
2728
if [ -n "$TEMP_CONFIG" -a -r "$TEMP_CONFIG" ]
2829
then
2930
cat "$TEMP_CONFIG" >> "$PGDATA/postgresql.conf"
@@ -107,6 +108,14 @@ EXTRA_REGRESS_OPTS="$EXTRA_REGRESS_OPTS --outputdir=$outputdir"
107108
export EXTRA_REGRESS_OPTS
108109
mkdir "$outputdir"
109110

111+
# pg_regress --make-tablespacedir would take care of that in 14~, but this is
112+
# still required for older versions where this option is not supported.
113+
if [ "$newsrc" != "$oldsrc" ]; then
114+
mkdir "$outputdir"/testtablespace
115+
mkdir "$outputdir"/sql
116+
mkdir "$outputdir"/expected
117+
fi
118+
110119
logdir=`pwd`/log
111120
rm -rf "$logdir"
112121
mkdir "$logdir"
@@ -163,31 +172,73 @@ createdb "regression$dbname1" || createdb_status=$?
163172
createdb "regression$dbname2" || createdb_status=$?
164173
createdb "regression$dbname3" || createdb_status=$?
165174

175+
# Extra options to apply to the dump. This may be changed later.
176+
extra_dump_options=""
177+
166178
if "$MAKE" -C "$oldsrc" installcheck-parallel; then
167179
oldpgversion=`psql -X -A -t -d regression -c "SHOW server_version_num"`
168180

169-
# before dumping, get rid of objects not feasible in later versions
181+
# Before dumping, tweak the database of the old instance depending
182+
# on its version.
170183
if [ "$newsrc" != "$oldsrc" ]; then
171184
fix_sql=""
185+
# Get rid of objects not feasible in later versions
172186
case $oldpgversion in
173187
804??)
174188
fix_sql="DROP FUNCTION public.myfunc(integer);"
175189
;;
176190
esac
177-
fix_sql="$fix_sql
178-
DROP FUNCTION IF EXISTS
179-
public.oldstyle_length(integer, text); -- last in 9.6
191+
192+
# Last appeared in v9.6
193+
if [ $oldpgversion -lt 100000 ]; then
194+
fix_sql="$fix_sql
195+
DROP FUNCTION IF EXISTS
196+
public.oldstyle_length(integer, text);"
197+
fi
198+
# Last appeared in v13
199+
if [ $oldpgversion -lt 140000 ]; then
200+
fix_sql="$fix_sql
180201
DROP FUNCTION IF EXISTS
181202
public.putenv(text); -- last in v13
182203
DROP OPERATOR IF EXISTS -- last in v13
183204
public.#@# (pg_catalog.int8, NONE),
184205
public.#%# (pg_catalog.int8, NONE),
185206
public.!=- (pg_catalog.int8, NONE),
186207
public.#@%# (pg_catalog.int8, NONE);"
208+
fi
187209
psql -X -d regression -c "$fix_sql;" || psql_fix_sql_status=$?
210+
211+
# WITH OIDS is not supported anymore in v12, so remove support
212+
# for any relations marked as such.
213+
if [ $oldpgversion -lt 120000 ]; then
214+
fix_sql="DO \$stmt\$
215+
DECLARE
216+
rec text;
217+
BEGIN
218+
FOR rec in
219+
SELECT oid::regclass::text
220+
FROM pg_class
221+
WHERE relname !~ '^pg_'
222+
AND relhasoids
223+
AND relkind in ('r','m')
224+
ORDER BY 1
225+
LOOP
226+
execute 'ALTER TABLE ' || rec || ' SET WITHOUT OIDS';
227+
END LOOP;
228+
END; \$stmt\$;"
229+
psql -X -d regression -c "$fix_sql;" || psql_fix_sql_status=$?
230+
fi
231+
232+
# Handling of --extra-float-digits gets messy after v12.
233+
# Note that this changes the dumps from the old and new
234+
# instances if involving an old cluster of v11 or older.
235+
if [ $oldpgversion -lt 120000 ]; then
236+
extra_dump_options="--extra-float-digits=0"
237+
fi
188238
fi
189239

190-
pg_dumpall --no-sync -f "$temp_root"/dump1.sql || pg_dumpall1_status=$?
240+
pg_dumpall $extra_dump_options --no-sync \
241+
-f "$temp_root"/dump1.sql || pg_dumpall1_status=$?
191242

192243
if [ "$newsrc" != "$oldsrc" ]; then
193244
# update references to old source tree's regress.so etc
@@ -249,7 +300,8 @@ esac
249300

250301
pg_ctl start -l "$logdir/postmaster2.log" -o "$POSTMASTER_OPTS" -w
251302

252-
pg_dumpall --no-sync -f "$temp_root"/dump2.sql || pg_dumpall2_status=$?
303+
pg_dumpall $extra_dump_options --no-sync \
304+
-f "$temp_root"/dump2.sql || pg_dumpall2_status=$?
253305
pg_ctl -m fast stop
254306

255307
if [ -n "$pg_dumpall2_status" ]; then

0 commit comments

Comments
 (0)