You are not logged in.

#1 2012-12-30 04:21:15

kleitonkk
Member
From: Brazil
Registered: 2012-04-22
Posts: 10

[Solved] postgresql with systemd

Hello Guys,

I'm having problems starting the postgres with systemd.

Following errors:


Running systemctl start postgresql

k@archK ~ % sudo systemctl start postgresql
Job for postgresql.service failed. See 'systemctl status postgresql.service' and 'journalctl -xn' for details.
1 k@archK ~ %  

Running systemctl status postgresql.service got the message below:

k@archK ~ % systemctl status postgresql.service
postgresql.service - PostgreSQL database server
          Loaded: loaded (/usr/lib/systemd/system/postgresql.service; enabled)
          Active: failed (Result: exit-code) since Sáb, 2012-12-29 19:09:19 BRT; 1min 19s ago
         Process: 1746 ExecStart=/usr/bin/pg_ctl -s -D ${PGROOT}/data start -w -t 120 (code=exited, status=1/FAILURE)
         Process: 1741 ExecStartPre=/usr/bin/postgresql-check-db-dir ${PGROOT}/data (code=exited, status=0/SUCCESS)
          CGroup: name=systemd:/system/postgresql.service

3 k@archK ~ % 

and journalctl -xn this:

k@archK ~ % sudo journalctl -xn
[sudo] password for k: 
-- Logs begin at Sáb, 2012-12-29 03:47:42 BRT, end at Sáb, 2012-12-29 19:11:49 BRT. --
Dez 29 19:09:19 archK systemd[1]: postgresql.service: control process exited, code=exited status=1
Dez 29 19:09:19 archK systemd[1]: Failed to start PostgreSQL database server.
-- Subject: Unit postgresql.service has failed
-- Defined-By: systemd
-- Support: http://lists.freedesktop.org/mailman/listinfo/systemd-devel
-- Documentation: http://www.freedesktop.org/wiki/Software/systemd/catalog/be02cf6855d2428ba40df7e9d022f03d
-- 
-- Unit postgresql.service has failed.
-- 
-- The result is failed.
Dez 29 19:09:19 archK systemd[1]: Unit postgresql.service entered failed state
Dez 29 19:09:19 archK sudo[1738]: pam_unix(sudo:session): session closed for user root
Dez 29 19:11:27 archK udisks-daemon[430]: **** Refreshing ATA SMART data for /sys/devices/pci0000:00/0000:00:1f.2/ata1/host0/target0:0:0/0:0:0:0/block/sda
Dez 29 19:11:27 archK udisks-daemon[430]: helper(pid  1781): launched job udisks-helper-ata-smart-collect on /dev/sda
Dez 29 19:11:28 archK udisks-daemon[430]: helper(pid  1781): completed with exit code 0
Dez 29 19:11:28 archK udisks-daemon[430]: **** EMITTING CHANGED for /sys/devices/pci0000:00/0000:00:1f.2/ata1/host0/target0:0:0/0:0:0:0/block/sda
Dez 29 19:11:49 archK sudo[1786]: k : TTY=pts/0 ; PWD=/home/k ; USER=root ; COMMAND=/usr/bin/journalctl -xn
Dez 29 19:11:49 archK sudo[1786]: pam_unix(sudo:session): session opened for user root by k(uid=0)

Here is the postgresql.service

[Unit]
Description=PostgreSQL database server
After=network.target

[Service]
Type=forking
TimeoutSec=120
User=postgres
Group=postgres

Environment=PGROOT=/var/lib/postgres

SyslogIdentifier=postgres
PIDFile=/var/lib/postgres/data/postmaster.pid

ExecStartPre=/usr/bin/postgresql-check-db-dir ${PGROOT}/data
ExecStart= /usr/bin/pg_ctl -s -D ${PGROOT}/data start -w -t 120
ExecReload=/usr/bin/pg_ctl -s -D ${PGROOT}/data reload
ExecStop=  /usr/bin/pg_ctl -s -D ${PGROOT}/data stop -m fast

# Due to PostgreSQL's use of shared memory, OOM killer is often overzealous in
# killing Postgres, so adjust it downward
OOMScoreAdjust=-200

[Install]
WantedBy=multi-user.target

