Using Homebrew PostgreSQL can't connect to server

My environment

macOS Mojave 10.14.6 Homebrew 2.1.11 PostgreSQL 11.5

I typed brew command and checked PostgreSQL server is running.

brew services start postgresql

But I can't connect PostgreSQL server like this command. And it displayed these errors.

psql postgres

psql: 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"?

How can I solve this problem?

I've already tried to restart PostgreSQL server

brew services restart postgresql

And also tried this answer, but this file did not exist in the directory.

1 Answer

I solved this problem as below.

First, run the database.

postgres -D /usr/local/var/postgres
2019-09-01 03:27:51.272 JST [5002] FATAL: database files are incompatible with server
2019-09-01 03:27:51.272 JST [5002] DETAIL: The data directory was initialized by PostgreSQL version 9.6, which is not compatible with this version 11.5.

It displayed incompatible version errors.

Second, remove the old database.

rm -rf /usr/local/var/postgres 

Third, initialize new one.

initdb /usr/local/var/postgres -E utf8

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

You Might Also Like