大网数据广告活动
服务器运维问答

pg_ctl: could not open PID file "/var/lib/postgres/data/postmaster.pid": Permission denied

· 52CE 我爱测

On Arch Linux, after running the initdb command, I get the following message: Success. You can now start the database using: pg_ctl -D /var/lib/postgres/data -l logfile start As postgres user I attempt to start by using command a…

问题原文

原帖链接 · user1135541 · CC BY-SA 3.0

On Arch Linux, after running the initdb command, I get the following message:

Success. You can now start the database using:
    pg_ctl -D /var/lib/postgres/data -l logfile start

As postgres user I attempt to start by using command above and get and error:

FATAL: could not create lock file "/run/postgresql/.s.PGSQL.5432.lock" no such file or directory

I exit to postgres user and attempt to start by the command above and get:

pg_ctl: could not open PID file "/var/lib/postgres/data/postmaster.pid" : Permission denied

Than I try the above command ran as sudo:

sudo pg_ctl -D /var/lib/postgres/data -l logfile start

and get:

pg_ctl: cannot run as root.

已采纳解答

原帖链接 · Daniel Vérité · CC BY-SA 4.0

When starting postgres manually, that is without using the packaged startup script, you need to do what the script does:

  1. create the /run/postgresql directory with write permission for postgres and read permission for others. /run is typically mounted on a ram disk so it's normal that it's empty.

  2. run pg_ctl as the user postgres exclusively. Use sudo -u postgres if sudo has to be used for that.

The first error you mention is solved by #1 and the two others are solved by #2. Or just use the startup script that comes with the package for your OS, it's there to take care of these details so you don't have to learn them.

The doc at https://wiki.archlinux.org/index.php/PostgreSQL tells to:

Finally, start and enable the postgresql.service.

which would mean systemctl enable postgresql.service and systemctl start postgresql.service, as opposed to pg_ctl [...options...] start.

摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。

资料来源与适用范围

资料来源
Server Fault
适用范围
以原帖系统、软件版本与发布日期为准(2018-02-28)
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 3.0 / CC BY-SA 4.0

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。