How to fix “Port 5432 is already in use” in MacOS

Bright Atsighi
2 min readFeb 28, 2024

--

PostgreSQL logo

INTRO

One of the craziest things that can happen to you while trying to get up and running, fixing your bug or writing your code peacefully is the error below:

Port 5432 is already in use error.

OPTIONS

I know it drives me crazy as a backend developer, so I decided to poke it a bit and guess what, I found a crazy hack that doesn’t require

  • Rebooting your machine
  • Running some terminal commands — [most of which you don’t understand, I know I never did! Be honest! 😸]

On a lighter mode, there was this one time I ran one of those cryptic commands and was unaware that the Mac User, my device was the one using the postgres port-5432 and it was like my machine was going to crash. 😨

SOLUTION

  1. Change the port: Port 5432 is the default port for PostgreSQL but like any other server you spin up in your machine, it could also run on any port. Change it to another port, in the screen below, I changed mine to Port 5433.
Changed PG DB Port to 5433

2. Update your project port.

.env file

DATABASE_URL="postgresql://db_user:db_password@localhost:5433/your_db?schema=public"

3. Restart your server.

Enjoy hacking 🎉🎉 🍺 🍵

--

--

Bright Atsighi

Full Stack Developer | MERN Stack | Backend | NestJS | NextJS | PostgreSQL | TailwindCSS | Ruby on Rails API