2

I've just got a new Macbook, and installed it from a backup of my old one.

Now, Homebrew thinks that Postgres is running:

% brew services restart postgresql
Stopping `postgresql`... (might take a while)
==> Successfully stopped `postgresql` (label: homebrew.mxcl.postgresql)
==> Successfully started `postgresql` (label: homebrew.mxcl.postgresql)

But I can't connect to any of my databases:

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

And postgres isn't showing up in the list of running processes:

% ps -ef | grep postgres          
501 88781 87701   0  5:34pm ttys000    0:00.00 grep postgres

What should I do? I've looked for postmaster.pid in /usr/local/var/postgres/ - it isn't there.

Richard
  • 62,943
  • 126
  • 334
  • 542

1 Answers1

1

If the brew service started up, but postgres failed to start within that service, you'll probably need to check the postgres log to see exactly what's wrong. For homebrew, that log is typically located at /usr/local/var/log/postgres.log.

Just a wild guess, but did you also upgrade postgres after the restore from backup? If so, you may need to run

brew postgresql-upgrade-database

to upgrade your data directory (see Postgres - FATAL: database files are incompatible with server). Note that you'll need plenty of free disk space for that command to succeed or it may fail with unintuitive errors.

You should be able to manually start up postgres by just running

postgres

or

postgres &

but you'll need to do that ever time you restart your computer.

If that command fails, you should have the reason why right there in your terminal without having to hunt for logs.

Troy
  • 21,172
  • 20
  • 74
  • 103
  • This is super useful, thanks! I did `postgres -D /usr/local/var/postgres &` and then I got useful debugging output without having to look at the logs. – Richard Jan 23 '21 at 17:53