0

I just updated my gems. And now I have problems connecting to my postgresql database. I get the error:

PGError

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 uninstalling the gem and reinstalling, I also tried to change the paths file and put '/usr/local/bin/' on top. I tried some of the things from post:

Repairing Postgresql after upgrading to OSX 10.7 Lion

This app worked fine before updating my gems, other apps still connect just fine, to the same server. I have the same settings in my database.yml file.. what could be wrong?

Community
  • 1
  • 1
jakobk
  • 1,120
  • 1
  • 14
  • 26
  • Finally, I found the related topic. http://stackoverflow.com/questions/7369164/postgresql-why-do-i-have-to-specify-h-localhost-when-running-psql/7377682#7377682 – wildplasser Feb 19 '12 at 18:38

1 Answers1

1

The error comes from the PostgreSQL server and I have seen it many times. It tells you that you are trying to connect via Unix domain socket (and not via TCP/IP!) to a server that is running locally and listening at port 5432. But no server can be found that would accept connections like that.

You did not mention where the PostgreSQL server resides - I assume you actually mean to connect to a database server on your local machine.

Check your setup, especially your pg_hba.conf file. You need a line like:

local      mydb    myuser     md5

or

local      all      all       peer

or some other connection method that includes your user and database.

These would not help in your case:

host ...

or

hostssl ...

They concern TCP/IP connections, not local connections via UNIX domain socket. When you connect to localhost you actually use TCP/IP via local loop and these settings apply.

Remember to reload after you edit pg_hba.conf. I quote the manual at the linked site:

If you edit the file on an active system, you will need to signal the postmaster (using pg_ctl reload or kill -HUP) to make it re-read the file.

Erwin Brandstetter
  • 605,456
  • 145
  • 1,078
  • 1,228
  • Erwin, IMHO this is again a topic about the unix-domain socket being in another place than where it is expected. The previous ones were all (recently upgraded) OSX installations. – wildplasser Feb 18 '12 at 18:50
  • @wildplasser: That may be. Or maybe jakobk confuses `local` and `localhost` like we had [here](http://stackoverflow.com/a/8976814/939860), or he confuses the port like we had [here](http://stackoverflow.com/q/7861867/939860). – Erwin Brandstetter Feb 18 '12 at 19:03
  • Hi Erwin, thanks for your solution.. I could'nt locate the pg_hba.conf file, where is it suppose to be ? I have one project that works, the database.yml file is the same(except for the database). One works fine, the other one gives me the PGerror. So it must be in the configuration of that project ? – jakobk Feb 19 '12 at 15:28
  • I spent too many hours finding the error... so I reverted to an earlier version.. thanks for your help – jakobk Feb 19 '12 at 15:37