# FATAL：锁定文件“postmaster.pid”为空

**URL:** <https://meta.discourse.org/t/fatal-lock-file-postmaster-pid-is-empty/240895>\
**Category:** Self-hosting\
**Created:** [2022年十月4日 14:52 UTC](https://meta.discourse.org/t/fatal-lock-file-postmaster-pid-is-empty/240895 "2022-10-04T14:52:49Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![will\_io](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/will_io/32/147541_2.png) [@will\_io](https://meta.discourse.org/u/will_io)\
**Post date:** [2022年十月4日 14:52 UTC](https://meta.discourse.org/t/fatal-lock-file-postmaster-pid-is-empty/240895/1 "2022-10-04T14:52:49Z")

</div>

这是我重建时第一次看到以下错误。

```plaintext
2022-10-04 14:39:49.780 UTC [1700] FATAL: lock file "postmaster.pid" is empty
2022-10-04 14:39:49.780 UTC [1700] HINT: Either another server is starting, or the lock file is the remnant of a previous server startup crash.

```

我显然可以读懂提示，但不确定如何进行。有人能提供一些见解吗？

---

<div class="post-metadata">

**Author:** ![pfaffman](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/pfaffman/32/120154_2.png) [@pfaffman](https://meta.discourse.org/u/pfaffman)\
**Post date:** [2022年十月4日 15:15 UTC](https://meta.discourse.org/t/fatal-lock-file-postmaster-pid-is-empty/240895/2 "2022-10-04T15:15:52Z")

</div>

这是什么时候发生的？这是标准安装吗？

---

<div class="post-metadata">

**Author:** ![will\_io](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/will_io/32/147541_2.png) [@will\_io](https://meta.discourse.org/u/will_io)\
**Post date:** [2022年十月4日 15:17 UTC](https://meta.discourse.org/t/fatal-lock-file-postmaster-pid-is-empty/240895/3 "2022-10-04T15:17:05Z")

</div>

标准安装，并在执行 ./launcher rebuild app 后

---

<div class="post-metadata">

**Author:** ![pfaffman](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/pfaffman/32/120154_2.png) [@pfaffman](https://meta.discourse.org/u/pfaffman)\
**Post date:** [2022年十月4日 15:19 UTC](https://meta.discourse.org/t/fatal-lock-file-postmaster-pid-is-empty/240895/4 "2022-10-04T15:19:07Z")

</div>

也许可以试试  
./launcher start app

这之前奏效吗？

这是错误还是警告。你试过在浏览器中打开吗？

什么显示

```
 docker ps

```

---

<div class="post-metadata">

**Author:** ![will\_io](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/will_io/32/147541_2.png) [@will\_io](https://meta.discourse.org/u/will_io)\
**Post date:** [2022年十月4日 15:21 UTC](https://meta.discourse.org/t/fatal-lock-file-postmaster-pid-is-empty/240895/5 "2022-10-04T15:21:14Z")

</div>

Response to ./launcher start app:

```plaintext
57c2a0746e93
Nothing to do, your container has already started!

```

然后我在浏览器中收到 502 Bad Gateway。

---

<div class="post-metadata">

**Author:** ![will\_io](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/will_io/32/147541_2.png) [@will\_io](https://meta.discourse.org/u/will_io)\
**Post date:** [2022年十月4日 15:22 UTC](https://meta.discourse.org/t/fatal-lock-file-postmaster-pid-is-empty/240895/6 "2022-10-04T15:22:04Z")

</div>

docker ps 输出

```plaintext
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
57c2a0746e93 local_discourse/app “/sbin/boot” 6 months ago Up 16 minutes 0.0.0.0:80->80/tcp, :::80->80/tcp, 0.0.0.0:443->443/tcp, :::443->443/tcp, 0.0.0.0:5432->5432/tcp, :::5432->5432/tcp app

```

---

<div class="post-metadata">

**Author:** ![pfaffman](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/pfaffman/32/120154_2.png) [@pfaffman](https://meta.discourse.org/u/pfaffman)\
**Post date:** [2022年十月4日 15:24 UTC](https://meta.discourse.org/t/fatal-lock-file-postmaster-pid-is-empty/240895/7 "2022-10-04T15:24:21Z")

</div>

这很奇怪。我想我可能会重启并重新构建。

或者也许

```
   ./launcher stop app; ./launcher rebuild app

```

您正在运行一个旧容器，而不是刚刚构建的（6个月前创建的）容器。

而且重新构建过程中可能还有其他您没有注意到的错误。

---

<div class="post-metadata">

**Author:** ![will\_io](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/will_io/32/147541_2.png) [@will\_io](https://meta.discourse.org/u/will_io)\
**Post date:** [2022年十月4日 15:27 UTC](https://meta.discourse.org/t/fatal-lock-file-postmaster-pid-is-empty/240895/8 "2022-10-04T15:27:25Z")

</div>

相同的结果

```plaintext
2022-10-04 15:26:43.452 UTC [1699] FATAL: lock file "postmaster.pid" is empty
2022-10-04 15:26:43.452 UTC [1699] HINT: Either another server is starting, or the lock file is the remnant of a previous server startup crash.

```

---

<div class="post-metadata">

**Author:** ![sam](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/sam/32/102149_2.png) [@sam](https://meta.discourse.org/u/sam)\
**Post date:** [2022年十一月21日 01:34 UTC](https://meta.discourse.org/t/fatal-lock-file-postmaster-pid-is-empty/240895/9 "2022-11-21T01:34:26Z")

</div>

这里没有足够的数据来调试。

发生这种情况是因为构建过程认为 PG 已经在运行，所以 PG 升级过程可能有些不对劲。你能包含启动器的完整日志（去除密码）以便我们查看情况吗？

---

<div class="post-metadata">

**Author:** ![Ed\_S](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/ed_s/32/134015_2.png) [@Ed\_S](https://meta.discourse.org/u/Ed_S)\
**Post date:** [2022年十一月23日 17:45 UTC](https://meta.discourse.org/t/fatal-lock-file-postmaster-pid-is-empty/240895/10 "2022-11-23T17:45:38Z")

</div>

也许看看一个正常工作的系统会有帮助。我在这里看到了我的锁文件：

```plaintext
# ls -l /var/discourse/shared/standalone/postgres_data/postmaster.pid
-rw------- 1 systemd-resolve input 92 Nov 15 16:20 /var/discourse/shared/standalone/postgres_data/postmaster.pid

```

11 月 15 日是我上次启动应用程序的日期。如果我进入应用程序，可以看到 postgres 进程：

```plaintext
# cd /var/discourse/
# ./launcher enter app
x86_64 arch detected.
# ps auxfc|egrep -1 postm
root 45 0.0 0.0 2332 0 ? S Nov15 0:00 \_ svlogd
postgres 48 0.0 0.1 213160 1784 ? S Nov15 0:27 \_ postmaster
postgres 67 0.0 2.6 213380 26924 ? Ss Nov15 0:34 \_ postmaster
postgres 68 0.0 0.4 213292 4236 ? Ss Nov15 0:15 \_ postmaster
postgres 69 0.0 0.1 213160 1068 ? Ss Nov15 3:44 \_ postmaster
postgres 70 0.0 0.1 213840 1520 ? Ss Nov15 0:16 \_ postmaster
postgres 71 0.0 0.0 68184 380 ? Ss Nov15 0:56 \_ postmaster
postgres 72 0.0 0.0 213716 468 ? Ss Nov15 0:00 \_ postmaster
postgres 92 0.0 0.0 225364 324 ? Ss Nov15 0:01 \_ postmaster
postgres 176 0.0 0.1 217944 1484 ? Ss Nov15 0:01 \_ postmaster
postgres 9126 0.0 0.7 215052 7336 ? Ss Nov16 0:19 \_ postmaster
postgres 1574 0.0 5.7 223540 58300 ? Ss 17:28 0:00 \_ postmaster
postgres 1973 0.0 3.3 221032 33960 ? Ss 17:34 0:00 \_ postmaster
postgres 2320 0.1 3.5 218080 36120 ? Ss 17:39 0:00 \_ postmaster
postgres 2321 0.1 2.9 218068 29928 ? Ss 17:39 0:00 \_ postmaster
postgres 2336 0.0 1.4 215052 14340 ? Ss 17:40 0:00 \_ postmaster
# exit

```

如果我停止了应用程序，我期望在该位置看不到锁文件，并且没有 postgres 进程在运行。（当然，我需要在主机上直接运行 `ps` 命令，因为容器将不再运行。）

在您的情况下，我认为我首先会这样做：停止应用程序并检查没有 postgres 进程在运行。似乎有可能您有两个实例在运行，它们之间发生了冲突。

不太可能，但也有可能磁盘已满，这就是为什么锁文件为空。或者可能存在某种权限问题。

编辑：在容器内，锁文件具有不同的位置和所有权：

```plaintext
# ./launcher enter app
x86_64 arch detected.
# ls -l /shared/postgres_data/postmaster.pid
-rw------- 1 postgres postgres 92 Nov 15 16:20 /shared/postgres_data/postmaster.pid
# exit
logout
# 

```

正如 Sam 指出的，我们需要看到更多信息。
