Take the 2-minute tour ×
Database Administrators Stack Exchange is a question and answer site for database professionals who wish to improve their database skills and learn from others in the community. It's 100% free, no registration required.

I am working to run PostgreSQL is running locally but I cannot connect. I installed postgress using brew, then I downloaded http://postgresapp.com

When I try to create a database

createdb: could not connect to database postgres: could not connect to server: Permission denied Is the server running locally and accepting connections on Unix domain socket "/var/pgsql_socket/.s.PGSQL.5432"?

I tried to troubleshot this by using :

sudo sysctl -w kern.sysv.shmall=65536
sudo sysctl -w kern.sysv.shmmax=16777216

But nothing work out.

Any ideas how to solve this

share|improve this question
    
Don't know about mac but postgres is not running. You have to start the postgres service before doing anything –  Fabrizio Mazzoni Jan 17 at 14:10
add comment

2 Answers 2

Manually:

create the directory where you want the database files to be:

mkdir /postgres_data

chown postgres /postgres_data

then initialize the directory:

initdb /postgres_data --encoding=UTF8

start the database engine:

pg_ctl -D /postgres_data start

Now you can create your database:

createdb test
share|improve this answer
    
I got this error message when I try to initdb : Data page checksums are disabled. fixing permissions on existing directory /postgres_data ... initdb: could not change permissions of directory "/postgres_data": Operation not permitted –  user3001937 Jan 17 at 22:31
    
Try executing the command as the postgres user su postgres –  Fabrizio Mazzoni Jan 18 at 11:19
    
It says that "-bash: initdb: command not found" –  user3001937 Jan 19 at 6:33
add comment

If you have installed postgresql with brew there's one createdb that comes with it and that will connect to brew's postgresql.

Then if you have also installed Postgres.app there's another createdb at a different location that will connect to Postgres.app's postgresql.

Since OS X also ships with its own createdb in /usr/bin, that's a third createdb that expects to connect to Apple's postgresql, which is not running unless it's OS X Server Edition. According to the error message, this is the one that you're trying to use and which fails.

The solution is to use the createdb command that comes with the PostgreSQL you're actually running. Locate its directory and type the full path of createdb, as in /Applications/Postgres.app/Contents/MacOS/bin/createdb, and/or change your $PATH as suggested in postgresapp's doc.

This is a common problem for PostgreSQL on Mac OS X due the existence of many concurrent packages and of client-side programs pre-installed by Apple.

share|improve this answer
    
Do you mean by changing the path in .profile, adding this line PATH="/Applications/Postgres.app/Contents/MacOS/bin:$PATH" –  user3001937 Jan 17 at 22:35
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.