iamntz
(Ionuț Staicu)
2023 年1 月 18 日 08:16
1
你好。
我尝试运行更新和重建,但遇到了这个烦人的错误:
I, [2023-01-18T08:05:48.701709 #1] INFO -- : cd /var/www/discourse & su discourse -c 'LOAD_PLUGINS=0 bundle exec rake plugin:pull_compatible_all'
I, [2023-01-18T08:05:52.431210 #1] INFO -- :
I, [2023-01-18T08:05:52.431807 #1] INFO -- : cd /var/www/discourse & su discourse -c 'bundle exec rake db:migrate'
2023-01-18 08:05:59.081 UTC [1166] discourse@discourse ERROR: could not create unique index "index_tags_on_name_ccnew_ccnew_ccnew5"
2023-01-18 08:05:59.081 UTC [1166] discourse@discourse DETAIL: Key (name)=(vuejs) is duplicated.
2023-01-18 08:05:59.081 UTC [1166] discourse@discourse STATEMENT: REINDEX INDEX CONCURRENTLY index_tags_on_name_ccnew_ccnew
rake aborted!
StandardError: An error has occurred, all later migrations canceled:
PG::UniqueViolation: ERROR: could not create unique index "index_tags_on_name_ccnew_ccnew_ccnew5"
DETAIL: Key (name)=(vuejs) is duplicated.
/var/www/discourse/vendor/bundle/ruby/3.1.0/gems/rack-mini-profiler-3.0.0/lib/patches/db/pg.rb:110:in `exec'
/var/www/discourse/vendor/bundle/ruby/3.1.0/gems/rack-mini-profiler-3.0.0/lib/patches/db/pg.rb:110:in `async_exec'
论坛上还有其他类似问题的帖子(1 , 2 , 3 ),但当我尝试进入容器时,我得到了这个:
/var/discourse# ./launcher enter app
x86_64 arch detected.
Error: No such container: app
因此,我无法手动删除索引。
还有其他建议我接下来应该采取什么方法吗?
2 个赞
nbianca
(Bianca)
2023 年1 月 18 日 08:59
2
你好 Ionut,
感谢你的 bug 报告。我会查看这个问题,但我认为你的数据库中存在一个索引问题,最近的一次迁移试图修复它,但有些问题需要人工干预才能解决。
我认为引入失败迁移的提交是这个:
committed 03:04AM - 13 Jan 23 UTC
In Discourse, there are many migration files where we CREATE INDEX CONCURRENTLY … which requires us to set disable_ddl_transaction!. Setting disable_ddl_transaction! in a migration file runs the SQL statements outside of a transaction. The implication of this is that there is no ROLLBACK should any of the SQL statements fail.
We have seen lock timeouts occuring when running CREATE INDEX CONCURRENTLY. When that happens, the index would still have been created but marked as invalid by Postgres.
Per the postgres documentation:
> If a problem arises while scanning the table, such as a deadlock or a uniqueness violation in a unique index, the CREATE INDEX command will fail but leave behind an “invalid” index. This index will be ignored for querying purposes because it might be incomplete; however it will still consume update overhead.
> The recommended recovery method in such cases is to drop the index and try again to perform CREATE INDEX CONCURRENTLY . (Another possibility is to rebuild the index with REINDEX INDEX CONCURRENTLY ).
When such scenarios happen, we are supposed to either drop and create the index again or run a REINDEX operation. However, I noticed today that we have not been doing so in Discourse. Instead, we’ve been incorrectly working around the problem by checking for the index existence before creating the index in order to make the migration idempotent. What this potentially mean is that we might have invalid indexes which are lying around in the database which PG will ignore for querying purposes.
This commits adds a migration which queries for all the
invalid indexes in the `public` namespace and reindexes them.
你可以尝试将你的 Discourse 实例固定到之前的版本,即提交 690e2f15ab9549486aaa6750e1093c1336bf17f2。编辑你的 app.yml 文件,并在 params 下设置 version 键 。确保取消注释该键!
然后,一切都应该可以启动,你应该能够删除重复的 vuejs 标签,但这可能会产生一些不希望的效果,如果重复的标签正在使用中。我们会尝试找到一个更好的解决方案,但在此之前,这应该可以工作。
2 个赞
iamntz
(Ionuț Staicu)
2023 年1 月 18 日 11:31
3
启动后,我使用 Data Explorer 插件找到了所有重复的标签:
SELECT name, count(*)
FROM tags
GROUP BY name
HAVING count(*) > 1
出于某些原因,大约有十个 重复的标签。我想知道为什么以及它们最初 是如何出现在那里的……
设法清除了那些讨厌的东西,从 yml 文件中删除了版本锁定,重新构建,现在看起来一切正常。
谢谢!
5 个赞
sam
(Sam Saffron)
2023 年1 月 18 日 22:50
4
我们过去也遇到过这种情况,这是一个噩梦般的问题,但我们已将其归结为与升级有关。
PG 中的索引结构取决于安装时使用的区域设置,升级有时会导致噩梦。
opened 09:42PM - 17 May 19 UTC
closed 06:18PM - 16 Jun 21 UTC
See https://lists.debian.org/debian-glibc/2019/03/msg00030.html, https://bugs.de… bian.org/926627, and https://salsa.debian.org/ddp-team/release-notes/commit/ad75c4b for some context.
> When upgrading from stretch to buster, the glibc locale data is upgraded.
> Specifically, this changes how PostgreSQL sorts data in text indexes.
> To avoid corruption, such indexes need to be `REINDEX`ed
> immediately after upgrading the `locales` or
> `locales-all` packages, before putting back the database
> into production.
>
> Suggested command: `sudo -u postgres reindexdb --all`
I'm not entirely sure how we're going to handle this, but it does mean it won't be reasonable for us to simply upgrade the images from Stretch to Buster once Buster is released. :confused: :disappointed:
如果索引重建没有足够早地执行,可能会带来麻烦。我们早期的一些 PG Docker 升级没有运行这个……而一些旧的安装不幸地埋下了一颗定时炸弹。
如今,这在生态系统中大部分已得到解决,但仍有一些痛苦存在。
2 个赞
iamntz
(Ionuț Staicu)
2023 年1 月 19 日 15:30
5
也许这有助于进一步查明原因,因此这里有一些关于系统的更多详细信息:
安装确实很古老,自 2014 年以来,但系统每月至少更新一次(尽管通常 是每两周一次)。因此,从未跳过任何主版本。
没有版本锁定,所以基本上我们运行的是 main 分支上可用的最新版本(YOLO!)。
虽然我们很久以前尝试过极少数非官方插件,但所有已安装的插件都是官方的,而且这种情况已经持续了……五年或更长时间。
1 个赞
uwe_keim
(Uwe Keim)
2023 年1 月 20 日 16:38
6
我也遇到了同样的问题,我一直跟着你的步骤直到这句话。
你实际上是如何删除重复项的?仅仅是在数据浏览器中发出一个 delete SQL 语句吗?指向此标签的外部表记录又该如何处理?
更新 1
好的,我看到你无法执行 update 语句。
我现在已经使用了图形用户界面,并简单地重命名了该标签。
iamntz
(Ionuț Staicu)
2023 年1 月 20 日 20:29
7
编辑标签(通过转到 /tag/foo)并重命名或删除它。
system
(system)
关闭
2023 年2 月 19 日 20:29
8
This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.