and /etc/conf.d/postgresql

##
## Parameters to be passed to postgresql
##
## Default data directory location
PGROOT="/var/lib/postgres"
## Passed to initdb if necessary
INITOPTS="--locale en_US.UTF-8"
## Default log file location
#PGLOG="/var/log/postgresql.log"
## Additional options to pass via pg_ctl's '-o' option
#PGOPTS=""

Does anyone have any idea how to fix this?

Thanks.

Last edited by kleitonkk (2013-01-03 23:51:41)

Offline

#2 2012-12-30 10:02:18

lothar_m
Member
From: Cyberspace
Registered: 2010-04-25
Posts: 32

Re: [Solved] postgresql with systemd

i've also had som trouble with postgresql and systemd in the past.
perhaps this could help https://bbs.archlinux.org/viewtopic.php?id=149446


“Clearly, Field Marshal Haig is about to make yet another gargantuan effort to move his drinks cabinet six inches closer to Berlin.”

Offline

#3 2013-01-03 20:42:32

kleitonkk
Member
From: Brazil
Registered: 2012-04-22
Posts: 10

Re: [Solved] postgresql with systemd

Sorry for the delay, was traveling and just returned yesterday.

lothar_m was followed as described in the post, since removed the packages twice and did the install again but the same error.

[root@archK conf.d]# systemctl start postgresql

Job for postgresql.service failed. See 'systemctl status postgresql.service' and 'journalctl -xn' for details.
[root@archK conf.d]# 

systemctl status postgresql.service

➜  ~  systemctl status postgresql.service
postgresql.service - PostgreSQL database server
          Loaded: loaded (/usr/lib/systemd/system/postgresql.service; disabled)
          Active: failed (Result: exit-code) since Thu, 2013-01-03 18:14:43 BRT; 9min ago
         Process: 10897 ExecStart=/usr/bin/pg_ctl -s -D ${PGROOT}/data start -w -t 120 (code=exited, status=1/FAILURE)
         Process: 10892 ExecStartPre=/usr/bin/postgresql-check-db-dir ${PGROOT}/data (code=exited, status=0/SUCCESS)
          CGroup: name=systemd:/system/postgresql.service

➜  ~  

[root@archK conf.d]# journalctl -xn

-- Logs begin at Wed, 2013-01-02 16:50:57 BRT, end at Thu, 2013-01-03 18:34:41 BRT. --
Jan 03 18:25:28 archK su[11082]: pam_unix(su:session): session opened for user root by k(uid=1000)
Jan 03 18:34:36 archK systemd[1]: Starting PostgreSQL database server...
-- Subject: Unit postgresql.service has begun with start-up
-- Defined-By: systemd
-- Support: http://lists.freedesktop.org/mailman/listinfo/systemd-devel
-- Documentation: http://www.freedesktop.org/wiki/Software/systemd/catalog/7d4958e842da4a758f6c1cdc7b36dcc5
-- 
-- Unit postgresql.service has begun starting up.
Jan 03 18:34:36 archK postgres[11127]: LOG:  could not translate host name "localhost", service "5432" to address: Name or service not known
Jan 03 18:34:36 archK postgres[11127]: WARNING:  could not create listen socket for "localhost"
Jan 03 18:34:36 archK postgres[11127]: FATAL:  could not create any TCP/IP sockets
Jan 03 18:34:41 archK postgres[11127]: pg_ctl: could not start server
Jan 03 18:34:41 archK postgres[11127]: Examine the log output.
Jan 03 18:34:41 archK systemd[1]: postgresql.service: control process exited, code=exited status=1
Jan 03 18:34:41 archK systemd[1]: Failed to start PostgreSQL database server.
-- Subject: Unit postgresql.service has failed
-- Defined-By: systemd
-- Support: http://lists.freedesktop.org/mailman/listinfo/systemd-devel
-- Documentation: http://www.freedesktop.org/wiki/Software/systemd/catalog/be02cf6855d2428ba40df7e9d022f03d
-- 
-- Unit postgresql.service has failed.
-- 
-- The result is failed.
Jan 03 18:34:41 archK systemd[1]: Unit postgresql.service entered failed state

/usr/lib/systemd/system/postgresql.service

