# Discourse重建由于非正常关闭失败

**URL:** https://meta.discourse.org/t/discourse-rebuild-fails-due-to-unclean-shutdown/350308
**Category:** Support
**Created:** [2025年二月3日 21:18 UTC](https://meta.discourse.org/t/discourse-rebuild-fails-due-to-unclean-shutdown/350308 "2025-02-03T21:18:35Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![KhoiUSA](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/khoiusa/32/373010_2.png) [@KhoiUSA](https://meta.discourse.org/u/KhoiUSA)
#### Post date: [2025年二月3日 21:18 UTC](https://meta.discourse.org/t/discourse-rebuild-fails-due-to-unclean-shutdown/350308/1 "2025-02-03T21:18:35Z")

</div>

继续讨论 [PostgreSQL 15 更新](https://meta.discourse.org/t/postgresql-15-update/349515)：

你好，我今天打算在 app.yml 文件中添加一个插件后重新构建我的 Discourse 安装。但是，当我运行重建操作时失败了，提示“源集群未干净关闭”。我已按照说明尝试通过启动和停止容器来解决问题，但结果相同。

我尝试的 FAQ 指令：

```plaintext
root@anomicforum:/var/discourse# ./launcher start app
x86_64 arch detected.

starting up existing container
+ /usr/bin/docker start app
app
root@anomicforum:/var/discourse# ./launcher stop app
x86_64 arch detected.
+ /usr/bin/docker stop -t 600 app
app

```

我的重建尝试：

```plaintext
x86_64 arch detected.
Ensuring launcher is up to date
Launcher is up-to-date
Stopping old container
+ /usr/bin/docker stop -t 600 app
app
2.0.20250129-0720: Pulling from discourse/base
Digest: sha256:01b8516e5504c0e9bc3707773015ff4407be03a89154194ff3b5b8699291bc26
Status: Image is up to date for discourse/base:2.0.20250129-0720
docker.io/discourse/base:2.0.20250129-0720
/usr/local/lib/ruby/gems/3.3.0/gems/pups-1.2.1/lib/pups.rb
/usr/local/bin/pups --stdin
I, [2025-02-03T21:14:22.601738 #1] INFO -- : Reading from stdin
I, [2025-02-03T21:14:22.615995 #1] INFO -- : File > /etc/service/postgres/run chmod: +x chown:
I, [2025-02-03T21:14:22.620264 #1] INFO -- : File > /etc/service/postgres/log/run chmod: +x chown:
I, [2025-02-03T21:14:22.624344 #1] INFO -- : File > /etc/runit/3.d/99-postgres chmod: +x chown:
I, [2025-02-03T21:14:22.628508 #1] INFO -- : File > /root/install_postgres chmod: +x chown:
I, [2025-02-03T21:14:22.636119 #1] INFO -- : File > /root/upgrade_postgres chmod: +x chown:
I, [2025-02-03T21:14:22.637957 #1] INFO -- : Replacing data_directory = '/var/lib/postgresql/15/main' with data_directory = '/shared/postgres_data' in /etc/postgresql/15/main/postgresql.conf
I, [2025-02-03T21:14:22.638736 #1] INFO -- : Replacing (?-mix:#?listen_addresses *=.*) with listen_addresses = '*' in /etc/postgresql/15/main/postgresql.conf
I, [2025-02-03T21:14:22.639276 #1] INFO -- : Replacing (?-mix:#?synchronous_commit *=.*) with synchronous_commit = $db_synchronous_commit in /etc/postgresql/15/main/postgresql.conf
I, [2025-02-03T21:14:22.640015 #1] INFO -- : Replacing (?-mix:#?shared_buffers *=.*) with shared_buffers = $db_shared_buffers in /etc/postgresql/15/main/postgresql.conf
I, [2025-02-03T21:14:22.641056 #1] INFO -- : Replacing (?-mix:#?work_mem *=.*) with work_mem = $db_work_mem in /etc/postgresql/15/main/postgresql.conf
I, [2025-02-03T21:14:22.641869 #1] INFO -- : Replacing (?-mix:#?default_text_search_config *=.*) with default_text_search_config = '$db_default_text_search_config' in /etc/postgresql/15/main/postgresql.conf
I, [2025-02-03T21:14:22.642730 #1] INFO -- : Replacing (?-mix:#?checkpoint_segments *=.*) with checkpoint_segments = $db_checkpoint_segments in /etc/postgresql/15/main/postgresql.conf
I, [2025-02-03T21:14:22.643579 #1] INFO -- : Replacing (?-mix:#?logging_collector *=.*) with logging_collector = $db_logging_collector in /etc/postgresql/15/main/postgresql.conf
I, [2025-02-03T21:14:22.644530 #1] INFO -- : Replacing (?-mix:#?log_min_duration_statement *=.*) with log_min_duration_statement = $db_log_min_duration_statement in /etc/postgresql/15/main/postgresql.conf
I, [2025-02-03T21:14:22.646187 #1] INFO -- : Replacing (?-mix:^#local +replication +postgres +peer$) with local replication postgres peer in /etc/postgresql/15/main/pg_hba.conf
I, [2025-02-03T21:14:22.646595 #1] INFO -- : Replacing (?-mix:^host.*all.*all.*127.*$) with host all all 0.0.0.0/0 md5 in /etc/postgresql/15/main/pg_hba.conf
I, [2025-02-03T21:14:22.646955 #1] INFO -- : Replacing (?-mix:^host.*all.*all.*::1\/128.*$) with host all all ::/0 md5 in /etc/postgresql/15/main/pg_hba.conf
I, [2025-02-03T21:14:22.647596 #1] INFO -- : > if [-f /root/install_postgres]; then
  /root/install_postgres && rm -f /root/install_postgres
elif [-e /shared/postgres_run/.s.PGSQL.5432]; then
  socat /dev/null UNIX-CONNECT:/shared/postgres_run/.s.PGSQL.5432 || exit 0 && echo postgres already running stop container ; exit 1
fi

2025/02/03 21:14:25 socat[33] E connect(, AF=1 "/shared/postgres_run/.s.PGSQL.5432", 36): Connection refused
initdb: warning: enabling "trust" authentication for local connections
initdb: hint: You can change this by editing pg_hba.conf or using the option -A, or --auth-local and --auth-host, the next time you run initdb.
W: https://dl.yarnpkg.com/debian/dists/stable/InRelease: Key is stored in legacy trusted.gpg keyring (/etc/apt/trusted.gpg), see the DEPRECATION section in apt-key(8) for details.
debconf: delaying package configuration, since apt-utils is not installed
I, [2025-02-03T21:14:59.545530 #1] INFO -- : Generating locales (this might take a while)...
  en_US.UTF-8... done
Generation complete.
Upgrading PostgreSQL from version 13 to 15
The files belonging to this database system will be owned by user "postgres".
This user must also own the server process.

The database cluster will be initialized with locale "en_US.UTF-8".
The default database encoding has accordingly been set to "UTF8".
The default text search configuration will be set to "english".

Data page checksums are disabled.

fixing permissions on existing directory /shared/postgres_data_new ... ok
creating subdirectories ... ok
selecting dynamic shared memory implementation ... posix
selecting default max_connections ... 100
selecting default shared_buffers ... 128MB
selecting default time zone ... Etc/UTC
creating configuration files ... ok
running bootstrap script ... ok
performing post-bootstrap initialization ... ok
syncing data to disk ... ok

Success. You can now start the database server using:

    /usr/lib/postgresql/15/bin/pg_ctl -D /shared/postgres_data_new -l logfile start

Get:1 http://deb.debian.org/debian bookworm-backports InRelease [59.0 kB]
Get:2 http://deb.debian.org/debian bookworm InRelease [151 kB]
Get:3 http://deb.debian.org/debian bookworm-updates InRelease [55.4 kB]
Get:4 http://deb.debian.org/debian-security bookworm-security InRelease [48.0 kB]
Get:5 https://deb.nodesource.com/node_22.x nodistro InRelease [12.1 kB]
Get:6 https://dl.yarnpkg.com/debian stable InRelease [17.1 kB]
Get:7 http://deb.debian.org/debian bookworm-backports/main amd64 Packages [280 kB]
Get:8 http://deb.debian.org/debian bookworm/main amd64 Packages [8,792 kB]
Get:9 https://apt.postgresql.org/pub/repos/apt bookworm-pgdg InRelease [129 kB]
Get:10 http://deb.debian.org/debian bookworm-updates/main amd64 Packages [13.5 kB]
Get:11 http://deb.debian.org/debian-security bookworm-security/main amd64 Packages [243 kB]
Get:12 https://deb.nodesource.com/node_22.x nodistro/main amd64 Packages [5,274 B]
Get:13 https://dl.yarnpkg.com/debian stable/main all Packages [10.9 kB]
Get:14 https://dl.yarnpkg.com/debian stable/main amd64 Packages [10.9 kB]
Get:15 https://apt.postgresql.org/pub/repos/apt bookworm-pgdg/main amd64 Packages [360 kB]
Fetched 10.2 MB in 4s (2,452 kB/s)
Reading package lists...
Reading package lists...
Building dependency tree...
Reading state information...
The following additional packages will be installed:
  postgresql-client-13
Suggested packages:
  postgresql-doc-13
The following NEW packages will be installed:
  postgresql-13 postgresql-13-pgvector postgresql-client-13
0 upgraded, 3 newly installed, 0 to remove and 0 not upgraded.
Need to get 17.3 MB of archives.
After this operation, 56.7 MB of additional disk space will be used.
Get:1 https://apt.postgresql.org/pub/repos/apt bookworm-pgdg/main amd64 postgresql-client-13 amd64 13.18-1.pgdg120+1 [1,523 kB]
Get:2 https://apt.postgresql.org/pub/repos/apt bookworm-pgdg/main amd64 postgresql-13 amd64 13.18-1.pgdg120+1 [15.4 MB]
Get:3 https://apt.postgresql.org/pub/repos/apt bookworm-pgdg/main amd64 postgresql-13-pgvector amd64 0.8.0-1.pgdg120+1 [297 kB]
Fetched 17.3 MB in 1s (14.9 MB/s)
Selecting previously unselected package postgresql-client-13.
(Reading database ... 33363 files and directories currently installed.)
Preparing to unpack .../postgresql-client-13_13.18-1.pgdg120+1_amd64.deb ...
Unpacking postgresql-client-13 (13.18-1.pgdg120+1) ...
Selecting previously unselected package postgresql-13.
Preparing to unpack .../postgresql-13_13.18-1.pgdg120+1_amd64.deb ...
Unpacking postgresql-13 (13.18-1.pgdg120+1) ...
Selecting previously unselected package postgresql-13-pgvector.
Preparing to unpack .../postgresql-13-pgvector_0.8.0-1.pgdg120+1_amd64.deb ...
Unpacking postgresql-13-pgvector (0.8.0-1.pgdg120+1) ...
Setting up postgresql-client-13 (13.18-1.pgdg120+1) ...
Setting up postgresql-13 (13.18-1.pgdg120+1) ...
Creating new PostgreSQL cluster 13/main ...
/usr/lib/postgresql/13/bin/initdb -D /var/lib/postgresql/13/main --auth-local peer --auth-host md5
The files belonging to this database system will be owned by user "postgres".
This user must also own the server process.

The database cluster will be initialized with locale "C.UTF-8".
The default database encoding has accordingly been set to "UTF8".
The default text search configuration will be set to "english".

Data page checksums are disabled.

fixing permissions on existing directory /var/lib/postgresql/13/main ... ok
creating subdirectories ... ok
selecting dynamic shared memory implementation ... posix
selecting default max_connections ... 100
selecting default shared_buffers ... 128MB
selecting default time zone ... Etc/UTC
creating configuration files ... ok
running bootstrap script ... ok
performing post-bootstrap initialization ... ok
syncing data to disk ... ok

Success. You can now start the database server using:

    pg_ctlcluster 13 main start

invoke-rc.d: could not determine current runlevel
invoke-rc.d: policy-rc.d denied execution of start.
Setting up postgresql-13-pgvector (0.8.0-1.pgdg120+1) ...
Processing triggers for postgresql-common (267.pgdg120+1) ...
Building PostgreSQL dictionaries from installed myspell/hunspell packages...
Removing obsolete dictionary files:
Stopping PostgreSQL 13 database server: main.
Stopping PostgreSQL 15 database server: main.
Performing Consistency Checks
-----------------------------
Checking cluster versions ok

The source cluster was not shut down cleanly.
Failure, exiting
-------------------------------------------------------------------------------------
UPGRADE OF POSTGRES FAILED

Please visit https://meta.discourse.org/t/postgresql-15-update/349515 for support.

You can run ./launcher start app to restart your app in the meanwhile
-------------------------------------------------------------------------------------

FAILED
--------------------
Pups::ExecError: if [-f /root/install_postgres]; then
  /root/install_postgres && rm -f /root/install_postgres
elif [-e /shared/postgres_run/.s.PGSQL.5432]; then
  socat /dev/null UNIX-CONNECT:/shared/postgres_run/.s.PGSQL.5432 || exit 0 && echo postgres already running stop container ; exit 1
fi
 failed with return #<Process::Status: pid 18 exit 1>
Location of failure: /usr/local/lib/ruby/gems/3.3.0/gems/pups-1.2.1/lib/pups/exec_command.rb:132:in `spawn'
exec failed with the params {"tag"=>"db", "cmd"=>"if [-f /root/install_postgres]; then\n /root/install_postgres && rm -f /root/install_postgres\nelif [-e /shared/postgres_run/.s.PGSQL.5432]; then\n socat /dev/null UNIX-CONNECT:/shared/postgres_run/.s.PGSQL.5432 || exit 0 && echo postgres already running stop container ; exit 1\nfi\n"}
bootstrap failed with exit code 1
**FAILED TO BOOTSTRAP** please scroll up and look for earlier error messages, there may be more than one.
./discourse-doctor may help diagnose the problem.
9a16613f6ad358fc52b6d9498c29d61d30857e30528fab9a5e7dc72b1d0d6bf8

```

有人知道解决方法吗？如果找不到解决方案，我可能本周末会重新镜像整个服务器，从头开始安装新的 Discourse 并从备份中恢复。提前感谢。

附注：我通过修改 yaml 文件使用 `postgres.13` 模板文件推迟了更新，目前论坛在版本 13 上正常运行。

---

<div class="post-metadata">

### Author: ![mwaniki](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/mwaniki/32/313097_2.png) [@mwaniki](https://meta.discourse.org/u/mwaniki)
#### Post date: [2025年二月4日 03:58 UTC](https://meta.discourse.org/t/discourse-rebuild-fails-due-to-unclean-shutdown/350308/2 "2025-02-04T03:58:16Z")

</div>

我已经更新了常见问题解答中的步骤。您能否尝试一下，让我们知道是否有帮助？

> [@mwaniki](#):
>
> 现在再次使用 `./launcher stop app` 关闭它。之后，跟踪日志以查看它是否干净：
> 
> ```plaintext
> tail -f shared/standalone/log/var-log/postgres/current
> 2025-01-24 09:19:06.437 UTC [37] LOG: received smart shutdown request
> 2025-01-24 09:19:06.444 UTC [37] LOG: background worker "logical replication launcher" (PID 54) exited with exit code 1
> 2025-01-24 09:19:06.446 UTC [49] LOG: shutting down
> 2025-01-24 09:19:06.468 UTC [37] LOG: database system is shut down
> 
> ```
> 
> 如果日志没有表明数据库已关闭，您可以再次启动旧容器，使用 `./launcher enter app` 进入，运行这些命令，完成后再次跟踪日志。
> 
> ```plaintext
> export SVWAIT=300
> sv stop nginx
> sv stop unicorn
> sv stop postgres
> exit
> 
> ```
> 
> 如果日志如上所示，您现在可以尝试使用 `./launcher rebuild app` 再次升级。

---

<div class="post-metadata">

### Author: ![KhoiUSA](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/khoiusa/32/373010_2.png) [@KhoiUSA](https://meta.discourse.org/u/KhoiUSA)
#### Post date: [2025年二月4日 16:09 UTC](https://meta.discourse.org/t/discourse-rebuild-fails-due-to-unclean-shutdown/350308/3 "2025-02-04T16:09:55Z")

</div>

你好，我回家后会尝试那些步骤。感谢你的回复，我会向大家更新结果。😁

---

<div class="post-metadata">

### Author: ![KhoiUSA](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/khoiusa/32/373010_2.png) [@KhoiUSA](https://meta.discourse.org/u/KhoiUSA)
#### Post date: [2025年二月4日 20:28 UTC](https://meta.discourse.org/t/discourse-rebuild-fails-due-to-unclean-shutdown/350308/4 "2025-02-04T20:28:42Z")

</div>

跟进：很高兴地报告，上面提供的解决方案确实有效。谢谢！ 👍

---

<div class="post-metadata">

### Author: ![system](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/system/32/443519_2.png) [@system](https://meta.discourse.org/u/system)
#### Post date: [2025年三月6日 20:28 UTC](https://meta.discourse.org/t/discourse-rebuild-fails-due-to-unclean-shutdown/350308/5 "2025-03-06T20:28:56Z")

</div>

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.
