Blog

Thoughts from my daily grind

PostgreSQL - Service Error - Port 5432 Connection Refused

Posted by Ziyan Junaideen |Published: 29 January 2022 |Category: Ruby on Rails
PG Error |

PostgreSQL is a popular ACID-compliant database engine. It has been my go-to database engine for nearly eight years. I have always used PostgreSQL in a Linux environment, but a month ago, I installed PostgreSQL on macOS through Homebrew. This was to avoid needing to boot multiple Vagrant virtual machines.

Since I migrated, I have noticed that Homebrew failed to start the PostgreSQL service many times.

ActiveRecord::ConnectionNotEstablished

connection to server at "localhost" (::1), port 5432 failed: Connection refused 
Is the server running on that host and accepting TCP/IP connections?
connection to server at "localhost" (127.0.0.1), port 5432 failed: Connection refused
Is the server running on that host and accepting TCP/IP connections?

This might be because the service does not shut down properly when the computer shuts down, and a PID file is not being removed. Removing this file is all you need to do.

rm -rf /usr/local/var/postgres/postmaster.pid
Tags
About the Author

Ziyan Junaideen -

Ziyan is an expert Ruby on Rails web developer with 8 years of experience specializing in SaaS applications. He spends his free time he writes blogs, drawing on his iPad, shoots photos.

Comments