无法启动 postgres 服务,因为预期的文件不在运行目录中

无法启动 postgres 服务,因为预期的文件不在运行目录中

我最近尝试在我的 arch 机器上安装 postgres。我能够initdb以 postgres 用户身份运行该命令,但实际上无法运行该服务。这是我尝试运行数据库时在终端中看到的内容:

insomnia@the-void ~/p/lemmy (main)> su - postgres -c "pg_ctl -D /var/lib/postgres/data -l logfile start"
Password: 
waiting for server to start.... stopped waiting
pg_ctl: could not start server
Examine the log output.
insomnia@the-void ~/p/lemmy (main) [1]> cat logfile
2023-05-11 06:31:05.607 EDT [6545] LOG:  starting PostgreSQL 15.2 on x86_64-pc-linux-gnu, compiled by gcc (GCC) 12.2.1 20230211, 64-bit
2023-05-11 06:31:05.607 EDT [6545] LOG:  listening on IPv6 address "::1", port 5432
2023-05-11 06:31:05.607 EDT [6545] LOG:  listening on IPv4 address "127.0.0.1", port 5432
2023-05-11 06:31:05.609 EDT [6545] FATAL:  could not create lock file "/run/postgresql/.s.PGSQL.5432.lock": No such file or directory
2023-05-11 06:31:05.611 EDT [6545] LOG:  database system is shut down
2023-05-11 06:37:28.083 EDT [7218] LOG:  starting PostgreSQL 15.2 on x86_64-pc-linux-gnu, compiled by gcc (GCC) 12.2.1 20230211, 64-bit
2023-05-11 06:37:28.083 EDT [7218] LOG:  listening on IPv6 address "::1", port 5432
2023-05-11 06:37:28.083 EDT [7218] LOG:  listening on IPv4 address "127.0.0.1", port 5432
2023-05-11 06:37:28.085 EDT [7218] FATAL:  could not create lock file "/run/postgresql/.s.PGSQL.5432.lock": No such file or directory
2023-05-11 06:37:28.087 EDT [7218] LOG:  database system is shut down
2023-05-11 06:38:39.659 EDT [7363] LOG:  starting PostgreSQL 15.2 on x86_64-pc-linux-gnu, compiled by gcc (GCC) 12.2.1 20230211, 64-bit
2023-05-11 06:38:39.660 EDT [7363] LOG:  listening on IPv6 address "::1", port 5432
2023-05-11 06:38:39.660 EDT [7363] LOG:  listening on IPv4 address "127.0.0.1", port 5432
2023-05-11 06:38:39.662 EDT [7363] FATAL:  could not create lock file "/run/postgresql/.s.PGSQL.5432.lock": No such file or directory
2023-05-11 06:38:39.666 EDT [7363] LOG:  database system is shut down
2023-05-11 06:38:53.104 EDT [7430] LOG:  starting PostgreSQL 15.2 on x86_64-pc-linux-gnu, compiled by gcc (GCC) 12.2.1 20230211, 64-bit
2023-05-11 06:38:53.105 EDT [7430] LOG:  listening on IPv6 address "::1", port 5432
2023-05-11 06:38:53.105 EDT [7430] LOG:  listening on IPv4 address "127.0.0.1", port 5432
2023-05-11 06:38:53.106 EDT [7430] FATAL:  could not create lock file "/run/postgresql/.s.PGSQL.5432.lock": No such file or directory
2023-05-11 06:38:53.108 EDT [7430] LOG:  database system is shut down

我检查了运行目录,就像日志中所说的那样,那里没有 postgres 的任何内容:

insomnia@the-void ~/p/lemmy (main)> ls -a /run
./       containerd/   dbus/             docker/       faillock/   log/    mount/           nvidia-xdriver-d8991f8f=  samba/  systemd/     udev/     utmp
../      credentials/  dmeventd-client|  docker.pid    initramfs/  lvm/    NetworkManager/  openvpn-client/           sddm/   tmpfiles.d/  udisks2/  xtables.lock
clamav/  cups/         dmeventd-server|  docker.sock=  lock/       media/  nscd/            openvpn-server/           sudo/   tpm2-tss/    user/
insomnia@the-void ~/p/lemmy (main)> ls -a /run | grep postgresql
insomnia@the-void ~/p/lemmy (main) [0|1]> 

如何确保预期的目录/文件位于 /run 中?

答案1

你掉进陷阱了!这拱门维基文字本身并没有说要使用pg_ctl start。相反,它说:

最后,开始使能够postgresql.service

链接的词说:

systemd 单元的控制

当一篇文章邀请启动、启用、停止或重新启动某些 systemd 单元(例如服务)时,它不会指示执行此操作的详细说明,而是您会看到类似以下内容的内容:

启动 example.service

这意味着您必须运行:

# systemctl start example.service

系统文章包含了熟练地与 Arch Linux 中的 systemd 单元交互的所有详细说明。

启动并启用 postgresql:

systemctl enable postgresql
systemctl start postgresql

这将使用系统服务定义。我们可能会猜测这知道如何创建/run/postgresql/

由于Arch使用systemd,它将确保postgresql直接启动PID 1。它将避免意外继承您终端中可能拥有的任何特殊自定义环境。漂亮又干净。

相关内容