首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >无法启动postgres服务,因为预期文件不在运行目录中

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

Unix & Linux用户
提问于 2023-05-11 11:06:50
回答 1查看 23关注 0票数 0

最近我试图在我的拱形机器上安装postgres。我能够以postgres用户的身份运行initdb命令,但实际上无法运行该服务。当我试图运行db时,我在我的终端中看到了这样的情况:

代码语言:javascript
复制
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

我检查了run目录,就像日志中说的那样,这里没有postgres:

代码语言:javascript
复制
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中?

EN

回答 1

Unix & Linux用户

发布于 2023-05-19 13:45:52

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

最后,开始启用 postgresql.service

这些连词说:

当一篇文章邀请启动、启用、停止或重新启动某些systemd单元(例如服务)时,它将不会指示这样做的详细说明,但是您将看到这样的内容: start example.service --这意味着您必须运行:# systemctl Start example.service -- 系统%d文章包含了在Arch中与systemd单元交互的所有详细说明。

要启动和启用postgresql,请执行以下操作:

代码语言:javascript
复制
systemctl enable postgresql
systemctl start postgresql

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

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

票数 1
EN
页面原文内容由Unix & Linux提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://unix.stackexchange.com/questions/745589

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档