Mountain Lion Postgres could not connect

我只是一个虾纸丫 提交于 2019-11-29 09:30:21

I just had the same problem. Personally I just reinstalled from the Postgres installer (postgresql-9.1.3-1-osx.dmg in my case), rebooted my mac and all is fine again. p.s. re-installing didn't zap my databases :)

Check which psql you're using. I had the same problem while using the Postgres.app server from Heroku and found that I was using Apple's /usr/bin/psql client based on my $PATH setting. Either set your $PATH to use your Postgres library or use the full path to your installed psql.

The default Unix domain socket path is hardcoded in libpq. What may have happen is that before the upgrade, your application used the libpq library installed by the Postgres one-click installer, while after the upgrade a different version of this library gets picked up.

To work around the problem, from a programmer's point of view, you could specify the socket directory instead of relying on the default. To locate the correct directory if you don't know it already, connect to any database as a superuser (generally postgres) and issue in SQL:

SHOW unix_socket_directory;

Then change or reconfigure your app with the path obtained in the host field of the connect call (e.g. in a connect string: host=/path/to/socket dbname=d user=u). Libpq will recognize it as a unix socket directory because it starts with a slash, as opposed to a hostname or IP address.

Somehow I totally forgot that this socket file will be hidden because of the dot. Make sure you use ls -A /tmp/.s.PGSQL.5432 if you are checking to see if the socket is actually there.

My postgres app started accepting a connection again from psql after I did the following. I think it had something to do with step 3.

  1. Exit the postgres app.
  2. In terminal type postgres -D ~/Library/Application\ Support/Postgres/var. This is the data directory if you are using the postgres app. If you are not using the postgres app you need to find out what the data directory really is.
  3. I got a prompt from OS X asking if I want to allow incoming traffic. I clicked yes.
  4. In a different terminal tab type psql. You should connect successfully.
  5. Type \q to exit psql.
  6. Back on the tab running postgres, type ctrl c to stop postgres.
  7. Start the postgres app. psql should work.

I've solved this problem by uninstalling and re-installing it

The problem is that mountain lion comes with it's own psql client (/usr/bin/psql) which apparently tries to connect postgres by searching the local socket file in a different location than the one from your installer. You could either change your PATH variable to include first your postgres bin folder or replace the default /usr/bin/psql with the one on your installation.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!