Error del servidor de Postgres -> PGError: no se pudo conectar al servidor

I get the error below when trying to start my rails app on the localhost:

PGError (could not connect to server: No such file or directory Is the server running locally and accepting connections on Unix domain socket "/tmp/.s.PGSQL.5432"?

From what I have read it sounds like this is most likely a problem in connecting to the Postgres server, and may indicate that it is not started?

It all started when I was attempting my first (yay noobs!) merge using git. There was a conflict (having to do with the Rubymine workspace.xml file), and I started to open up a conflict resolution program. It then seemed that there was really no need to track workspace.xml at all and so I quit from the resolution program, intending to run "git rm --cached" on the file. I think in quitting the program something went foul, and I ended up restarting, before untracking the file, and then completing the merge. Further evidence that something was gummed up is that my terminal shell didn't open up correctly until I restarted the machine.

Now, as far as I can tell, everything in the merge went fine (there were trivial differences in the two branches anyway), but for the life of me I can't seem to get rid of this PGError. If it is as simple as starting the server, then I'd love help on how to do that.

(other context: OSx, rails 3, posgresql83 installed via macports, pg gem).

EDIT - I have been trying to start up the server, but am not succeeding. e.g., I tried:

pg_ctl start -D /opt/local/var/db/postgresql83/defaultdb

This seems to be the right path for the data (it finds the postgresql.conf file) but the response I get is "cannot execute binary file."

preguntado el 09 de enero de 11 a las 11:01

3 Respuestas

Trata sudo port load postgresql83-server - this should work with the latest 8.3 port from macports.

Si esto no funciona, intente sudo port selfupdate; sudo port upgrade outdated y luego inténtalo de nuevo

Note - this may take absolutely ages.

Respondido el 09 de enero de 11 a las 15:01

I tried the first, command, but it replied with "aleady loaded", tried the other two and then the first, and got the same "already loaded" response. (though there did seem to be a slight upgrade in postgresql83. still getting the same error. have I really hosed the server? or just this db? can I just create a new one? - Phil_Ken_Sebben

Interesting ... so it is loaded definitely ... try sudo port unload postgresql83-server THEN load it, it might work, might not. - Omar Qureshi

you might be able to kill the db and start again - not sure how much of a pain that will be. - Omar Qureshi

sudo port unload postgresql83-server produces so response (so it works?), and then loading also produces no response (so i guess that worked too?) but then I still get the same error, even after restarting the machine. I don't understand what could have changed that would have ruined the startup process. - Phil_Ken_Sebben

and may indicate that it is not started?

Yes, sounds like the server is not running on your local machine.

See the description of this error in the PostgreSQL manual:

Respondido el 09 de enero de 11 a las 14:01

Yes, I've been reading that, but nothing I do seems to start it up. e.g I've tried running pg_ctl on what I think is the right data folder (it's very hard to find) and I get this response : /opt/local/lib/postgresql83/bin/pg_ctl: /opt/local/lib/postgresql83/bin/pg_ctl: cannot execute binary file - Phil_Ken_Sebben

That error seems to indicate that either the binary is not installed properly or you do not have the necessary privileges to start the server - un caballo sin nombre

I don't think it's the priveliges, since I do need to enter in a password and it complains otherwise. Everything was working fine for a long time before the event I mentioned, so perhaps I really scrambled it? - Phil_Ken_Sebben

Are you using the "postgres" user to start the server? - un caballo sin nombre

I've tried both using the "postgres" user and a user I created a while back with my mac username, but neither seems to work. - Phil_Ken_Sebben

To start the server, try something along the following lines (adjust for pgsql version # and logfile):

sudo su postgres -c '/opt/local/lib/postgresql84/bin/pg_ctl -D /opt/local/var/db/postgresql8/defaultdb -l /opt/local/var/log/postgresql84/postgres.log start'

To stop the server,

sudo su postgres -c '/opt/local/lib/postgresql84/bin/pg_ctl -D /opt/local/var/db/postgresql84/defaultdb stop'

Respondido el 17 de enero de 12 a las 15:01

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.