Error: connection to server on socket "/tmp/.s.PGSQL.5432" failed

Viewed 3661

I'm kind of hitting my head against the wall trying to figure this out...

When I run psql in my terminal, it gives me:

psql: error: connection to server on socket "/tmp/.s.PGSQL.5432" failed: Connection refused
        Is the server running locally and accepting connections on that socket?

I see the service running with brew services, but another one appears because I tried to upgrade PSQL as well, but that might've messed it up even more.

postgresql        started fella /Users/fella/Library/LaunchAgents/homebrew.mxcl.postgresql.plist
postgresql@13     stopped 

I've tried:

  • pg_ctl -D /usr/local/var/postgres stop -s -m fast
  • output >> pg_ctl: PID file "/usr/local/var/postgres/postmaster.pid" does not exist Is server running?
  • pg_ctl -D /usr/local/var/postgres -l /usr/local/var/postgres/server.log start
  • output >> waiting for server to start.... stopped waiting pg_ctl: could not start server Examine the log output.

I tried:

  • brew update
  • brew upgrade

which went without any errors, but I still get the same error when I run psql

I just ran

āžœ ~ code /usr/local/opt/postgresql/homebrew.mxcl.postgresql.plist

āžœ ~ tail -n 100 /usr/local/var/log/postgres.log

And found a whole bunch of errors there. Lots of this happening:

incompatible with server 2021-10-24 18:04:41.848 MDT [1038] DETAIL: 
The data directory was initialized by PostgreSQL version 13, which is
not compatible with this version 14.0.

But this was the most recent one:

2021-10-24 18:09:45.680 MDT [4129] LOG: starting PostgreSQL 14.0 on x86_64-apple-darwin20.6.0, compiled by Apple clang version 13.0.0

(clang-1300.0.29.3), 64-bit 2021-10-24 18:09:45.682 MDT [4129] LOG: listening on IPv6 address "::1", port 5432 2021-10-24 18:09:45.682 MDT

[4129] LOG: listening on IPv4 address "127.0.0.1", port 5432

2021-10-24 18:09:45.763 MDT [4129] LOG: listening on Unix socket

"/tmp/.s.PGSQL.5432" 2021-10-24 18:09:45.814 MDT [4129] LOG: could not open directory "pg_tblspc": No such file or directory 2021-10-24

18:09:45.815 MDT [4129] LOG: could not open configuration file

"/usr/local/var/postgres/pg_hba.conf": No such file or directory

2021-10-24 18:09:45.816 MDT [4129] FATAL: could not load pg_hba.conf

2021-10-24 18:09:45.818 MDT [4129] LOG: database system is shut down

postgres: could not access the server configuration file

"/usr/local/var/postgres/postgresql.conf": No such file or directory

postgres: could not access the server configuration file

"/usr/local/var/postgres/postgresql.conf": No such file or directory

postgres: could not access the server configuration file

"/usr/local/var/postgres/postgresql.conf": No such file or directory

1 Answers

I worked with one of the instructors at my bootcamp to resolve this - we found that I had two instance of PSQL on my PC. We dug into the root folder and removed the older version 13 and re-ran the installation which solved all my issues.

Related