0

I recently tried to install postgres on my arch machine. I was able to run the initdb command as the postgres user, but I cannot actually run the service. This is what I see in my terminal when I try to run the db:

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

I checked the run directory and, just like was said in the logs, there is nothing for postgres there:

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]> 

How do I make sure the expected directories/files are in /run?

1 Answer 1

1

You fell in a trap! The Arch wiki text itself does not say to use pg_ctl start. Instead, it says:

Finally, start and enable the postgresql.service

The linked words say:

Control of systemd units

When an article invites to start, enable, stop or restart some systemd units (e.g. a service), it will not indicate the detailed instructions to do so, but instead you will read something like:

Start example.service

This means that you have to run:

# systemctl start example.service

The systemd article contains all the detailed explanations to interact with systemd units in Arch Linux proficiently.

To start and enable postgresql:

systemctl enable postgresql
systemctl start postgresql

This will use the system service definition. We might guess this knows how to create /run/postgresql/.

Since Arch uses systemd, it will ensure postgresql is started directly by PID 1. It will avoid accidentally inheriting any special custom environment you may have in your terminal. Nice and clean.

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.