Postgresql installation : initdb data directory not empty

installationpostgresql

I am trying to create the postgresql database.

When I install PostgreSQL, I gave this command:

sudo yum install postgresql postgresql-server

and later I modified the config file:

sudo vim /var/lib/pgsql/data/pg_hba.conf

and modified as

local   all         all                               trust
host    all         all         127.0.0.1/32          trust
host    all         all         ::1/128               trust
host    all         all         0.0.0.0/0             md5

While I am trying to startup the postgresql service:

sudo service postgresql initdb

> Data directory is not empty!                               [FAILED]

sudo chkconfig postgresql on

sudo service postgresql start

Starting postgresql service:                               [  OK  ]

What is caused these errors and how do I fix them?

Best Answer

Initdb should only be run once. It will create the directory where you'll keep the config files and (usually) the actual database. You've obviously already done that already; otherwrise there wouldn't be any pg_hba.conf for you to edit.

So, just don't run postgresql initdb again, unless you are doing a complete reinstall.