Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Failing to start PostgreSQL server on Centos

I just followed this tutorial:

http://www.unixmen.com/postgresql-9-4-released-install-centos-7/

But I can't start my postgres server on my centOS 6.5 machine.

Here's the error:

[root@vm5 ~]# service postgresql-9.4 initdb
Data directory is not empty!
[root@vm5 ~]# service postgresql-9.4 start                 [FAILED]
Starting postgresql-9.4 service:                           [FAILED]
[root@vm5 ~]# /etc/init.d/postgresql-9.4 start
Starting postgresql-9.4 service:                           [FAILED]

Before that tutorial I had already tried this one:

https://wiki.postgresql.org/wiki/YUM_Installation

I don't know what else to do.

like image 985
dex90 Avatar asked Dec 10 '25 18:12

dex90


2 Answers

It seems your postgres Data directory is not empty!. So manually remove data directory under lib/pgsql like,

 rm -rf /var/lib/pgsql/data

now initialize db. Yes, as @joop said, it would be better to take backup of data directory

mv /var/lib/pgsql/data  /var/lib/pgsql/data.OLD; 
mkdir /var/lib/pgsql/data; 
chown postgres:postgres /var/lib/pgsql/data

If you are facing low disk memory in pgsql dir, you can move data to some where, to do

cp -aRv /var/lib/pgsql/data  to_dir/path
rm -rf /var/lib/pgsql/data/*

so here, I hope you won't face chown problem.

like image 115
venkat Avatar answered Dec 13 '25 10:12

venkat


I just had a similar problem. It was related to permissions. If you look at startup logs you should find error message.

cat /var/lib/pgsql/9.4/pgstartup.log

< 2018-05-03 22:15:35.896 EDT >FATAL:  data directory "/var/lib/pgsql/9.4/data" has group or world access

< 2018-05-03 22:15:35.896 EDT >DETAIL:  Permissions should be u=rwx (0700).

If it is related to permissions like in my case then run the following

chown -R postgres /var/lib/pgsql/9.4/data

chmod -R 700 /var/lib/pgsql/9.4/data 

service postgresql-9.4 start
like image 31
Sergey V. Avatar answered Dec 13 '25 09:12

Sergey V.



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!