I just upgraded my MacMini Server from Lion Server to Mountain Lion using OS X Server. I am having the same problem with PostgreSQL that I did last year when I first installed Lion Server.
When I try to do any kind of PostgreSQL terminal command I get the following notorious error message that many have gotten over the years:
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"?
I was attempting to change the password for _postgres when I got the error. I tried several commands but got the same error. I just rebooted my server but no luck. I logged in as root to look at /var/pgsql_socket and the folder is empty. Folder /var/pgsql_socket_alt is also empty.
I have checked online about this. However just about all of the solutions I have read, including on Stack Overflow, suggest a removal and reinstall of PostgreSQL. I do not know but this does not seem like a plausible option because several options on the Server App use PostgreSQL. I contacted Apple Enterprise Support (no agreement) and I was told that my issue would have to be solved by the developers which would cost $695.
I have a website that is down right now because I cannot rebuild it. I don't know where to turn for help with this at this point. I will continue looking online to see if I can find something. However I hope that someone can give me an answer quick so I can rebuild my database.
Update: 12/13/2012 15:33 GMT-6
Here is my output for ps auwx|grep postg:
_postgres 28123 0.0 0.1 2479696 7724 ?? Ss 3:01PM 0:00.04 /Applications/Server.app/Contents/ServerRoot/usr/bin/postgres_real -D /Library/Server/PostgreSQL For Server Services/Data -c listen_addresses= -c log_connections=on -c log_directory=/Library/Logs/PostgreSQL -c log_filename=PostgreSQL_Server_Services.log -c log_line_prefix=%t -c log_lock_waits=on -c log_statement=ddl -c logging_collector=on -c unix_socket_directory=/Library/Server/PostgreSQL For Server Services/Socket -c unix_socket_group=_postgres -c unix_socket_permissions=0770 server1 28216 0.0 0.0 2432768 620 s000 R+ 3:02PM 0:00.00 grep postg _postgres 28138 0.0 0.0 2439388 752 ?? Ss 3:01PM 0:00.01 postgres: stats collector process _postgres 28137 0.0 0.0 2479828 1968 ?? Ss 3:01PM 0:00.00 postgres: autovacuum launcher process _postgres 28136 0.0 0.0 2479696 544 ?? Ss 3:01PM 0:00.00 postgres: wal writer process _postgres 28135 0.0 0.0 2479696 732 ?? Ss 3:01PM 0:00.01 postgres: writer process _postgres 28134 0.0 0.0 2479696 592 ?? Ss 3:01PM 0:00.00 postgres: checkpointer process _postgres 28131 0.0 0.0 2439388 368 ?? Ss 3:01PM 0:00.00 postgres: logger process
Update: 12/13/2012 18:10 GMT-6
After intense web searching this video was found. I was able to get PostgreSQL working and remove the error. I am able to connect using pgadmin and phppgadmin. I was about to go back to Lion Server because of sheer frustration. Now I will not have to.
http://www.youtube.com/watch?v=y1c7WFMMkZ4
When connecting to Postgres you might see this error: psql: could not connect to server: No such file or directory Is the server running locally and accepting connections on Unix domain socket <some socket> . This happens most often when Postgres' server daemon process is not running.
“Could not connect to server: Connection refused” To be sure that PostgreSQL is running, you can also restart it with systemctl restart postgresql. If this does not fix the problem, the most likely cause of this error is that PostgreSQL is not configured to allow TCP/IP connections.
I was able to add the following to my .bash_profile to prevent the error:
export PGHOST=localhost
This works because:
If you omit the host name, psql will connect via a Unix-domain socket to a server on the local host, or via TCP/IP to localhost on machines that don't have Unix-domain sockets.
Your OS supports Unix domain sockets, but PostgreSQL's Unix socket that psql
needs either doesn't exist or is in a different location than it expects.
Specifying a hostname explicitly as localhost
forces psql
to use TCP/IP. Setting an environment variable PGHOST
is one of the ways to achieve that. It's documented in psql's manual.
Try paste in console this:
$ mkdir /var/pgsql_socket/ $ ln -s /private/tmp/.s.PGSQL.5432 /var/pgsql_socket/
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With