Postgresql – Can’t run PostgreSQL locally

postgresqlpostgresql-9.2

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

Best Answer

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.