How to get postgres to start on big sur?

Viewed 2540

I'm attempting to launch a rails server on big sur (M1 chip) and postgres is giving the following error:

ActiveRecord::ConnectionNotEstablished (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"?
):

I've seen and tried several fixes but none have worked, including the following:

  • Reinstalling postgres via homebrew.
  • Reinstalling the pg gem.
  • brew services restart.
  • Trying to delete a postmaster.pid file (none exist). This directory: "/usr/local/var/postgres/postmaster.pid" does not exist on my machine.

My postgres.log file contains the following line repeating:

could not open directory "pg_notify": No such file or directory LOG: database system is shut down

2 Answers

While Genetic's answer works, a quicker solution would be to delete the partially created database (assuming you have just installed postgres and there's no data to be lost) and then run initdb as listed in brew info postgresql to recreate the database:

brew services stop postgresql
rm -rf "$(brew --prefix)/var/postgres"
initdb --locale=C -E UTF-8 "$(brew --prefix)/var/postgres"
brew services start postgresql

The original error on the console didn't change until I entered the following command:

brew services restart -vvv postgresql

After doing this, the errors updated. It then displayed the other directories and sub-directories that were missing. Once I added everything, all was fine.

Related