问题原文
原帖链接 · 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:
create the
/run/postgresqldirectory with write permission forpostgresand read permission for others./runis typically mounted on a ram disk so it's normal that it's empty.run
pg_ctlas the userpostgresexclusively. Usesudo -u postgresifsudohas 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:
which would mean systemctl enable postgresql.service and systemctl start postgresql.service, as opposed to pg_ctl [...options...] start.
摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。
