I get this error when I haven't correctly shut down my Rails server or PostgreSQL database. Your mileage may vary on the solution. I always find myself coming back to this StackOverflow post and all I really have to do is run:
sudo rm /usr/local/var/postgres/postmaster.pid brew services restart postgresql
And that does the trick! Good luck out there.