Move into separate file all the SQL queries used in pg_upgrade tests
authorMichael Paquier <[email protected]>
Thu, 2 Dec 2021 01:31:48 +0000 (10:31 +0900)
committerMichael Paquier <[email protected]>
Thu, 2 Dec 2021 01:31:48 +0000 (10:31 +0900)
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[email protected]
Backpatch-through: 10

src/bin/pg_upgrade/test.sh
src/bin/pg_upgrade/upgrade_adapt.sql [new file with mode: 0644]

index 0a4047ed7cb86a33d0c2fb4952a297e6ff0cddb0..b97d4e9af3c86861ad394b1f154cd9f15ad3063e 100644 (file)
@@ -184,16 +184,11 @@ if "$MAKE" -C "$oldsrc" installcheck; then
 
    # before dumping, get rid of objects not feasible in later versions
    if [ "$newsrc" != "$oldsrc" ]; then
-       fix_sql=""
-       case $oldpgversion in
-           804??)
-               fix_sql="DROP FUNCTION public.myfunc(integer);"
-               ;;
-       esac
-       fix_sql="$fix_sql
-                DROP FUNCTION IF EXISTS
-                   public.oldstyle_length(integer, text);  -- last in 9.6";
-       psql -X -d regression -c "$fix_sql;" || psql_fix_sql_status=$?
+       # This SQL script has its own idea of the cleanup that needs to be
+       # done on the cluster to-be-upgraded, and includes version checks.
+       # Note that this uses the script stored on the new branch.
+       psql -X -d regression -f "$newsrc/src/bin/pg_upgrade/upgrade_adapt.sql" \
+           || psql_fix_sql_status=$?
    fi
 
    pg_dumpall --no-sync -f "$temp_root"/dump1.sql || pg_dumpall1_status=$?
diff --git a/src/bin/pg_upgrade/upgrade_adapt.sql b/src/bin/pg_upgrade/upgrade_adapt.sql
new file mode 100644 (file)
index 0000000..8677a18
--- /dev/null
@@ -0,0 +1,51 @@
+--
+-- SQL queries for upgrade tests across different major versions.
+--
+-- This file includes a set of SQL queries to make a cluster to-be-upgraded
+-- compatible with the version this file is based on.  Note that this
+-- requires psql, as per-version queries are controlled with a set of \if
+-- clauses.
+
+-- This script is backward-compatible, so it is able to work with any version
+-- newer than 9.2 we are upgrading from, up to the branch this script is stored
+-- on (even if this would not run if running pg_upgrade with the same version
+-- for the origin and the target).
+
+-- \if accepts a simple boolean value, so all the version checks are
+-- saved based on this assumption.
+SELECT
+  ver <= 902 AS oldpgversion_le92,
+  ver <= 904 AS oldpgversion_le94,
+  ver <= 906 AS oldpgversion_le96
+  FROM (SELECT current_setting('server_version_num')::int / 100 AS ver) AS v;
+\gset
+
+-- Objects last appearing in 9.2.
+\if :oldpgversion_le92
+-- Note that those tables are removed from the regression tests in 9.3
+-- and newer versions.
+DROP TABLE abstime_tbl;
+DROP TABLE reltime_tbl;
+DROP TABLE tinterval_tbl;
+\endif
+
+-- Objects last appearing in 9.4.
+\if :oldpgversion_le94
+-- This aggregate has been fixed in 9.5 and later versions, so drop
+-- and re-create it.
+DROP AGGREGATE array_cat_accum(anyarray);
+CREATE AGGREGATE array_larger_accum (anyarray) (
+                  sfunc = array_larger,
+                  stype = anyarray,
+                  initcond = $${}$$);
+-- This operator has been fixed in 9.5 and later versions, so drop and
+-- re-create it.
+DROP OPERATOR @#@ (NONE, bigint);
+CREATE OPERATOR @#@ (PROCEDURE = factorial,
+                     RIGHTARG = bigint);
+\endif
+
+-- Objects last appearing in 9.6.
+\if :oldpgversion_le96
+DROP FUNCTION public.oldstyle_length(integer, text);
+\endif