Trying to get Postgres setup in my environment but can't seem to get permissions to intidb

Jimmy Odom picture Jimmy Odom · May 3, 2012 · Viewed 38.1k times · Source

I'm following the recent RailsCast on setting up PostgreSQL, but I'm unable to run the initdb /usr/local/var/postgres command. Each time I run it, I get this error:

The files belonging to this database system will be owned by user "Construct".
This user must also own the server process.

The database cluster will be initialized with locale en_US.UTF-8.
The default database encoding has accordingly been set to UTF8.
The default text search configuration will be set to "english".

creating directory /usr/local/var/postgres ... initdb: could not create directory "/usr/local/var": Permission denied

Answer

Gaurav Swaroop picture Gaurav Swaroop · Mar 10, 2013

This should work just fine:

# sudo mkdir /usr/local/var/postgres
# sudo chmod 775 /usr/local/var/postgres
# sudo chown construct /usr/local/var/postgres
# initdb /usr/local/var/postgres

use your username in place of construct. So, if your computer username is WDurant, the code will be:

# sudo chown $(whoami) /usr/local/var/postgres