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. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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

12 Answers 12

up vote 25 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

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

Late, but I found this helpful:

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 hard-coded 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


psql -U rails -d myapp_development -h localhost


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

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

I found this answer: And, as simple as it was, it worked for me... ran a $bundle update and it started working again.

share|improve this answer

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

I don't know of any config file for the psql client. However psql does respect a number of environment variables that correlate to command line options.

So to have the psql automatically use the socket of your choice you can set the PGHOST variable to the directory containing the socket. i.e.

psql -d mydatabsase
share|improve this answer

Here it is, 2016, El Capitan is out there, and Apple keeps changing things up. Postgres is installed as part of the OS, and the postgres config file sets the unix_socket_directories property in postgresql.conf to /tmp. The socket is in /tmp/.s.PGSQL.5432. I was able to get around the problem by executing the following:

sudo ln -s /tmp /var/pgsql_socket

Hope this helps someone.

share|improve this answer

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

1) Download 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/$PATH
It's a PATH to psql from The row (command) runs every time console is started.

3) Launch 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! can be made to run every time your system starts.

5) Also if you wanna see your databases graphically you should install PG 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

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.

share|improve this answer

I got this same error from trying to run psql on the command line. It turned out that my solution was far simpler. I had mis-configured the listening port in the config file: /etc/postgresql/9.4/main/postgres.conf. I had changed the port from port = 5432 to port = 5433. When I changed it back to 5432, it worked as expected.

To test if you have done something similar, you can run $ psql -p5433 There are a number of useful options like this for the psql command that you can find here: so that you can test out your OWN particular misconfiguration. Of course, you can simply remove your last set of config changes from the *.conf files, too, to test if those are the source of your problem. I think it is certainly worth checking out before you muck about with file permissions and ownerships. (Just don't forget to /etc/init.d/postgresql restart )

What I could NOT find was the config file that sets the default values for the psql CLI command. Can someone comment with that, please?

For me I always go back to my first principle of programming: "I am usually the source of any given error!"

share|improve this answer

Your Answer


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.