You are not logged in.

#1 2012-06-04 08:17:45

TwiNight
Member
Registered: 2011-06-04
Posts: 46

[SOLVED]Cannot start postgresql using systemctl

I am thinking about switching entirely to systemd. So I have been playing around to learn systemd way of starting services.

[root@myhost sudeep]# systemctl start postgresql.service
Job failed. See system journal and 'systemctl status' for details.
[root@myhost sudeep]# systemctl status postgresql.service
postgresql.service - PostgreSQL database server
	  Loaded: loaded (/usr/lib/systemd/system/postgresql.service; disabled)
	  Active: failed (Result: exit-code) since Mon, 04 Jun 2012 19:14:44 +0530; 11s ago
	 Process: 1473 ExecStartPre=/usr/lib/systemd/scripts/postgresql-initdb (code=exited, status=1/FAILURE)
	  CGroup: name=systemd:/system/postgresql.service

Jun 04 19:14:44 myhost postgres[1473]: Creating symlink /var/lib/postgres ->

I also tried

[root@myhost sudeep]# initdb -D /var/lib/postgres/data
initdb: cannot be run as root
Please log in (using, e.g., "su") as the (unprivileged) user that will
own the server process.

And obviously I cannot run systemctl as a normal user. What is the problem?

Last edited by TwiNight (2012-06-06 04:52:30)

Offline

#2 2012-06-06 02:55:19

deltaecho
Member
From: Georgia (USA)
Registered: 2008-08-06
Posts: 187

Re: [SOLVED]Cannot start postgresql using systemctl

Try editing /etc/conf.d/postgresql, and uncomment the line for PGROOT="/var/lib/postgres" (although it is listed as having a default value, doing this resolved the issue for me).

EDIT: I found that config by looking in the postgesql.service file, which set the option ExecStartPre=/usr/lib/systemd/scripts/postgresql-initdb.  Looking in the corresponding file, I noticed that it made several references to $PGROOT, and since the statement "Creating symlink /var/lib/postgres -> $PGROOT" returned the empty string for $PGROOT, I figured that it was not correctly set.  At the top of that script, you will notice where it imports the postgres config: ". /etc/conf.d/postgresql".  Within that file is where the postgres options are set.

Last edited by deltaecho (2012-06-06 02:58:59)


Dylon

Offline

#3 2012-06-06 03:16:20

TwiNight
Member
Registered: 2011-06-04
Posts: 46

Re: [SOLVED]Cannot start postgresql using systemctl

deltaecho wrote:

Try editing /etc/conf.d/postgresql, and uncomment the line for PGROOT="/var/lib/postgres" (although it is listed as having a default value, doing this resolved the issue for me).

EDIT: I found that config by looking in the postgesql.service file, which set the option ExecStartPre=/usr/lib/systemd/scripts/postgresql-initdb.  Looking in the corresponding file, I noticed that it made several references to $PGROOT, and since the statement "Creating symlink /var/lib/postgres -> $PGROOT" returned the empty string for $PGROOT, I figured that it was not correctly set.  At the top of that script, you will notice where it imports the postgres config: ". /etc/conf.d/postgresql".  Within that file is where the postgres options are set.


I tried this. Still I am getting error as follows:

[root@myhost sudeep]# systemctl start postgresql.service
[root@myhost sudeep]# systemctl status postgresql.service
postgresql.service - PostgreSQL database server
          Loaded: loaded (/usr/lib/systemd/system/postgresql.service; disabled)
          Active: failed (Result: exit-code) since Wed, 06 Jun 2012 14:13:24 +0530; 8s ago
         Process: 1668 ExecStop=/bin/su - postgres -m -c /usr/bin/pg_ctl -s -D /var/lib/postgres/data stop -m fast (code=exited, status=1/FAILURE)
         Process: 1661 ExecStart=/bin/su - postgres -m -c /usr/bin/pg_ctl -s -D /var/lib/postgres/data start (code=exited, status=0/SUCCESS)
         Process: 1658 ExecStartPre=/usr/lib/systemd/scripts/postgresql-initdb (code=exited, status=0/SUCCESS)
        Main PID: 1666 (code=exited, status=1/FAILURE)
          CGroup: name=systemd:/system/postgresql.service

Jun 06 14:13:22 myhost su[1661]: pam_unix(su:session): session opened for user postgres by (uid=0)
Jun 06 14:13:24 myhost su[1668]: pam_unix(su:session): session opened for user postgres by (uid=0)
Jun 06 14:13:24 myhost postgres[1668]: pg_ctl: PID file "/var/lib/postgres/data/postmaster.pid" does not exist

Offline

#4 2012-06-06 04:06:00

deltaecho
Member
From: Georgia (USA)
Registered: 2008-08-06
Posts: 187

Re: [SOLVED]Cannot start postgresql using systemctl

EDIT: Scratch what I just wrote.  What do you see in /var/log/postgresql.log?

EDIT: Also, you can try starting postgres explicitly via the ExecStart directive of the service file:

/bin/su - postgres -m -c "/usr/bin/pg_ctl -s -D /var/lib/postgres/data start"

That may give you a more descriptive error message.

Last edited by deltaecho (2012-06-06 04:09:13)


Dylon

Offline

#5 2012-06-06 04:52:07

TwiNight
Member
Registered: 2011-06-04
Posts: 46

Re: [SOLVED]Cannot start postgresql using systemctl

deltaecho wrote:

EDIT: Scratch what I just wrote.  What do you see in /var/log/postgresql.log?

EDIT: Also, you can try starting postgres explicitly via the ExecStart directive of the service file:

/bin/su - postgres -m -c "/usr/bin/pg_ctl -s -D /var/lib/postgres/data start"

That may give you a more descriptive error message.


Problem Solved. When I ran the aforesaid directive, I got the typical error of postgresql shared_buffer exceeding kernel SHMMAX parameter. So I edited /etc/sysctl.conf appropriately and after restarting the system, I was able to start postgresql successfully via systemctl

Offline

#6 2012-08-13 09:49:25

g9164313
Member
Registered: 2012-08-13
Posts: 1

Re: [SOLVED]Cannot start postgresql using systemctl

try put the line, 'SYSTEMCTL_SKIP_REDIRECT=yes' in /etc/init.d/postgresql

like this
.
.
.
PGDOCDIR=/usr/share/doc/postgresql-9.0.4

SYSTEMCTL_SKIP_REDIRECT=yes

# Source function library.
. /etc/rc.d/init.d/functions

# Get network config.
. /etc/sysconfig/network

# Find the name of the script
NAME=`basename $0`
if [ ${NAME:0:1} = "S" -o ${NAME:0:1} = "K" ]
then
    NAME=${NAME:3}
fi
.
.
.

then, kill all files in /var/lib/pgsql

execute 'service postgresql initdb',

then, 'service postgresql start'.

regards

Offline

Board footer

Powered by FluxBB