Question

I am setting up a postgresql HA cluster using built-in streaming replication, due to the multiple NICs configuration on 2 server, I want to restrict postgresql replication network traffic to 2nd NIC(eth1), but I have not found the configuration or document to achieve it. Any clue is appreciated, thanks.

thanks, Emre

Was it helpful?

Solution

listen_addresses in postgresql.conf

It's the same setting used for all other connections. There is no way to bind a different listening IP for streaming replication.

pg_hba.conf can be used to control which source IPs can actually make replication connections and what credentials they require. It can also require SSL.

OTHER TIPS

No, listen_addresses is definitely not the right place to do so, and you won't accomplish what you want this way.

Streaming replication is initiated by standby (slave) server, and basically it will decide which NICs will be used. It means that the following configurations should be done on the slave:

1) If you want to enforce using particular NIC (IP address) on the primary server, you'll set the appropriate IP in recovery.conf file on the slave. Something like:

primary_conninfo   = 'host=192.168.1.1 port=5432 ...

This way you'll ensure that 192.168.1.1 IP (thus corresponding NIC) will be used on the primary server. Of course you need to ensure that primary server is configured to listen to this address (mentioned listen_addresses in postgresql.conf).

2) If you want to ensure that particular NIC on the slave server is used, you can accomplish this by setting the appropriate route (again on the slave). Let's assume that your primary will be contacted at 192.168.1.1, and your slave has two NICs (eth0 192.168.1.3 and eth1 192.168.1.4), and you want to ensure that eth1 is used. Then you can add the following route:

route add 192.168.1.1/32 dev eth1

This way you'll ensure that whenever slave communicates with the master (192.168.1.1) it will use eth1 (192.168.1.4). On primary you need to ensure that 192.168.1.4 is acceptable in pg_hba.conf.

Also note that by setting the route you'll define all traffic to the primary server, not only replication traffic.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top