Reputation: 1105
I have searched for how to close psql port for a while, but most of the answers are talking about closing psql command line using \q
, which is not what I am looking for.
My problem is, the postgresql on my laptop are running and listening on port 5432, but I would like to use port 5432 for some other use. Usually I run netstat -plnt
to find the process to kill, but in this case the process that is listening on port 5432 does not have a process id...
Any idea on how I can release the port 5432?
Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
tcp 0 0 127.0.0.1:5432 0.0.0.0:* LISTEN -
Upvotes: 3
Views: 5544
Reputation: 51599
psql
is a client that connects to postgres server. closing connection with \q
just finishes session. When it happens, backend for that session stops, so by closing connection you only release pid on server. And server keeps on listening on port 5432.
If you want to stop listening on port 5432, you can either stop postgres server with pg_ctl stop
or even assign different port to it in postgres.conf, so you can run both programs in parallel
update
If you installed from packages (Ubuntu/Debian/Fedora/RHEL/CentOS/etc) you should use the system services manager to stop postgresql. e.g. in RHEL 7 or Fedora, sudo systemctl stop postgresql-9.6
(or whatever your version is) rather than pg_ctl
(quoting Craig Ringer)
Upvotes: 2