0

Trying to setup Postgres / PostGIS on OSX Mountain Lion to use with Django. However, something is wrong and I am not sure how to fix it.

$ createdb geo
createdb: could not connect to database postgres: could not connect to server: No such file or directory
    Is the server running locally and accepting
    connections on Unix domain socket "/var/pgsql_socket/.s.PGSQL.5432"?

$ postgres -D /usr/local/var/postgres
FATAL:  lock file "postmaster.pid" already exists
HINT:  Is another postmaster (PID 221) running in data directory "/usr/local/var/postgres"?

$ pg_ctl -D /usr/local/var/postgres -l logfile start
pg_ctl: another server might be running; trying to start server anyway
server starting

Then I found this gist that said how to fix it on lion. However it did not work for me:

$ kill -9 221
$ pg_ctl -D /usr/local/var/postgres stop
waiting for server to shut down.... done
server stopped

$ pg_ctl -D /usr/local/var/postgres start
pg_ctl: another server might be running; trying to start server anyway
server starting
FATAL:  lock file "postmaster.pid" already exists
HINT:  Is another postmaster (PID 1436) running in data directory "/usr/local/var/postgres"?

Another attempt:

$ cd /usr/local/var/postgres
$ mv postmaster.pid postmaster.backup
$ pg_ctl -D /usr/local/var/postgres start
server starting

$ LOG:  could not bind IPv6 socket: Address already in use
HINT:  Is another postmaster already running on port 5432? If not, wait a few seconds and retry.
LOG:  could not bind IPv4 socket: Address already in use
HINT:  Is another postmaster already running on port 5432? If not, wait a few seconds and retry.
LOG:  could not bind IPv6 socket: Address already in use
HINT:  Is another postmaster already running on port 5432? If not, wait a few seconds and retry.
WARNING:  could not create listen socket for "localhost"
FATAL:  could not create any TCP/IP sockets

Has anyone successfully done this with mountain lion? If so, what am I missing? Thanks for your help with this issue!

Nick B
  • 9,267
  • 17
  • 64
  • 105

1 Answers1

1

This message:

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

indicates that your PostgreSQL server doesn't use /var/pgsql_socket as its Unix domain socket directory, which is the rendez-vous point between the server and the client. This is quite common, since only PostgreSQL shipped by Apple with OSX server uses that path. Incidentally, this is why the createdb command as shipped by Apple tries to connect to the server as configured by Apple.

From that point, there are a lot of different solutions to work around the problem, but the more obvious one would be to use the createdb command that comes with your PostgreSQL installation instead of the one that is preinstalled in your system.

Should you need further help with that, you should specify how you installed PostgreSQL, because there are quite a few different packages that provide it, and they all use different paths to avoid trampling over each other.

Update for Homebrew

If using brew, I suggest to apply the answer on superuser.com: How should I set the PATH variable on my Mac so the Hombrew-installed tools are found?

Presumably the author of the Postgres+Postgis tutorial you're referring to has changed its PATH long ago and forgot to mention it in his text.

Once done, the command which createdb should return /usr/local/bin/psql which is the homebrew version instead of the initial /usr/bin/psql which is the Apple version.

Community
  • 1
  • 1
Daniel Vérité
  • 58,074
  • 15
  • 129
  • 156
  • Thanks for your thoughts @Daniel. I installed PostGREs using homebrew, and followed the [instructions here](http://pageworthy.com/blog/postgis-on-mountain-lion/). Do you have any ideas of how to fix this so that I can use my PostGREs database in a django project? Thanks for your ideas! – Nick B Jul 01 '13 at 19:49
  • Thanks @Daniel. I followed the instructions from the linked post and put `usr/local/bin` above `usr/bin`, but when I try `which createdb` it outputs `/usr/bin/createdb`, not what you listed above. Am I missing something to properly link the path? Thanks for your ideas! – Nick B Jul 01 '13 at 21:43
  • @NickB: you mean editing `/etc/paths`? And did you start a new session in a new terminal? – Daniel Vérité Jul 02 '13 at 17:31
  • Thanks @Daniel. Yes, I edited `/etc/paths` as suggested in the accepted answer in the post that you linked. I also started a new terminal session and `which createdb` now returns `/usr/local/bin/createdb`.. Any ideas as to how to address this issue? Thanks for your thoughts! – Nick B Jul 02 '13 at 20:25
  • @NickB: so now back to the start of the question, you may retry `createdb geo` and hopefully it won't fail to connect to postgresql. – Daniel Vérité Jul 02 '13 at 20:45
  • There is still a problem with my Postgres, unfortunately. `createdb geo` returns `createdb: could not connect to database template1: FATAL: could not open relation mapping file "global/pg_filenode.map": No such file or directory`. I wish I knew how to address this, but thanks for any suggestions.. – Nick B Jul 03 '13 at 17:27
  • That's unusual. You may look at: http://stackoverflow.com/questions/7445935 for answers to a similar question – Daniel Vérité Jul 03 '13 at 21:27