Diganta Bharali
Diganta Bharali

Reputation: 243

could not access directory "/usr/local/pgsql/data": Permission denied ,while trying to setup database cluster

I am trying to set up Postgres in Redhat. I do the following steps:

$ sudo yum install postgresql-server postgresql-contrib

It is successfully installed. Then i try to set up a database cluster.

$ initdb -D /usr/local/pgsql/data

I get the error:

initdb: could not access directory "/usr/local/pgsql/data": Permission denied

New to linux. Not being able to move forward

Figured out the solution. I went to the specified folder and changed its access permission. It worked after that.

Upvotes: 5

Views: 20189

Answers (3)

summea
summea

Reputation: 7593

The PostgreSQL documentation notes that the /usr/local/pgsql/data directory needs to be owned by the postgres user.

To do this, you can run the following command:

chown postgres /usr/local/pgsql/data

And if that doesn't work, you might need to also use sudo:

sudo chown postgres /usr/local/pgsql/data

Upvotes: 5

Kadaztrof
Kadaztrof

Reputation: 13

While installing postgre, I used

su - postgres

to connect to the specific user with root privileges. Then, the following returned a success

/usr/pgsql-9.5/bin/initdb

Upvotes: 0

TWhelan
TWhelan

Reputation: 191

You are running the first command as a superuser and the second as a regular user. Try

 sudo initdb -D /usr/local/pgsql/data

Upvotes: 0

Related Questions