Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 0df9641

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 babe545 commit 0df9641

File tree

2 files changed

+96
-47
lines changed

2 files changed

+96
-47
lines changed

src/bin/pg_upgrade/test.sh

+5-47
Original file line numberDiff line numberDiff line change
@@ -181,53 +181,11 @@ if "$MAKE" -C "$oldsrc" installcheck-parallel; then
181181
# Before dumping, tweak the database of the old instance depending
182182
# on its version.
183183
if [ "$newsrc" != "$oldsrc" ]; then
184-
fix_sql=""
185-
# Get rid of objects not feasible in later versions
186-
case $oldpgversion in
187-
804??)
188-
fix_sql="DROP FUNCTION public.myfunc(integer);"
189-
;;
190-
esac
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
201-
DROP FUNCTION IF EXISTS
202-
public.putenv(text); -- last in v13
203-
DROP OPERATOR IF EXISTS -- last in v13
204-
public.#@# (pg_catalog.int8, NONE),
205-
public.#%# (pg_catalog.int8, NONE),
206-
public.!=- (pg_catalog.int8, NONE),
207-
public.#@%# (pg_catalog.int8, NONE);"
208-
fi
209-
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
184+
# This SQL script has its own idea of the cleanup that needs to be
185+
# done on the cluster to-be-upgraded, and includes version checks.
186+
# Note that this uses the script stored on the new branch.
187+
psql -X -d regression -f "$newsrc/src/bin/pg_upgrade/upgrade_adapt.sql" \
188+
|| psql_fix_sql_status=$?
231189

232190
# Handling of --extra-float-digits gets messy after v12.
233191
# Note that this changes the dumps from the old and new

src/bin/pg_upgrade/upgrade_adapt.sql

+91
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
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+
ver <= 1100 AS oldpgversion_le11,
22+
ver <= 1300 AS oldpgversion_le13
23+
FROM (SELECT current_setting('server_version_num')::int / 100 AS ver) AS v;
24+
\gset
25+
26+
-- Objects last appearing in 9.2.
27+
\if :oldpgversion_le92
28+
-- Note that those tables are removed from the regression tests in 9.3
29+
-- and newer versions.
30+
DROP TABLE abstime_tbl;
31+
DROP TABLE reltime_tbl;
32+
DROP TABLE tinterval_tbl;
33+
\endif
34+
35+
-- Objects last appearing in 9.4.
36+
\if :oldpgversion_le94
37+
-- This aggregate has been fixed in 9.5 and later versions, so drop
38+
-- and re-create it.
39+
DROP AGGREGATE array_cat_accum(anyarray);
40+
CREATE AGGREGATE array_larger_accum (anyarray) (
41+
sfunc = array_larger,
42+
stype = anyarray,
43+
initcond = $${}$$);
44+
-- This operator has been fixed in 9.5 and later versions, so drop and
45+
-- re-create it.
46+
DROP OPERATOR @#@ (NONE, bigint);
47+
CREATE OPERATOR @#@ (PROCEDURE = factorial,
48+
RIGHTARG = bigint);
49+
\endif
50+
51+
-- Objects last appearing in 9.6.
52+
\if :oldpgversion_le96
53+
DROP FUNCTION public.oldstyle_length(integer, text);
54+
\endif
55+
56+
-- Objects last appearing in 10.
57+
\if :oldpgversion_le10
58+
DROP FUNCTION IF EXISTS boxarea(box);
59+
DROP FUNCTION IF EXISTS funny_dup17();
60+
\endif
61+
62+
-- Objects last appearing in 11.
63+
\if :oldpgversion_le11
64+
-- WITH OIDS is supported until v11, so remove its support for any
65+
-- relations marked as such.
66+
DO $stmt$
67+
DECLARE
68+
rec text;
69+
BEGIN
70+
FOR rec in
71+
SELECT oid::regclass::text
72+
FROM pg_class
73+
WHERE relname !~ '^pg_'
74+
AND relhasoids
75+
AND relkind in ('r','m')
76+
ORDER BY 1
77+
LOOP
78+
execute 'ALTER TABLE ' || rec || ' SET WITHOUT OIDS';
79+
END LOOP;
80+
END; $stmt$;
81+
\endif
82+
83+
-- Objects last appearing in 13.
84+
\if :oldpgversion_le13
85+
-- Until v10, operators could only be dropped one at a time, so be careful
86+
-- to stick with one command for each drop here.
87+
DROP OPERATOR public.#@# (pg_catalog.int8, NONE);
88+
DROP OPERATOR public.#%# (pg_catalog.int8, NONE);
89+
DROP OPERATOR public.!=- (pg_catalog.int8, NONE);
90+
DROP OPERATOR public.#@%# (pg_catalog.int8, NONE);
91+
\endif

0 commit comments

Comments
 (0)