How to fix “Port 5432 is already in use” in MacOS
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:
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
- 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.
2. Update your project port.
DATABASE_URL="postgresql://db_user:db_password@localhost:5433/your_db?schema=public"
3. Restart your server.
Enjoy hacking 🎉🎉 🍺 🍵