postgres=# show listen_addresses ;
listen_addresses
------------------
localhost (127.0.0.1)
postgres=# \! netstat -ntlp |grep postgres
tcp 0 0 127.0.0.1:5434 0.0.0.0:* LISTEN 6807/postgres
postgres=# \! /sbin/ifconfig |grep inet
10.71.6.61 netmask 255.255.255.0 broadcast 10.71.6.255
127.0.0.1 netmask 255.0.0.0
postgres=# alter system set listen_addresses ='10.71.6.61';
postgres=# alter system set port = '5434';
listen_addresses : Default is localhost (127.0.0.1). Since Postgres only listens
on localhost, it only allows local connections. It does not allow connections over the
network. A restart is required after the change.
The IPs you want to be accessed must be open for listening.
For the server to listen on one of its IP, 10.71.6.61
alter system set listen_addresses ='10.71.6.61';
To listen on all IPs
alter system set listen_addresses ='*';
For listening both IP 10.71.6.61 and local
alter system set listen_addresses ='10.71.6.61,localhost';
port : The default value is 5432. A restart is required for a change. Each instance
runs from its own port.
# Details can be seen with netstat.
postgres@srv1:~$ sudo netstat -ntlp
Proto Local Address Foreign Address State PID/Program name
tcp 0.0.0.0:22 0.0.0.0:* LISTEN 541/sshd
tcp 127.0.0.1:5434 0.0.0.0:* LISTEN 7983/postgres
tcp 10.71.6.61:5434 0.0.0.0:* LISTEN 7983/postgres
# We open the other instance and check again.
systemctl start postgresql@14-main.service
postgres@srv1:~$ sudo netstat -ntlp
Proto Local Address F.Address State PID/Program name
tcp 10.71.6.61:5433 0.0.0.0:* LISTEN 8239/postgres
tcp 10.71.6.61:5434 0.0.0.0:* LISTEN 7983/postgres
max_connections : Determines the maximum number of simultaneous
connections.
The default value is 100. A restart is required for a change. It is a parameter that will
affect the performance. Each connection reserves the amount of ‘work_mem’ memory.
In other words, it takes as much memory as the “number of connections * work_mem” amount from the system. If you have a multi-link system, you can
consider using a shared link solution like pgpool, pgbouncer, etc.
superuser_reserved_connections : The number of reserved connections
for superusers. The default value is 3.