How to uninstall Postgres on Mac?

Yesterday I wanted to run Postgres image on my mac but the docker was complaining that port 5432 is in use. I was pretty sure that I did not install Postgres on my machine,  and due to the Microservice settings that I intended to run locally, I only wanted to run Postgres on port 5432, not any other port. I have searched my local machine for a copy of running Postgres and the result was negative. I reached to a good friend (Dave Oxley) with the awesome Linux background and he guided me to find the running instance of Postgres and get rid of it. Here are the steps that I took:

  1. Finding the processor that is running the Postgres instance:

sudo lsof -i tcp:5432

       Result:

COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
postgres 6975 postgres 4u IPv6 0xb82fa8ce4a70a695 0t0 TCP *:postgresql (LISTEN)
postgres 6975 postgres 5u IPv4 0xb82fa8ce4fc9647d 0t0 TCP *:postgresql (LISTEN)

by looking at the result it is very clear that there is a parent processor that is running the Postgres, so technically killing PID was not helpful because it parent processor would run it again. The only option was uninstalling the Postgres, but how do I know where that Postgres was in my machine.

2. To find the answer I ran this command:

 ps -ef |grep 6975

and running this command gives me this result:

502 6975 1 0 11:40AM ?? 0:00.04 /Library/PostgreSQL/10/bin/postmaster -D/Library/PostgreSQL/10/data
502 6982 6975 0 11:40AM ?? 0:00.00 postgres: logger process
502 6984 6975 0 11:40AM ?? 0:00.00 postgres: checkpointer process
502 6985 6975 0 11:40AM ?? 0:00.04 postgres: writer process
502 6986 6975 0 11:40AM ?? 0:00.01 postgres: wal writer process
502 6987 6975 0 11:40AM ?? 0:00.00 postgres: autovacuum launcher process
502 6988 6975 0 11:40AM ?? 0:00.00 postgres: stats collector process
502 6989 6975 0 11:40AM ?? 0:00.00 postgres: bgworker: logical replication launcher
501 7073 6601 0 11:45AM ttys005 0:00.00 grep --color=auto --exclude-dir=.bzr --exclude-dir=CVS --exclude-dir=.git --exclude-dir=.hg --exclude-dir=.svn 6975

form the first line of log you can see that Postgres version 10 was running in my machine, so I head to that directory and uninstalled the Postgres and then I was able to run docker without any problem.

 

🙂

Advertisement

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s