我在 Postgres 13 (RDS) 上,需要通过其 oid 值删除一个函数。这是我正在看的:
postgres> select oid,proowner::regrole,proname||'('||pg_catalog.pg_get_function_identity_arguments(oid)||')' as func from pg_proc where proname='unnest' order by oid;
oid | proowner | func
---------+----------+------------------------------------------------------------------------------------------
2331 | jclough | unnest(anyarray)
3322 | rdsadmin | unnest(tsvector tsvector, OUT lexeme text, OUT positions smallint[], OUT weights text[])
1030822 | jclough | unnest(anyarray)
(3 rows)
我想删除带有 oid 1030822 的函数,然后
alter function unnest(anyarray) owner to rdsadmin;
这会很棘手,因为
postgres> set role rdsadmin;
ERROR: permission denied to set role "rdsadmin"
但这是一场未来的战斗。
一点历史可能是有序的。我们在 Postgres 8 和 9 上使用了很长时间,我实现了自己的 unnest(anyarray) 函数,因为它只存在于 >=10 的版本中。当我们从 9 跳到 13(几年后)时,我拼凑起来的 unnest 函数出现了。所以在这里我有两个版本的函数具有相同的签名。
我还应该提到我是一名伪装成 DBA 的应用程序程序员,我很糟糕。我想我将不得不直接修改 pg_proc(或其他)。有没有最不危险的方法来做到这一点?
不要因为弄乱目录而让所有相关人员感到悲伤。
相反,弄清楚函数在哪个模式中。除非您正在处理实际的数据损坏,否则两个函数只有在同一架构中时才能具有相同的名称和签名。
尝试以下操作:
输出将包含各个函数的架构。如果架构在您的 上,架构的输出将被抑制
search_path
,因此将其设置为空值以查看架构。