恢复失败的 RDS Postgres 13.7 的 `entity2char already exists`

我正在尝试恢复一个数据库,该数据库是在 \"Discourse 2.9.0.beta10 - https://github.com/discourse/discourse version 8d3fe3ddc5d38ab02a8f5c6aed7ebf7a6bcfbfec\"\u003e 上创建的,并恢复到 Discourse 2.9.0.beta12 - https://github.com/discourse/discourse version d4371a9ffcc6c727105a880b4b70c715ed0283cb\"\u003e。两者都使用 RDS Postgres 13.7。未压缩的数据库为 126GB,因此在花费了几天时间认为我需要一个 200GB 的磁盘来运行这个 30GB 压缩数据库的恢复后,我得到了这个:

...
SET
CREATE TYPE
ERROR:  function "entity2char" already exists with same argument types
EXCEPTION: psql failed: ERROR:  function "entity2char" already exists with same argument types
/var/www/discourse/lib/backup_restore/database_restorer.rb:92:in `restore_dump'
/var/www/discourse/lib/backup_restore/database_restorer.rb:26:in `restore'
/var/www/discourse/lib/backup_restore/restorer.rb:51:in `run'
...

搜索 \"entity2char\" already exists 找不到任何结果,并且我在核心或任何插件中都看不到 entity2char。我也没在 retort 中看到它,我曾希望将其归咎于它,但删除它并没有帮助。

这是插件列表:

         - git clone https://github.com/discourse/discourse-adplugin.git
         - git clone https://github.com/discourse/discourse-affiliate.git
         - git clone https://github.com/discourse/discourse-bbcode.git
         - git clone https://github.com/discourse/discourse-canned-replies.git
         - git clone https://github.com/discourse/discourse-data-explorer.git
         - git clone https://github.com/discourse/discourse-prometheus.git
         - git clone https://github.com/discourse/discourse-push-notifications.git
         - git clone https://github.com/discourse/discourse-signatures.git
         - git clone https://github.com/discourse/discourse-user-notes.git
         - git clone https://github.com/discourse/discourse-spoiler-alert.git
         - git clone https://github.com/discourse/discourse-cakeday.git
         - git clone https://github.com/discourse/discourse-checklist.git
         - git clone https://github.com/discourse/discourse-calendar.git
         - git clone https://github.com/discourse/discourse-reactions.git

在我尝试备份的数据库中查找 entity2char 函数时,我没有找到它。

该论坛的历史是什么?它最初使用的是哪个 PostgreSQL 和 Discourse 版本?它是否曾使用过 Bitnami 或其他可疑的托管服务?

1 个赞

数据库转储似乎包含对 entity2char 函数的引用,不知何故。删除它应该可以使其正常工作,除非转储中还有其他不该存在的内容。

1 个赞

您有什么关于如何从现有数据库中删除它的提示吗?我的第一个谷歌提示不起作用。

不要从数据库中删除它,从备份中删除。

我差点就把它从数据库中删除了,因为执行 SQL 的 drop function entity2char; 命令似乎容易得多。

我能够使用 \df 列出它们。

你认为如果我把它从数据库中删除,会破坏什么吗?

等等……这个练习的目的是将生产数据库恢复到我想要启动的新镜像上,以确保在我安装最新的 Discourse 并迁移数据库时,Discourse 能够与现有的生产数据库一起工作,因此修改数据库以便在暂存环境中恢复它没有意义。

是的,正是这样

还有这个 :wink:

也许可行的方法是,在恢复之前尝试在目标数据库实例中重命名该函数。但我没有测试过。

所以(在目标数据库上)

  • ALTER FUNCTION entity2char RENAME TO e2c_outoftheway
  • 恢复
  • ALTER FUNCTION entity2char RENAME TO e2c_from_backup
  • ALTER FUNCTION e2c_outoftheway RENAME TO entity2char
1 个赞

哦!所以问题是 暂存 数据库已经有了那个函数,备份里也有那个函数,而且它太笨了,无法理解这是同一个函数。

也许我应该直接删除暂存/目标站点上的数据库然后重新创建?

但你的主意似乎更容易一些。

编辑:好的,我重命名了函数,现在正在进行恢复。大约一小时后我就可以知道是否成功了。

而且担心的是,备份中携带的 entity2char 函数不知何故将无法与现有数据库一起使用?也许我应该创建一个全新的数据库并恢复到其中。我也不太喜欢 xx-discourse-database-5 这个名字。

编辑:嗯,看起来还有一些“鼹鼠”(问题)需要我处理。

ERROR:  function "replace_mentions" already exists with same argument types

也许从一个新数据库开始是最好的选择。

解决方案是先删除、创建和迁移数据库,然后再进行恢复。我本应该尝试跳过迁移步骤。

感谢 @RGJ@gerhard 的帮助。你们的提示对我弄清楚这个问题很有帮助。

我想不总是先删除数据库的原因是,当它失败时你就无法回退了。

1 个赞