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

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

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日志中遇到了以下致命错误:

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

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

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

  1. --在每个数据库上查找不兼容项:
  2. \c <DATABASE>
  3. SELECT 'aggregate' AS objkind,
  4. p.oid::regprocedure::text AS objname
  5. FROM pg_proc AS p
  6. JOIN pg_aggregate AS a ON a.aggfnoid=p.oid
  7. JOIN pg_proc AS transfn ON transfn.oid=a.aggtransfn
  8. WHERE p.oid >= 16384
  9. 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[]);
  10. objkind | objname
  11. -----------+-------------------------
  12. aggregate | array_accum(anyelement)
  13. (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:

  1. fatal
  2. Your installation contains user-defined objects that refer to internal
  3. polymorphic functions with arguments of type &quot;anyarray&quot; or &quot;anyelement&quot;.
  4. These user-defined objects must be dropped before upgrading and restored
  5. afterwards, changing them to refer to the new corresponding functions with
  6. 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:

  1. --find incompatibilites on each DB:
  2. \c &lt;DATABASE&gt;
  3. SELECT &#39;aggregate&#39; AS objkind,
  4. p.oid::regprocedure::text AS objname
  5. FROM pg_proc AS p
  6. JOIN pg_aggregate AS a ON a.aggfnoid=p.oid
  7. JOIN pg_proc AS transfn ON transfn.oid=a.aggtransfn
  8. WHERE p.oid &gt;= 16384
  9. 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[]);
  10. objkind | objname
  11. -----------+-------------------------
  12. aggregate | array_accum(anyelement)
  13. (1 row)

Okay, so now what?

答案1

得分: 2

解决方案:

  1. --从子 14.x 数据库中删除聚合函数
  2. mygreatdatabase=&gt; DROP AGGREGATE array_accum(anyelement);
  3. DROP AGGREGATE
  4. --升级到 14.x 或更高版本,然后使用更新后的类型重新创建:
  5. mygreatdatabase=&gt; CREATE AGGREGATE array_accum(anycompatible) (SFUNC = array_append,STYPE = anycompatiblearray,INITCOND = &#39;{}&#39;);

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

英文:

Solution:

  1. --drop aggregate from sub 14.x db
  2. mygreatdatabase=&gt; DROP AGGREGATE array_accum(anyelement);
  3. DROP AGGREGATE
  4. --upgrade to 14.x or higher, and then re-create using updated type:
  5. 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:

确定