Artix Linux Forum

Artix Linux => Installation / Migration / Configuration => Topic started by: Leonardo on 10 July 2021, 11:36:44

Title: How do you setup PostgreSQL on Runit?
Post by: Leonardo on 10 July 2021, 11:36:44
Hello,
I downloaded
Code: [Select]
postgresql && postgresql-runit
After that I did this:
Code: [Select]
sudo ln -s /etc/runit/sv/postgresql /run/runit/service

After a reboot I started the service via
Code: [Select]
sudo sv start postgres (I also tried it with postgresql)
and it seemed to work, but after a
Code: [Select]
sudo sv status postgres
it always tells me that the service is down and I can`t create a user/database.
I followed the arch-installation (https://wiki.archlinux.org/title/PostgreSQL#Installation) until
Code: [Select]
sudo systemctl enable --now postgresql.service
.

Some information about my System:

I hope you can help me.
Thanks in advance!
Title: How do you setup PostgreSQL on Runit?
Post by: Leonardo on 10 July 2021, 12:46:47
Sorry, I accidentally replied with my Question.
Title: Re: How do you setup PostgreSQL on Runit?
Post by: capezotte on 10 July 2021, 15:56:07
I'm able to reproduce the issue here.

Running PostgreSQL manually:

Code: [Select]
$ sudo sh -c 'cd /etc/runit/sv/postgresql/ && exec sh -x ./run'
+ [ -r conf ]
+ . ./conf
+ PGROOT=/var/lib/postgres
+ PGLOG=/var/log/postgresql.log
+ INITOPTS=-A peer --auth-host=md5 --auth-local=peer --locale en_US.UTF-8
+ : /var/lib/postgres/data
+ [ /var/lib/postgres != /var/lib/postgres ]
+ [ ! -d /var/lib/postgres/data ]
+ exec chpst -u postgres:postgres postgres -D /var/lib/postgres/data
2021-07-10 10:50:41.123 -03 [20760] LOG:  starting PostgreSQL 13.3 on x86_64-pc-linux-gnu, compiled by gcc (GCC) 11.1.0, 64-bit
2021-07-10 10:50:41.124 -03 [20760] LOG:  listening on IPv6 address "::1", port 5432
2021-07-10 10:50:41.124 -03 [20760] LOG:  listening on IPv4 address "127.0.0.1", port 5432
2021-07-10 10:50:41.175 -03 [20760] FATAL:  could not create lock file "/run/postgresql/.s.PGSQL.5432.lock": No such file or directory
2021-07-10 10:50:41.180 -03 [20760] LOG:  database system is shut down

I then added the following line to the end of the conf in /etc/runit/sv/postgresql/conf so it'd create the folder it's complaining about not existing:

Code: [Select]
mkdir -p /run/postgresql/ && chown postgres:postgres /run/postgresql

Now it starts successfully here (both from sv start and manually).

Code: [Select]
sudo sh -c 'cd /etc/runit/sv/postgresql/ && exec sh -x ./run'
+ [ -r conf ]
+ . ./conf
+ PGROOT=/var/lib/postgres
+ PGLOG=/var/log/postgresql.log
+ INITOPTS=-A peer --auth-host=md5 --auth-local=peer --locale en_US.UTF-8
+ mkdir -p /run/postgresql/
+ chown postgres:postgres /run/postgresql
+ : /var/lib/postgres/data
+ [ /var/lib/postgres != /var/lib/postgres ]
+ [ ! -d /var/lib/postgres/data ]
+ exec chpst -u postgres:postgres postgres -D /var/lib/postgres/data
2021-07-10 10:55:12.549 -03 [22164] LOG:  starting PostgreSQL 13.3 on x86_64-pc-linux-gnu, compiled by gcc (GCC) 11.1.0, 64-bit
2021-07-10 10:55:12.549 -03 [22164] LOG:  listening on IPv6 address "::1", port 5432
2021-07-10 10:55:12.549 -03 [22164] LOG:  listening on IPv4 address "127.0.0.1", port 5432
2021-07-10 10:55:12.990 -03 [22164] LOG:  listening on Unix socket "/run/postgresql/.s.PGSQL.5432"
2021-07-10 10:55:13.205 -03 [22170] LOG:  database system was shut down at 2021-07-10 10:54:32 -03
2021-07-10 10:55:13.269 -03 [22164] LOG:  database system is ready to accept connections

Title: Re: How do you setup PostgreSQL on Runit?
Post by: Leonardo on 10 July 2021, 16:04:42
Thank you very much! My issue was that I kept running my service
Code: [Select]
sudo sv start postgresql
in the background. After stopping it and restarting it, I could succesfully create my user and a database!
Title: Re: How do you setup PostgreSQL on Runit?
Post by: capezotte on 10 July 2021, 16:30:55
Was that the only issue, or did my suggestion help?
Title: Re: How do you setup PostgreSQL on Runit?
Post by: Leonardo on 10 July 2021, 19:12:40
Was that the only issue, or did my suggestion help?
You totally solved my Problem. I wrote another answer, because after running your command, it showed me that an lockfile already exists and that there may be another one running this service. But after I
Code: [Select]
sudo mv stop postgresql
and then start it again it worked. But that was not the original solution, as I tried that multiple times yesterday.