紧急:升级构建失败 UniqueViolation

我尝试升级 Discourse,但收到了以下消息 -

I, [2021-01-21T18:39:25.045454 #1]  INFO -- : > cd /var/www/discourse && su discourse -c 'bundle exec rake db:migrate'
2021-01-21 18:39:32.724 UTC [4051] discourse@discourse LOG:  duration: 336.116 ms  statement: UPDATE users
	SET locale = 'en_GB'
	WHERE locale = 'en'
	
2021-01-21 18:39:33.373 UTC [4051] discourse@discourse ERROR:  duplicate key value violates unique constraint "index_users_on_username_lower"
2021-01-21 18:39:33.373 UTC [4051] discourse@discourse DETAIL:  Key (username_lower)=(xyz123) already exists.
2021-01-21 18:39:33.373 UTC [4051] discourse@discourse STATEMENT:  UPDATE users
	SET locale = 'en'
	WHERE locale = 'en_US'
	
rake aborted!
StandardError: An error has occurred, this and all later migrations canceled:

我尝试执行 ./launcher enter appsu postgres -c 'psql discourse',但收到以下错误 -

psql: error: could not connect to server: could not connect to server: No such file or directory
Is the server running locally and accepting
connections on Unix domain socket “/var/run/postgresql/.s.PGSQL.5432”?

@merefield 你有什么想法吗?谢谢!

嘿。

当升级失败时,容器会停留在停止状态。(尝试通过浏览器连接您的网站,您会看到确实如此)

因此,您可能只是没有启动最新的工作容器(升级前的版本)。

请执行 ./launcher start app,然后进入容器并尝试进入数据库 CLI。

谢谢,我已经重启了容器,有什么建议吗?我尝试了 ./launcher enter app,还有其他可以试的吗?

ubuntu@:/var/discourse$ ./launcher start app
WARNING: Docker version 17.05.0-ce deprecated …
Nothing to do, your container has already started!

您在进入容器时是否遇到错误?

没有报错,但当我运行 ./launcher logs app 时,得到了以下输出:

ok: run: redis: (pid 47) 918s
timeout: down: postgres: 1s, normally up, want up
ok: run: redis: (pid 47) 925s
timeout: down: postgres: 0s, normally up, want up
ok: run: redis: (pid 47) 933s
ok: run: postgres: (pid 1855) 0s
supervisor pid: 1847 unicorn pid: 1857
config/unicorn_launcher: line 71: kill: (1857) - No such process
config/unicorn_launcher: line 15: kill: (1857) - No such process
(1847) exiting
ok: run: redis: (pid 47) 938s
timeout: down: postgres: 0s, normally up, want up
ok: run: redis: (pid 47) 945s

ps -ef | grep postgres 的结果是什么?

root 38 35 0 19:09 ? 00:00:00 runsv postgres
root 46 38 0 19:09 ? 00:00:00 svlogd /var/log/postgres
root 2573 2571 0 19:31 ? 00:00:00 sv start postgres
root 2575 2497 0 19:31 ? 00:00:00 grep postgres

我应该是在容器内运行,还是直接在 Linux 主机上运行?

内部。看起来它没有运行。

我怀疑您需要以 postgres 用户身份手动重启它。

你知道重启它的快速命令吗?

你可以尝试:

su - postgres /usr/lib/postgresql/13/bin/postmaster -D /etc/postgresql/13/main - 将 13 替换为你当前的版本。

这是健康安装过程中宣传的命令。

不过没有保修,因为我尚未测试过!

不,别费心这么做了,请查看下文。

谢谢。我有版本 12,但遇到了以下错误:

su: 无效选项 – ‘D’
请尝试 ‘su --help’ 获取更多信息。

-D 是一个合法的开关。

请确认您没有在代码片段之外包含连字符?

顺便问一下,我想知道你的 13 版本升级过程是否失败了。

如果是的话,你可能想看看这个主题,并考虑在其中发帖:PostgreSQL 13 update

是的,我还在用 12 版本……

抱歉,看起来这被更高层级的进程包装并管理着。

如果我终止我的进程,它会自动重启。

尝试以 root 身份运行:sv start postgres

你的意思是将其在 Docker 容器中运行吗?谢谢。

是的,服务正在那里运行。

更好的做法是执行:sv restart postgres

然后检查:

tail /var/log/postgres/current

正常状态应显示类似以下内容:

2021-01-21 20:21:10.284 UTC [575368] LOG: database system is ready to accept connections 出现在日志中。

这是错误日志 -

root@ip–app:/var/www/discourse# cat /var/log/postgresql/postgresql-12-main.log
2021-01-21 18:12:04.965 UTC [623] FATAL: 数据库文件与服务器不兼容
2021-01-21 18:12:04.965 UTC [623] DETAIL: 数据目录由 PostgreSQL 版本 13 初始化,与此版本 12.3 (Debian 12.3-1.pgdg100+1) 不兼容。
pg_ctl: 无法启动服务器
请检查日志输出。