Search code examples
postgresqlmacos

psql: error: connection to server on socket "/tmp/.s.PGSQL.5432" failed: No such file or directory


Not really sure what caused this but most likely exiting the terminal while my rails server which was connected to PostgreSQL database was closed (not a good practice I know but lesson learned!)

I've already tried the following:

  1. Rebooting my machine (using MBA M1 2020)
  2. Restarting PostgreSQL using homebrew brew services restart postgresql
  3. Re-installing PostgreSQL using Homebrew
  4. Updating PostgreSQL using Homebrew
  5. I also tried following this link but when I run cd Library/Application\ Support/Postgres terminal tells me Postgres folder doesn't exist, so I'm kind of lost already. Although I have a feeling that deleting postmaster.pid would really fix my issue. Any help would be appreciated!

Solution

  • Below was the workaround if you prefer to stay in v13.3, if you are on 14.2 you can simply change the port postgresql is listening to. Read their docs about it here.

    Note that this solution works for the setup that I have (take a look at the original post for my setup details ie. OS & how what I'd use to install Postgres)

    1. open your postgresql.conf file in the following directory and use any text editor you want. below uses vscode/vim.

    vscode

    sudo code . /usr/local/var/postgres/postgresql.conf
    

    vim

    sudo vi /usr/local/var/postgres/postgresql.conf
    
    1. change port to 5432 and restart your machine.

    v13.3 solution

    it appears that the upgrade really messed up my postgres since per Nagev's answer it's listening to port 5433 instead of 5432. I downgraded to v13.3 to fix this issue.

    brew uninstall postgresql
    brew install postgresql@13
    brew services start postgresql@13
    brew link postgresql@13 --force