Postgresql – psql: could not connect to server: No route to host

high-availabilitymaster-slavepostgresql

I know this is repeated question but I didn't found any solution

I want to Set-Up Master-Slave Replication for PostgreSQL 9.6 in Debian 9. But slave server could not connect master .

xx.xxx.xxx.205 = master
xx.xxx.xxx.206 = slave


    root@master:~# netstat -plntu |grep 5432
tcp        0      0 0.0.0.0:5432            0.0.0.0:*               LISTEN      6290/postgres
tcp6       0      0 :::5432                 :::*                    LISTEN      6290/postgres

root@slave:~# netstat -plntu |grep 5432
tcp        0      0 0.0.0.0:5432            0.0.0.0:*               LISTEN      31961/postgres
tcp6       0      0 :::5432                 :::*                    LISTEN      31961/postgres

I get error first when I try to do Copy PostgreSQL Data from the MASTER to the SLAVE.

postgres@slave:~/9.6$ pg_basebackup -h xx.xxx.xxx.205 -D ~postgres/9.6/main/ -X stream -P
pg_basebackup: could not connect to server: could not connect to server: No route to host
        Is the server running on host "xx.xxx.xxx.205" and accepting
        TCP/IP connections on port 5432?

After that I check the connection on postgresql.

There is no firewalld and ufw in my servers.

I edited pg_hba.conf and postgresql.conf on both server like this.

host     all         all        xx.xxx.xxx.205/32 md5
host     all         all        xx.xxx.xxx.206/32 md5

postgresql.conf

listen_addresses = '*'

I can connect slave from master it work fine.

root@master:~# psql -h xx.xxx.xxx.206 -p 5432
Password:

But I can't connect from slave to master.

root@slave:~# psql -h xx.xxx.xxx.205 -p 5432
psql: could not connect to server: No route to host
        Is the server running on host "xx.xxx.xxx.205" and accepting
        TCP/IP connections on port 5432?

Please help me..

Best Answer

Finally I found the solution, my Iptables rules are different in Master and Slave.

iptables -L INPUT


iptables -P INPUT ACCEPT
iptables -P OUTPUT ACCEPT
iptables -P FORWARD ACCEPT
iptables -F INPUT 
iptables -F OUTPUT
iptables  -F FORWARD

iptables -L INPUT