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.

Recently updated my machine from Mac OS X Lion (10.7.4) to Mountain Lion (10.8) and I think it borked my PostgreSQL installation. It was installed originally via Homebrew. I'm not a DBA, but hoping someone can tell me how to troubleshoot this.

I am unable to connect (but was able to before pre-Mountain Lion):

$ psql -U rails -d myapp_development
psql: 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"?

But Postgres is still clearly running:

$ ps aux | grep postgres
meltemi          2010   0.0  0.0  2444124   5292   ??  Ss   Wed01PM   0:00.02 postgres: rails myapp_development [local] idle    
meltemi           562   0.0  0.0  2439312    592   ??  Ss   Wed12PM   0:02.28 postgres: stats collector process       
meltemi           561   0.0  0.0  2443228   1832   ??  Ss   Wed12PM   0:01.57 postgres: autovacuum launcher process       
meltemi           560   0.0  0.0  2443096    596   ??  Ss   Wed12PM   0:02.89 postgres: wal writer process       
meltemi           559   0.0  0.0  2443096   1072   ??  Ss   Wed12PM   0:04.01 postgres: writer process       
meltemi           466   0.0  0.0  2443096   3728   ??  S    Wed12PM   0:00.85 /usr/local/bin/postgres -D /usr/local/varpostgres -r /usr/local/var/postgres/server.log

And it's responding to queries (both to a test db and the development db) from a local Rails app

  User Load (0.2ms)  SELECT "users".* FROM "users" 
  Rendered users/index.html.haml within layouts/application (1.3ms)

There appears to be no /var/pgsql_socket/ directory, let alone the /var/pgsql_socket/.s.PGSQL.5432 socket file mentioned above!?! Maybe the install of Mountain Lion wiped that out?

$ ls -l /var/ | grep pg
drwxr-x---   2 _postgres  _postgres    68 Jun 20 16:39 pgsql_socket_alt

How can I troubleshoot this?

share|improve this question
    
Not a postgres admin, but a missing socket file sounds about right. Create the /var/pgsql_socket directory (with your user having write permissions) and restart the server. See if that fixes it –  Derek Downey Jul 26 '12 at 20:54
    
Related question on SO. Seems like Apple didn't do a great job with the upgrade. –  Erwin Brandstetter Jul 26 '12 at 20:57
    
is there any mention of a socket file being created in the log file /usr/local/var/postgres/server.log ? –  Phil Jul 26 '12 at 21:55
    
@ErwinBrandstetter How do you expect Apple to do a "good job" of upgrading manually installed 3rd party *nix apps? –  Phil Jul 26 '12 at 21:55
    
@Phil- no mention. I'm starting to think this might be a path variable problem. I think my $PATH got changed with the upgrade /usr/bin is ahead of /usr/local/bin and I think Mountain Lion may come with PostgreSQL pre-installed!?! Investigating... –  Meltemi Jul 26 '12 at 22:00
add comment

9 Answers

up vote 19 down vote accepted

I found that I had an extremely similar problem, namely that postgres was opening a socket in /var/pgsql_socket_alt where none of my software expects to look, but the solution to my problem was not only a problem with my $PATH.

I had to create the directory /var/pgsql_socket, chown it to myself, and set unix_socket_directory in postgresql.conf (located in /usr/local/var/postgres) to that directory, then use the pg_ctl binary in /usr/local/bin to start the right postgres server successfully (which is where $PATH comes in – make sure which pg_ctl resolves to /usr/local/bin/pg_ctl, or just always call it explicitly).

This might help other users who find this question via the /var/pgsql_socket_alt mention.

share|improve this answer
    
Interesting. Are you also on Mountain Lion? Did you install PostgreSQL with Homebrew? If so, wonder if anyone else can verify this solution as opposed to changing my $PATH as I have done. –  Meltemi Jul 26 '12 at 23:42
    
Yes, yes, and I hope so! –  thure Jul 27 '12 at 2:47
    
@wolftron your solution was bang-on for me (Mountain Lion, homebrew/postgres, /var/pgsql_socket_alt, the whole nine). Is this a new issue on Mountain Lion with homebrew? I'll open a ticket with them if you think so. –  user10458 Jul 27 '12 at 17:21
    
Looks like we've got verification from @Jamie. –  thure Jul 30 '12 at 3:24
    
Thanks man! I was starting to get pretty hoples...... –  Alex Zak Oct 4 '12 at 3:47
show 2 more comments

A plausible and typical explanation would be that the psql that comes with homebrew is in /usr/local/bin/psql which is different from the one that would be in your $PATH, like /usr/bin/psql (bundled with OS X). You may want to try with the full path:

$ /usr/local/bin/psql -U rails -d myapp_development

