简体   繁体   中英

Change PostgreSQL CLIENT Ports

I would like to limit PostgreSQL on what ports he allocates for client connections.

What I mean is having the server listening on 5432, when a connection comes in it will allocate a port to that connection, examples currently on my local test server are 61943, 61949, 61951, 61952, 61957, etc.

In a production server what happens is those client ports are around the high 30000s which is a problem since we have some services running on those, sometimes, before our service has a chance to start, a random client connection will steal the port from it.

How would I go about configuring what the client ports should be for PostgreSQL?

PostgreSQL does not have a way to change this, it's up to the Operating System.

If using a unix system you can tell the system not to reserve ports in the range of your application by doing this (x and y being the port numbers):

sysctl -w.net.ipv4.ip_local_port_range="xy"

Edit /etc/sysctl.conf with your preferred text editor and add net.ipv4.ip_local_port_range = xy

Then to reload the file do sysctl -p

This will not kill ongoing connections on the old ports, so a reboot is suggested.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM