I restarted my MacBook tonight and when I attempted to start up my Rails development environment I encountered the following error:
connection to server at "localhost" (::1), port 5432 failed: Connection refused Is the server running on that host and accepting TCP/IP connections?
The problem is due to PostgreSQL not properly closing before the machine was restarted and then a straggling
postmaster.pid file is left, making the machine think that the port is in use.
Remove the file on an M1 Mac (or M2... any Apple Silicon) with the following command:
Then restart PostgreSQL (this only works if PostgreSQL was installed using Homebrew).
brew services restart postgresql
By now this has happened enough times after restarting my Mac that I'm confident that I can remove the file, but if you're unsure it's always good to double check