Also, there's something rather unusual in the ps output of your question: the postgres server is running under a meltemi Unix user, whereas generally, the dedicated postgres Unix user is used for that.

share|improve this answer
    
Also, _postgres (with underscore) for user / group are unknown to me. Is that an artifact or expected? –  Erwin Brandstetter Jul 26 '12 at 22:10
    
Yes, it appears to be a $PATH problem as you stated. Things work as before when I use /usr/local/bin/psql to access the database. Either Lion didn't have a system PostgreSQL or my $PATH was set up differently. It's been a year since I last muddled with this so I can't remember exactly. As for the Unix user...with a Homebrew install of PostgreSQL the server is launched by launchd and the user is set to the local user who installed it, as a default. Things are set up differently on Mac OS X Server which starts up PostgreSQL automatically under postgres. –  Meltemi Jul 26 '12 at 22:10
    
Excellent Answer –  Krishnaprasad Varma May 9 '13 at 9:31
add comment

Late, but I found this helpful: http://tammersaleh.com/posts/installing-postgresql-for-rails-3-1-on-lion

That was for Lion, but I was having same issues as the one in this thread after upgrading from 10.6.8 to Mountain Lion and having installed postgresql via homebrew prior while on 10.6.8. I also had the mysterious /var/pgsql_socket_alt folder post-upgrade, but I just removed it and created /var/pgsql_socket as suggested by @wolftron. However, that wasn't the final solution.

If I left 'unix_socket_directory' blank/commented out in postgresql.conf, any projects existing prior to the upgrade would complain that the socket in '/var/pgsql_socket' was missing. But if I changed conf and hardcoded 'var/pgsql_socket', any new projects would complain that the socket in '/tmp' was missing. Very frustrating...until I re-installed pg gem in an pre-10.8 project (gem uninstall pg && gem install pg) and left unix_socket_directory commented out in conf file. After a quick pg_ctl to restart the server, both new and old projects worked. My pgsql socket lives in /tmp now, fwiw.

Sidenote: if you are using activerecord-postgresql-adapter gem, uninstall it first, then re-install pg, then install activerecord-postgresql-adapter again.

share|improve this answer
add comment

Try:

psql -U rails -d myapp_development -h localhost

or

psql -U rails -d myapp_development -h 127.0.0.1
share|improve this answer
add comment

I've only just signed up to the dba SE, so don't seem to be able to comment on the relevant post (what a crock!).

However, I was confident that I was in the same boat as @thure. I'd made sure /usr/local/bin was earlier in my PATH than /usr/bin, had checked which binaries the shell had hashed with which and type, etc.

I saw the same symptoms as @thure. Then I had an epiphany; I realised I'd rebuilt the pg gem (I'm using Ruby) in a shell whose PATH had been adversely affected by Mac's path_helper (which is run from /etc/profile and puts /usr/bin before /usr/local/bin).

I uninstalled pg and reinstalled it in a shell whose PATH was correct. All of a sudden I could connect!

So make sure you recompile your language bindings people, and let them find the correct copy of (presumably) pg_config.

share|improve this answer
add comment

I found this answer: http://stackoverflow.com/questions/10763143/in-rails-couldnt-create-database-for-adapter-postgresql And, as simple as it was, it worked for me... ran a $bundle update and it started working again.

share|improve this answer
add comment

I found that symlinking the actual location to the expected location worked just fine:

sudo ln -s /var/pgsql_socket_alt /var/pgsql_socket

along the lines of the accepted answer by @thure but simpler.

share|improve this answer
add comment

Hello world :)
The best but strange way for me was to do next things.

1) Download postgres93.app or other version. Add this app into /Applications/ folder.

2) Add a row (command) into the file .bash_profile (which is in my home directory):

export PATH=/Applications/Postgres93.app/Contents/MacOS/bin/:$PATH
It's a PATH to psql from Postgres93.app. The row (command) runs every time console is started.

3) Launch Postgres93.app from /Applications/ folder. It starts a local server (port is "5432" and host is "localhost").

4) After all of this manipulations I was glad to run $ createuser -SRDP user_name and other commands and to see that it worked! Postgres93.app can be made to run every time your system starts.

5) Also if you wanna see your databases graphically you should install PG Commander.app. It's good way to see your postgres DB as pretty data-tables

Of, course, it's helpful only for local server. I will be glad if this instructions help others who has faced with this problem.

share|improve this answer
add comment

I can't quickly find the link where I found this nugget, but it worked for me.

export PGHOST=localhost

Oh, here's the link. http://stackoverflow.com/questions/13868730/socket-file-var-pgsql-socket-s-pgsql-5432-missing-in-mountain-lion-os-x-ser

share|improve this answer
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.