Skip to content

Commit

Permalink
PG17 compatibility: fix pg16 to pg17 upgrade (#7788)
Browse files Browse the repository at this point in the history
In `citus_prepare_upgrade()`, don't drop any_value when upgrading from
PG16+, because PG16+ has its own any_value function. Attempting to do so
results in the error seen in [pg16-pg17
upgrade](https://github.com/citusdata/citus/actions/runs/11768444117/job/32778340003?pr=7661):
```
ERROR:  cannot drop function any_value(anyelement) because it is required by the database system
CONTEXT:  SQL statement "DROP AGGREGATE IF EXISTS pg_catalog.any_value(anyelement)"
```
When 16 becomes the minimum supported Postgres version, the drop
statements can be removed.
  • Loading branch information
colm-mchugh authored and naisila committed Dec 24, 2024
1 parent aee59ca commit 83e7371
Show file tree
Hide file tree
Showing 3 changed files with 109 additions and 6 deletions.
1 change: 1 addition & 0 deletions src/backend/distributed/sql/citus--12.1-1--13.0-1.sql
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
-- citus--12.1-1--13.0-1.sql

-- bump version to 13.0-1
#include "udfs/citus_prepare_pg_upgrade/13.0-1.sql"
100 changes: 100 additions & 0 deletions src/backend/distributed/sql/udfs/citus_prepare_pg_upgrade/13.0-1.sql

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,15 @@ BEGIN
DROP AGGREGATE IF EXISTS array_cat_agg(anyarray);
DROP AGGREGATE IF EXISTS array_cat_agg(anycompatiblearray);

-- We should drop any_value because PG16 has its own any_value function
-- We should drop any_value because PG16+ has its own any_value function
-- We can remove this part when we drop support for PG16
DELETE FROM pg_depend WHERE
objid IN (SELECT oid FROM pg_proc WHERE proname = 'any_value' OR proname = 'any_value_agg') AND
refobjid IN (select oid from pg_extension where extname = 'citus');
DROP AGGREGATE IF EXISTS pg_catalog.any_value(anyelement);
DROP FUNCTION IF EXISTS pg_catalog.any_value_agg(anyelement, anyelement);
IF substring(current_Setting('server_version'), '\d+')::int < 16 THEN
DELETE FROM pg_depend WHERE
objid IN (SELECT oid FROM pg_proc WHERE proname = 'any_value' OR proname = 'any_value_agg') AND
refobjid IN (select oid from pg_extension where extname = 'citus');
DROP AGGREGATE IF EXISTS pg_catalog.any_value(anyelement);
DROP FUNCTION IF EXISTS pg_catalog.any_value_agg(anyelement, anyelement);
END IF;

--
-- Drop existing backup tables
Expand Down

0 comments on commit 83e7371

Please sign in to comment.