DEV Community

balt1794
balt1794

Posted on

PostgreSQL - port 5432 already in use

New videos very Sunday and Friday.

For more content, visit:

baltlogs

When installing your Postgres database for the first time, one of the problems that might arise is that two different versions of the PostgreSQL server are running at the same time. When this happens, you will get a message similar to the screenshot below.

Screen-Shot-2021-02-10-at-1.29.28-PM

In my case, I downloaded PostgreSQL, but apparently I already had a different version running on my computer and it was using the port 5432. Postgres is known for using port 5432 as a default (this can be changed). The problem described can also be caused by other applications using port 5432.

To check what is running on port 5432, issue the following command on your terminal.



$ sudo lsof -i :5432


Enter fullscreen mode Exit fullscreen mode

When issuing the command above, you will prompted for the computer's password. After entering your password, you should get an output of what's currently running on port 5432.

Screen-Shot-2021-02-11-at-11.07.33-AM

You might get a different output depending on what application is using the port. In my case, I had a different version of the PostgreSQL server running on my Mac, that was interfering with the Postgres.app. If you have the same problem, to kill all PostgreSQL processes, issue the following command.



$ sudo pkill -u postgres


Enter fullscreen mode Exit fullscreen mode

Usually Postgres is the only app interested in using port 5432, but if after issuing the first command to see what is running on port 5432, you find out that there is an application other than PostgreSQL running on port 5432, try to check the activity monitor and see what app might be interfering with your PostgreSQL server and shut it down from there.

If you find this content useful, please share with others.

Other ways to support:

Django 3…2…1…Takeoff! Kindle

Django 3…2…1…Takeoff! Paperback

Top comments (13)

Collapse
 
henleyridgemc profile image
Henley Ridge MC Ltd #MSInspire

Thanks for this info - nearly 5pm on a Friday for me, what better time to solve a problem :) I can go into the weekend with one less thing to fix.

Collapse
 
balt1794 profile image
balt1794

I'm glad I could help

Collapse
 
lucasdabra profile image
Lucas Silva

Thanks!!!

Collapse
 
mikedroid profile image
Miguel Ángel Reyes Moreno

Thanks for the post, it was what I needed!

Collapse
 
balt1794 profile image
balt1794

Awesome! Glad it helped

Collapse
 
jeisson_caicedo_840e6889f profile image
Jeisson Caicedo

Thank u so much!!!!!!!!

Collapse
 
balt1794 profile image
balt1794

Thanks for leaving a message. I'm glad the tutorial was helpful :)

Collapse
 
imran_khan_d46c1ebbd38324 profile image
Imran Khan

I followed these commands and get the following prompt: pkill: Unknown user `postgres'

Image description

Collapse
 
awaken180dev profile image
Jeremy Lopez

I know this is late but hopefully it helps someone. -u needs to be followed by the name in the USER column. In your case it would be -u lilimiindahouse. CAUTION this will crash your computer and you will need to restart it. I did that and following the restart everything worked properly. In my situation killing by the PID did not work as the process restarted itself with a different PID immediately. Killing the USER was the only solution.

Collapse
 
imran_khan_d46c1ebbd38324 profile image
Imran Khan

and still not able to run Postgres can someone plz help!? Thanks

Collapse
 
imran_khan_d46c1ebbd38324 profile image
Imran Khan

sudo kill -kill $(sudo lsof -t -i :5432)

use this command^^^^^^^^^

Collapse
 
imran_khan_d46c1ebbd38324 profile image
Imran Khan

sudo kill -kill $(sudo lsof -t -i :5432)

This command saved my life!! ^^^^^