Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I release a psql port?

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 -

like image 509
Justin Li Avatar asked Dec 16 '25 13:12

Justin Li


1 Answers

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)

like image 133
Vao Tsun Avatar answered Dec 19 '25 07:12

Vao Tsun



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!