Score:0

Issue to configure PostGreSQL as a service on Ubuntu

np flag

I'm struggling to deal with PostGreSQL which I'm not able to launch as a service

My conf is set like this:

[Unit]
Description=PostgreSQL RDBMS
Documentation=https://www.postgresql.org/docs/
After=network.target

[Service]
Type=simple
User=postgres
ExecStart=/usr/lib/postgresql/13/bin/postgres "-D" "/var/lib/postgresql/13/main" "-c" "config_file=/etc/postgresql/13/main/postgresql.conf"
#ExecStart=/bin/true


[Install]
WantedBy=multi-user.target

then trying to start service:

ubuntu@my-server:~$ service postgresql status
● postgresql.service - PostgreSQL RDBMS
     Loaded: loaded (/lib/systemd/system/postgresql.service; enabled; vendor preset: enabled)
     Active: failed (Result: exit-code) since Fri 2023-08-25 05:33:53 UTC; 9min ago
       Docs: https://www.postgresql.org/docs/
    Process: 44461 ExecStart=/usr/lib/postgresql/13/bin/postgres -D /var/lib/postgresql/13/main -c config_file=/etc/postgresql/13/main/postgresql.conf (code=exited, status=1/FAILURE)
   Main PID: 44461 (code=exited, status=1/FAILURE)

Aug 25 05:33:53 my-server systemd[1]: Started PostgreSQL RDBMS.
Aug 25 05:33:53 my-server postgres[44461]: 2023-08-25 05:33:53.797 UTC [44461] FATAL:  lock file "postmaster.pid" already exists
Aug 25 05:33:53 my-server postgres[44461]: 2023-08-25 05:33:53.797 UTC [44461] HINT:  Is another postmaster (PID 43831) running in data directory "/var/lib/postgresql/13/main"?
Aug 25 05:33:53 my-server systemd[1]: postgresql.service: Main process exited, code=exited, status=1/FAILURE
Aug 25 05:33:53 my-server systemd[1]: postgresql.service: Failed with result 'exit-code'.

I guess something goes wrong

ubuntu@my-server:~$ sudo kill 43831
kill: (43831): No such process
ubuntu@my-server:~$ sudo service postgresql stop
ubuntu@my-server:~$ sudo service postgresql start

then again

ubuntu@my-server:~$ service postgresql status
● postgresql.service - PostgreSQL RDBMS
     Loaded: loaded (/lib/systemd/system/postgresql.service; enabled; vendor preset: enabled)
     Active: failed (Result: exit-code) since Fri 2023-08-25 05:45:42 UTC; 2s ago
       Docs: https://www.postgresql.org/docs/
    Process: 45126 ExecStart=/usr/lib/postgresql/13/bin/postgres -D /var/lib/postgresql/13/main -c config_file=/etc/postgresql/13/main/postgresql.conf (code=exited, status=1/FAILURE)
   Main PID: 45126 (code=exited, status=1/FAILURE)

Aug 25 05:45:42 my-server systemd[1]: Started PostgreSQL RDBMS.
Aug 25 05:45:42 my-server postgres[45126]: 2023-08-25 05:45:42.514 UTC [45126] FATAL:  lock file "postmaster.pid" already exists
Aug 25 05:45:42 my-server postgres[45126]: 2023-08-25 05:45:42.514 UTC [45126] HINT:  Is another postmaster (PID 45108) running in data directory "/var/lib/postgresql/13/main"?
Aug 25 05:45:42 my-server systemd[1]: postgresql.service: Main process exited, code=exited, status=1/FAILURE
Aug 25 05:45:42 my-server systemd[1]: postgresql.service: Failed with result 'exit-code'.

What am I doing wrong?

Trying to run this on Ubuntu 20

Thanks a lot for any help

Romeo Ninov avatar
in flag
Check which service create `postmaster.pid` and if its postgres remove the file by hand and try to start the service again.
Toucouleur avatar
np flag
I wish I could do that. I already went deleted it. In fact whenever I try to launch `postgresql.service` it does create this postmaster.pid so I don't understand why it says it already exists
I sit in a Tesla and translated this thread with Ai:

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.