Updating "anyarray" or "anyelement" polymorphic functions when upgrading to 14.x or higher on AWS RDS aurora postgresql

huangapple go评论59阅读模式
英文:

Updating "anyarray" or "anyelement" polymorphic functions when upgrading to 14.x or higher on AWS RDS aurora postgresql

问题

在将AWS RDS Aurora PostgreSQL集群从11.17升级到15.2时,在pg_upgrade日志中遇到了以下致命错误:

致命错误
您的安装包含引用内部多态函数的用户定义对象,其参数类型为"anyarray"或"anyelement"。
在升级之前必须删除这些用户定义对象,然后在之后恢复它们,将它们更改为引用新的相应函数,其参数类型为"anycompatiblearray"和"anycompatible"。

AWS在升级文档中没有提到这一点,因此我认为这些更改可能是由系统用户引入的。经过一些调查,似乎聚合函数已更改了类型的命名方式(在明确指出的情况下,是在PostgreSQL版本14中)。那么我该如何更新呢?

我在目标集群中的每个数据库上运行了一部分升级失败的查询:

--在每个数据库上查找不兼容项:
\c <DATABASE>

SELECT 'aggregate' AS objkind,
       p.oid::regprocedure::text AS objname
FROM pg_proc AS p
JOIN pg_aggregate AS a ON a.aggfnoid=p.oid
JOIN pg_proc AS transfn ON transfn.oid=a.aggtransfn
WHERE p.oid >= 16384
  AND a.aggtransfn = ANY(ARRAY['array_append(anyarray,anyelement)', 'array_cat(anyarray,anyarray)', 'array_prepend(anyelement,anyarray)', 'array_remove(anyarray,anyelement)', 'array_replace(anyarray,anyelement,anyelement)', 'array_position(anyarray,anyelement)', 'array_position(anyarray,anyelement,integer)', 'array_positions(anyarray,anyelement)', 'width_bucket(anyelement,anyarray)']::regprocedure[]);

  objkind  |         objname         
-----------+-------------------------
 aggregate | array_accum(anyelement)
(1 row)

好的,现在怎么办?

英文:

When upgrading AWS RDS aurora postgresql cluster from 11.17 -> 15.2, I was met with this fatal error in the pg_upgrade logs:

fatal
Your installation contains user-defined objects that refer to internal
polymorphic functions with arguments of type &quot;anyarray&quot; or &quot;anyelement&quot;.
These user-defined objects must be dropped before upgrading and restored
afterwards, changing them to refer to the new corresponding functions with
arguments of type &quot;anycompatiblearray&quot; and &quot;anycompatible&quot;.

AWS does not mention this in the upgrade docs, so I thought the changed may have been introduced by a system user. After a bit of digging, it seems that the aggregate functions changed the way the types are named (in postgresql version 14 to be clear). So how do I update this?

I ran a subset the query that the upgrade failed on, on each DB in the target cluster:

--find incompatibilites on each DB:
\c &lt;DATABASE&gt;

SELECT &#39;aggregate&#39; AS objkind,
       p.oid::regprocedure::text AS objname
FROM pg_proc AS p
JOIN pg_aggregate AS a ON a.aggfnoid=p.oid
JOIN pg_proc AS transfn ON transfn.oid=a.aggtransfn
WHERE p.oid &gt;= 16384
  AND a.aggtransfn = ANY(ARRAY[&#39;array_append(anyarray,anyelement)&#39;, &#39;array_cat(anyarray,anyarray)&#39;, &#39;array_prepend(anyelement,anyarray)&#39;, &#39;array_remove(anyarray,anyelement)&#39;, &#39;array_replace(anyarray,anyelement,anyelement)&#39;, &#39;array_position(anyarray,anyelement)&#39;, &#39;array_position(anyarray,anyelement,integer)&#39;, &#39;array_positions(anyarray,anyelement)&#39;, &#39;width_bucket(anyelement,anyarray)&#39;]::regprocedure[]);

  objkind  |         objname         
-----------+-------------------------
 aggregate | array_accum(anyelement)
(1 row)

Okay, so now what?

答案1

得分: 2

解决方案:

--从子 14.x 数据库中删除聚合函数
mygreatdatabase=&gt; DROP AGGREGATE array_accum(anyelement);
DROP AGGREGATE

--升级到 14.x 或更高版本,然后使用更新后的类型重新创建:
mygreatdatabase=&gt; CREATE AGGREGATE array_accum(anycompatible) (SFUNC = array_append,STYPE = anycompatiblearray,INITCOND = &#39;{}&#39;);

希望 AWS 将此内容添加到 RDS Aurora PostgresQL 升级预检文档中,但在那方面更加明确之前,这里将保留这一信息。

英文:

Solution:

--drop aggregate from sub 14.x db
mygreatdatabase=&gt; DROP AGGREGATE array_accum(anyelement);
DROP AGGREGATE

--upgrade to 14.x or higher, and then re-create using updated type:
mygreatdatabase=&gt; CREATE AGGREGATE array_accum(anycompatible) (SFUNC = array_append,STYPE = anycompatiblearray,INITCOND = &#39;{}&#39;);

My hope is that AWS adds this to the documentation on RDS Aurora PostgresQL Upgrade Pre-Checks, but this will be here until that is more clear.

huangapple
  • 本文由 发表于 2023年6月2日 04:08:49
  • 转载请务必保留本文链接:https://go.coder-hub.com/76385364.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定