Skip to content

Commit 0e603b7

Browse files
committed
Move into separate file all the SQL queries used in pg_upgrade tests
The existing pg_upgrade/test.sh and the buildfarm code have been holding the same set of SQL queries when doing cross-version upgrade tests to adapt the objects created by the regression tests before the upgrade (mostly, incompatible or non-existing objects need to be dropped from the origin, perhaps re-created). This moves all those SQL queries into a new, separate, file with a set of \if clauses to handle the version checks depending on the old version of the cluster to-be-upgraded. The long-term plan is to make the buildfarm code re-use this new SQL file, so as committers are able to fix any compatibility issues in the tests of pg_upgrade with a refresh of the core code, without having to poke at the buildfarm client. Note that this is only able to handle the main regression test suite, and that nothing is done yet for contrib modules yet (these have more issues like their database names). A backpatch down to 10 is done, adapting the version checks as this script needs to be only backward-compatible, so as it becomes possible to clean up a maximum amount of code within the buildfarm client. Author: Justin Pryzby, Michael Paquier Discussion: https://postgr.es/m/20201206180248.GI24052@telsasoft.com Backpatch-through: 10
1 parent 82d3544 commit 0e603b7

File tree

2 files changed

+63
-10
lines changed

2 files changed

+63
-10
lines changed

src/bin/pg_upgrade/test.sh

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -186,16 +186,11 @@ if "$MAKE" -C "$oldsrc" installcheck; then
186186

187187
# before dumping, get rid of objects not feasible in later versions
188188
if [ "$newsrc" != "$oldsrc" ]; then
189-
fix_sql=""
190-
case $oldpgversion in
191-
804??)
192-
fix_sql="DROP FUNCTION public.myfunc(integer);"
193-
;;
194-
esac
195-
fix_sql="$fix_sql
196-
DROP FUNCTION IF EXISTS
197-
public.oldstyle_length(integer, text); -- last in 9.6";
198-
psql -X -d regression -c "$fix_sql;" || psql_fix_sql_status=$?
189+
# This SQL script has its own idea of the cleanup that needs to be
190+
# done on the cluster to-be-upgraded, and includes version checks.
191+
# Note that this uses the script stored on the new branch.
192+
psql -X -d regression -f "$newsrc/src/bin/pg_upgrade/upgrade_adapt.sql" \
193+
|| psql_fix_sql_status=$?
199194
fi
200195

201196
pg_dumpall --no-sync -f "$temp_root"/dump1.sql || pg_dumpall1_status=$?

src/bin/pg_upgrade/upgrade_adapt.sql

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
--
2+
-- SQL queries for upgrade tests across different major versions.
3+
--
4+
-- This file includes a set of SQL queries to make a cluster to-be-upgraded
5+
-- compatible with the version this file is based on. Note that this
6+
-- requires psql, as per-version queries are controlled with a set of \if
7+
-- clauses.
8+
9+
-- This script is backward-compatible, so it is able to work with any version
10+
-- newer than 9.2 we are upgrading from, up to the branch this script is stored
11+
-- on (even if this would not run if running pg_upgrade with the same version
12+
-- for the origin and the target).
13+
14+
-- \if accepts a simple boolean value, so all the version checks are
15+
-- saved based on this assumption.
16+
SELECT
17+
ver <= 902 AS oldpgversion_le92,
18+
ver <= 904 AS oldpgversion_le94,
19+
ver <= 906 AS oldpgversion_le96,
20+
ver <= 1000 AS oldpgversion_le10
21+
FROM (SELECT current_setting('server_version_num')::int / 100 AS ver) AS v;
22+
\gset
23+
24+
-- Objects last appearing in 9.2.
25+
\if :oldpgversion_le92
26+
-- Note that those tables are removed from the regression tests in 9.3
27+
-- and newer versions.
28+
DROP TABLE abstime_tbl;
29+
DROP TABLE reltime_tbl;
30+
DROP TABLE tinterval_tbl;
31+
\endif
32+
33+
-- Objects last appearing in 9.4.
34+
\if :oldpgversion_le94
35+
-- This aggregate has been fixed in 9.5 and later versions, so drop
36+
-- and re-create it.
37+
DROP AGGREGATE array_cat_accum(anyarray);
38+
CREATE AGGREGATE array_larger_accum (anyarray) (
39+
sfunc = array_larger,
40+
stype = anyarray,
41+
initcond = $${}$$);
42+
-- This operator has been fixed in 9.5 and later versions, so drop and
43+
-- re-create it.
44+
DROP OPERATOR @#@ (NONE, bigint);
45+
CREATE OPERATOR @#@ (PROCEDURE = factorial,
46+
RIGHTARG = bigint);
47+
\endif
48+
49+
-- Objects last appearing in 9.6.
50+
\if :oldpgversion_le96
51+
DROP FUNCTION public.oldstyle_length(integer, text);
52+
\endif
53+
54+
-- Objects last appearing in 10.
55+
\if :oldpgversion_le10
56+
DROP FUNCTION IF EXISTS boxarea(box);
57+
DROP FUNCTION IF EXISTS funny_dup17();
58+
\endif

0 commit comments

Comments
 (0)