Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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 
like image 213
Jimmy Odom Avatar asked May 03 '12 12:05

Jimmy Odom


People also ask

How do I fix Postgres permission denied?

Grant privileges to a new user We resolve this permission denied error using the command. GRANT ALL PRIVILEGES ON ALL TABLES IN SCHEMA public TO new_user; The new_user was then able to read data from the table. Similarly, we can also resolve the permission denied error by setting DEFAULT privileges to the user.

What is PostgreSQL initdb?

initdb initializes the database cluster's default locale and character set encoding. The character set encoding, collation order ( LC_COLLATE ) and character set classes ( LC_CTYPE , e.g., upper, lower, digit) can be set separately for a database when it is created.


1 Answers

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 
like image 106
Gaurav Swaroop Avatar answered Oct 06 '22 10:10

Gaurav Swaroop