[Unit]
Description=PostgreSQL database server
After=network.target

[Service]
Type=forking
TimeoutSec=120
User=postgres
Group=postgres

Environment=PGROOT=/var/lib/postgres

SyslogIdentifier=postgres
PIDFile=/var/lib/postgres/data/postmaster.pid

ExecStartPre=/usr/bin/postgresql-check-db-dir ${PGROOT}/data
ExecStart= /usr/bin/pg_ctl -s -D ${PGROOT}/data start -w -t 120
ExecReload=/usr/bin/pg_ctl -s -D ${PGROOT}/data reload
ExecStop=  /usr/bin/pg_ctl -s -D ${PGROOT}/data stop -m fast

# Due to PostgreSQL's use of shared memory, OOM killer is often overzealous in
# killing Postgres, so adjust it downward
OOMScoreAdjust=-200

[Install]
WantedBy=multi-user.target
➜  ~  pacman -Q |grep postgres
postgresql 9.2.2-2
postgresql-libs 9.2.2-2
➜  ~     

/etc/conf.d

##
## Parameters to be passed to postgresql
##
## Default data directory location
PGROOT="/var/lib/postgres"
## Passed to initdb if necessary
INITOPTS="--locale en_US.UTF-8"
## Default log file location
#PGLOG="/var/log/postgresql.log"
## Additional options to pass via pg_ctl's '-o' option
#PGOPTS=""

/usr/lib/systemd/system/postgresql.service

[Unit]
Description=PostgreSQL database server
After=network.target

[Service]
Type=forking
TimeoutSec=120
User=postgres
Group=postgres

Environment=PGROOT=/var/lib/postgres

SyslogIdentifier=postgres
PIDFile=/var/lib/postgres/data/postmaster.pid

ExecStartPre=/usr/bin/postgresql-check-db-dir ${PGROOT}/data
ExecStart= /usr/bin/pg_ctl -s -D ${PGROOT}/data start -w -t 120
ExecReload=/usr/bin/pg_ctl -s -D ${PGROOT}/data reload
ExecStop=  /usr/bin/pg_ctl -s -D ${PGROOT}/data stop -m fast

# Due to PostgreSQL's use of shared memory, OOM killer is often overzealous in
# killing Postgres, so adjust it downward
OOMScoreAdjust=-200

[Install]
WantedBy=multi-user.target

I'm still looking for how to solve.
Thank you.

Offline

#4 2013-01-03 23:51:11

kleitonkk
Member
From: Brazil
Registered: 2012-04-22
Posts: 10

Re: [Solved] postgresql with systemd

Following a tip from a friend of the Brazilian forum I realized that the service is looking for a hostname different from what I had set "localhost"

So it was just change for the same name in /etc/hosts and /etc/hostname that worked perfectly.

Thanks for the help.

Offline

#5 2013-01-27 20:35:14

gavrik
Member
Registered: 2013-01-27
Posts: 7

Re: [Solved] postgresql with systemd

Another way for solving problem was rewriting service file for systemd. Something like that:

[Unit]
Description=PostgreSQL database server
After=network.target

[Service]
Type=forking
TimeoutSec=120
User=postgres
Group=postgres

EnvironmentFile=/etc/conf.d/postgresql
#Environment=PGROOT=/var/lib/postgres

SyslogIdentifier=postgres
#PIDFile=/var/lib/postgres/data/postmaster.pid
PIDFile=$PGROOT/data/postgresql.pid

ExecStartPre=/usr/bin/postgresql-check-db-dir ${PGROOT}
ExecStart= /usr/bin/pg_ctl -s -D ${PGROOT} start -l ${PGLOG} -o ${PGOPTS} -w -t 120
ExecReload=/usr/bin/pg_ctl -s -D ${PGROOT} reload
ExecStop=  /usr/bin/pg_ctl -s -D ${PGROOT} stop -m fast

# Due to PostgreSQL's use of shared memory, OOM killer is often overzealous in
# killing Postgres, so adjust it downward
OOMScoreAdjust=-200

[Install]
WantedBy=multi-user.target

Last edited by gavrik (2013-01-27 20:36:12)

Offline

Board footer

Powered by FluxBB