# Rebake 出现错误消息并中止

**URL:** https://meta.discourse.org/t/rebake-aborts-with-error-message/220803
**Category:** Self-hosting
**Tags:** server-resources
**Created:** [2022年三月12日 11:19 UTC](https://meta.discourse.org/t/rebake-aborts-with-error-message/220803 "2022-03-12T11:19:39Z")
**Posts on this page:** 6
**Page:** 1

<div class="post-metadata">

### Author: ![Canapin](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/canapin/32/119591_2.png) [@Canapin](https://meta.discourse.org/u/Canapin)
#### Post date: [2022年三月12日 11:19 UTC](https://meta.discourse.org/t/rebake-aborts-with-error-message/220803/1 "2022-03-12T11:19:39Z")

</div>

您好！  
当我尝试使用 rake 任务重新烘焙帖子时，它有时会因以下消息而停止：

`168858 / 329447 ( 51.3%)WARNING: terminating connection because of crash of another server process DETAIL: The postmaster has commanded this server process to roll back the current transaction and exit, because another server process exited abnormally and possibly corrupted shared memory. HINT: In a moment you should be able to reconnect to the database and repeat your command.`

并在大量文本的末尾，包含类似以下内容：

```plaintext
/var/www/discourse/vendor/bundle/ruby/2.7.0/gems/activerecord-6.1.4.7/lib/active_record/relation.rb:828:in `exec_queries'
/var/www/discourse/vendor/bundle/ruby/2.7.0/gems/activerecord-6.1.4.7/lib/active_record/relation.rb:631:in `load'
/var/www/discourse/vendor/bundle/ruby/2.7.0/gems/activerecord-6.1.4.7/lib/active_record/relation.rb:249:in `records'
/var/www/discourse/vendor/bundle/ruby/2.7.0/gems/activerecord-6.1.4.7/lib/active_record/relation/delegation.rb:88:in `each'
/var/www/discourse/lib/tasks/posts.rake:124:in `block in rebake_posts'

```

最后是这个：  
`168859 / 329447 ( 51.3%)rake aborted! ActiveRecord::ConnectionNotEstablished: connection to server on socket \"/var/run/postgresql/.s.PGSQL.5432\" failed: FATAL: the database system is in recovery mode `

* * *

Discourse 日志中的错误：

 ![image](https://global.discourse-cdn.com/meta/original/3X/5/0/5078cee0c7440536da94a3835156958954db28b6.png)

有什么方法可以解决这个问题吗？

---

<div class="post-metadata">

### Author: ![RGJ](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/rgj/32/523185_2.png) [@RGJ](https://meta.discourse.org/u/RGJ)
#### Post date: [2022年三月12日 12:09 UTC](https://meta.discourse.org/t/rebake-aborts-with-error-message/220803/2 "2022-03-12T12:09:37Z")

</div>

> [@Canapin](#):
>
> 邮政管理员已命令此服务器进程回滚当前事务并退出

您应该检查您的 postgresql 日志。

---

<div class="post-metadata">

### Author: ![Canapin](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/canapin/32/119591_2.png) [@Canapin](https://meta.discourse.org/u/Canapin)
#### Post date: [2022年三月12日 12:32 UTC](https://meta.discourse.org/t/rebake-aborts-with-error-message/220803/3 "2022-03-12T12:32:17Z")

</div>

谢谢！

我承认 PostgreSQL 对我来说是一个全新的领域，我对此完全不了解。  
你能确认日志是否存储在 `/var/discourse/shared/standalone/log/var-log/postgres` 中，还是我应该去某个地方查找特定的 _错误_ 日志？  
我查看了该文件夹中的 `current` 文件，但没发现任何可疑内容，尤其是与 Discourse 界面日志显示的时间段不符。

但也很有可能，是我不知道 _该_ 查找什么。

* * *

编辑：在 `current` 文件中找到了以下内容：

```plaintext
	
2022-03-12 05:27:51.651 UTC [450818] discourse@discourse LOG: duration: 258.470 ms parse <unnamed>: SELECT 1 AS one FROM "permalinks" WHERE "permalinks"."url" = 'images/emoji/twitter/roll_eyes.png' LIMIT 1
2022-03-12 05:27:52.287 UTC [450818] discourse@discourse LOG: duration: 557.420 ms bind <unnamed>: SELECT 1 AS one FROM "permalinks" WHERE "permalinks"."url" = 'images/emoji/twitter/roll_eyes.png' LIMIT 1
2022-03-12 05:27:52.500 UTC [450818] discourse@discourse LOG: duration: 158.213 ms execute <unnamed>: SELECT 1 AS one FROM "permalinks" WHERE "permalinks"."url" = 'images/emoji/twitter/roll_eyes.png' LIMIT 1
2022-03-12 05:27:53.047 UTC [450818] discourse@discourse LOG: duration: 301.290 ms parse <unnamed>: SELECT 1 AS one FROM "permalinks" WHERE "permalinks"."url" = 'images/emoji/twitter/roll_eyes.png' LIMIT 1
2022-03-12 05:27:56.647 UTC [560] LOG: checkpointer process (PID 180496) was terminated by signal 9: Killed
2022-03-12 05:27:56.650 UTC [560] LOG: terminating any other active server processes
2022-03-12 05:27:56.652 UTC [455579] discourse@discourse WARNING: terminating connection because of crash of another server process
2022-03-12 05:27:56.652 UTC [455579] discourse@discourse DETAIL: The postmaster has commanded this server process to roll back the current transaction and exit, because another server process exited abnormally and possibly corrupted shared memory.
2022-03-12 05:27:56.652 UTC [455579] discourse@discourse HINT: In a moment you should be able to reconnect to the database and repeat your command.
2022-03-12 05:27:56.652 UTC [455580] discourse@discourse WARNING: terminating connection because of crash of another server process
2022-03-12 05:27:56.652 UTC [455580] discourse@discourse DETAIL: The postmaster has commanded this server process to roll back the current transaction and exit, because another server process exited abnormally and possibly corrupted shared memory.
2022-03-12 05:27:56.652 UTC [455580] discourse@discourse HINT: In a moment you should be able to reconnect to the database and repeat your command.
2022-03-12 05:27:56.653 UTC [455573] discourse@discourse WARNING: terminating connection because of crash of another server process
2022-03-12 05:27:56.653 UTC [455573] discourse@discourse DETAIL: The postmaster has commanded this server process to roll back the current transaction and exit, because another server process exited abnormally and possibly corrupted shared memory.
2022-03-12 05:27:56.653 UTC [455573] discourse@discourse HINT: In a moment you should be able to reconnect to the database and repeat your command.
2022-03-12 05:27:56.653 UTC [455560] discourse@discourse WARNING: terminating connection because of crash of another server process
2022-03-12 05:27:56.653 UTC [455560] discourse@discourse DETAIL: The postmaster has commanded this server process to roll back the current transaction and exit, because another server process exited abnormally and possibly corrupted shared memory.
2022-03-12 05:27:56.653 UTC [455560] discourse@discourse HINT: In a moment you should be able to reconnect to the database and repeat your command.
2022-03-12 05:27:56.653 UTC [455476] discourse@discourse WARNING: terminating connection because of crash of another server process
2022-03-12 05:27:56.653 UTC [455476] discourse@discourse DETAIL: The postmaster has commanded this server process to roll back the current transaction and exit, because another server process exited abnormally and possibly corrupted shared memory.
2022-03-12 05:27:56.653 UTC [455476] discourse@discourse HINT: In a moment you should be able to reconnect to the database and repeat your command.
2022-03-12 05:27:56.653 UTC [180506] discourse@discourse WARNING: terminating connection because of crash of another server process
2022-03-12 05:27:56.653 UTC [180506] discourse@discourse DETAIL: The postmaster has commanded this server process to roll back the current transaction and exit, because another server process exited abnormally and possibly corrupted shared memory.
2022-03-12 05:27:56.653 UTC [180506] discourse@discourse HINT: In a moment you should be able to reconnect to the database and repeat your command.
2022-03-12 05:27:56.653 UTC [455477] discourse@discourse WARNING: terminating connection because of crash of another server process
2022-03-12 05:27:56.653 UTC [455477] discourse@discourse DETAIL: The postmaster has commanded this server process to roll back the current transaction and exit, because another server process exited abnormally and possibly corrupted shared memory.
2022-03-12 05:27:56.653 UTC [455477] discourse@discourse HINT: In a moment you should be able to reconnect to the database and repeat your command.
2022-03-12 05:27:56.653 UTC [180499] WARNING: terminating connection because of crash of another server process
2022-03-12 05:27:56.653 UTC [180499] DETAIL: The postmaster has commanded this server process to roll back the current transaction and exit, because another server process exited abnormally and possibly corrupted shared memory.
2022-03-12 05:27:56.653 UTC [180499] HINT: In a moment you should be able to reconnect to the database and repeat your command.
2022-03-12 05:27:56.653 UTC [455581] discourse@discourse WARNING: terminating connection because of crash of another server process
2022-03-12 05:27:56.653 UTC [455581] discourse@discourse DETAIL: The postmaster has commanded this server process to roll back the current transaction and exit, because another server process exited abnormally and possibly corrupted shared memory.
2022-03-12 05:27:56.653 UTC [455581] discourse@discourse HINT: In a moment you should be able to reconnect to the database and repeat your command.
2022-03-12 05:27:56.653 UTC [455574] discourse@discourse WARNING: terminating connection because of crash of another server process
2022-03-12 05:27:56.653 UTC [455574] discourse@discourse DETAIL: The postmaster has commanded this server process to roll back the current transaction and exit, because another server process exited abnormally and possibly corrupted shared memory.
2022-03-12 05:27:56.653 UTC [455574] discourse@discourse HINT: In a moment you should be able to reconnect to the database and repeat your command.
2022-03-12 05:27:56.654 UTC [427436] discourse@discourse WARNING: terminating connection because of crash of another server process
2022-03-12 05:27:56.654 UTC [427436] discourse@discourse DETAIL: The postmaster has commanded this server process to roll back the current transaction and exit, because another server process exited abnormally and possibly corrupted shared memory.
2022-03-12 05:27:56.654 UTC [427436] discourse@discourse HINT: In a moment you should be able to reconnect to the database and repeat your command.
2022-03-12 05:27:56.657 UTC [455341] discourse@discourse WARNING: terminating connection because of crash of another server process
2022-03-12 05:27:56.657 UTC [455341] discourse@discourse DETAIL: The postmaster has commanded this server process to roll back the current transaction and exit, because another server process exited abnormally and possibly corrupted shared memory.
2022-03-12 05:27:56.657 UTC [455341] discourse@discourse HINT: In a moment you should be able to reconnect to the database and repeat your command.
2022-03-12 05:27:56.661 UTC [455559] discourse@discourse WARNING: terminating connection because of crash of another server process
2022-03-12 05:27:56.661 UTC [455559] discourse@discourse DETAIL: The postmaster has commanded this server process to roll back the current transaction and exit, because another server process exited abnormally and possibly corrupted shared memory.
2022-03-12 05:27:56.661 UTC [455559] discourse@discourse HINT: In a moment you should be able to reconnect to the database and repeat your command.
2022-03-12 05:27:56.698 UTC [450818] discourse@discourse WARNING: terminating connection because of crash of another server process
2022-03-12 05:27:56.698 UTC [450818] discourse@discourse DETAIL: The postmaster has commanded this server process to roll back the current transaction and exit, because another server process exited abnormally and possibly corrupted shared memory.
2022-03-12 05:27:56.698 UTC [450818] discourse@discourse HINT: In a moment you should be able to reconnect to the database and repeat your command.
2022-03-12 05:27:56.773 UTC [560] LOG: all server processes terminated; reinitializing
2022-03-12 05:27:56.957 UTC [455632] LOG: database system was interrupted; last known up at 2022-03-12 05:25:19 UTC
2022-03-12 05:27:56.957 UTC [455634] discourse@discourse FATAL: the database system is in recovery mode
2022-03-12 05:27:56.957 UTC [455633] discourse@discourse FATAL: the database system is in recovery mode
2022-03-12 05:27:56.958 UTC [455636] discourse@discourse FATAL: the database system is in recovery mode
2022-03-12 05:27:56.958 UTC [455635] discourse@discourse FATAL: the database system is in recovery mode
2022-03-12 05:27:56.966 UTC [455637] discourse@discourse FATAL: the database system is in recovery mode
2022-03-12 05:27:56.966 UTC [455638] discourse@discourse FATAL: the database system is in recovery mode
2022-03-12 05:27:56.966 UTC [455639] discourse@discourse FATAL: the database system is in recovery mode
2022-03-12 05:27:56.969 UTC [455640] discourse@discourse FATAL: the database system is in recovery mode
2022-03-12 05:27:56.977 UTC [455641] discourse@discourse FATAL: the database system is in recovery mode
2022-03-12 05:27:57.331 UTC [455632] LOG: database system was not properly shut down; automatic recovery in progress
2022-03-12 05:27:57.334 UTC [455632] LOG: redo starts at E/B99AC028
2022-03-12 05:27:57.371 UTC [455632] LOG: invalid record length at E/BA16D680: wanted 24, got 0
2022-03-12 05:27:57.371 UTC [455632] LOG: redo done at E/BA16D640
2022-03-12 05:27:57.467 UTC [560] LOG: database system is ready to accept connections

```

我认为最重要的几行是：

```plaintext
2022-03-12 05:27:56.647 UTC [560] LOG: checkpointer process (PID 180496) was terminated by signal 9: Killed
2022-03-12 05:27:56.650 UTC [560] LOG: terminating any other active server processes

```

论坛活动：

 ![image](https://global.discourse-cdn.com/meta/original/3X/9/0/907c6941c5e81fe837015c3418f384862fad8dce.png)  
需要重新烘焙 300000 条帖子（但错误可能在 150000 条或 1000 条重新烘焙的帖子后发生，具有一定的随机性）。

服务器配置：  
来自 Hetzner 的 **CPX21** ：[https://www.hetzner.com/cloud-fr](https://www.hetzner.com/cloud-fr)

- 3 个 vCPU
- 4 GB 内存
- 80 GB 磁盘（50% 可用）

另外，我发现 `dmesg` 命令可以显示更多信息，以下是该命令的末尾部分：

```plaintext
[590461.105649] oom-kill:constraint=CONSTRAINT_NONE,nodemask=(null),cpuset=2f5e8cd98980f017bab02228d6af1cfbbd0068935aedea9ab3680470befa2030,mems_allowed=0,global_oom,task_memcg=/docker/2f5e8cd98980f017bab02228d6af1cfbbd0068935aedea9ab3680470befa2030,task=postmaster,pid=1135915,uid=105
[590461.105673] Out of memory: Killed process 1135915 (postmaster) total-vm:1172132kB, anon-rss:7244kB, file-rss:0kB, shmem-rss:839588kB, UID:105 pgtables:2104kB oom_score_adj:0
[590461.109673] oom_reaper: reaped process 1135915 (postmaster), now anon-rss:0kB, file-rss:0kB, shmem-rss:839588kB
[592120.454582] Process accounting resumed
[592121.145664] Process accounting resumed

```

这些信息有帮助吗？

---

<div class="post-metadata">

### Author: ![RGJ](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/rgj/32/523185_2.png) [@RGJ](https://meta.discourse.org/u/RGJ)
#### Post date: [2022年三月12日 15:47 UTC](https://meta.discourse.org/t/rebake-aborts-with-error-message/220803/4 "2022-03-12T15:47:43Z")

</div>

> [@Canapin](#):
>
> `内存不足`

就是这个。  
当您的服务器（虚拟）内存不足时，操作系统会开始终止进程，以确保系统不会完全变得不可用。

由于这仅在重新烘焙期间发生，您可能不需要更多的实际内存，只需要更多的虚拟内存，这可以通过增大交换文件来完成。

---

<div class="post-metadata">

### Author: ![Canapin](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/canapin/32/119591_2.png) [@Canapin](https://meta.discourse.org/u/Canapin)
#### Post date: [2022年三月12日 17:50 UTC](https://meta.discourse.org/t/rebake-aborts-with-error-message/220803/5 "2022-03-12T17:50:29Z")

</div>

好的！

我有点惊讶，因为在重新烘焙时会出现内存不足的情况，而且它发生在重新烘焙的随机“阶段”，似乎在每个重新烘焙批次之间都会释放内存，而默认的重新烘焙批次默认相当小（大约 150 篇帖子？）。

* * *

我按照本指南创建了一个 2 GB 的交换文件。希望这会没问题。🙂

> [@Create a swapfile for your Linux server](https://meta.discourse.org/t/create-a-swapfile-for-your-linux-server/13880):
>
> bulb For servers with \<= 2GB of RAM, running ./discourse-setup will prompt for and automatically create a 2GB swapfile. Most cloud virtual machine providers do not set up swapfiles as part of their server provisioning. In particular, upgrading Discourse produces a lot of memory pressure. With a swap file, rather than randomly terminating processes with an out of memory error, things will slow down instead. Having a swap file is a cheap insurance policy that protects you from many other lo…

---

<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: [2022年四月11日 17:51 UTC](https://meta.discourse.org/t/rebake-aborts-with-error-message/220803/6 "2022-04-11T17:51:05Z")

</div>

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