How to do a certain database replication in postgres for a given port?

1

Well I have the following scenario, I need to do a replication from bank A to bank B. Well I've been doing this from one machine to another with the following changes:

Master Machine - 10.0.0.1

    sudo vim /etc/postgresql/9.4/main/postgresql.conf
        listen_addresses = 'localhost,10.0.0.1'
        wal_level = hot_standby
        max_replication_slots = 3
        max_wal_senders = 3

    sudo vim /etc/postgresql/9.4/main/pg_hba.conf
        host    replication   all        10.0.0.2/32   trust   # the slave

    sudo su - postgres
    psql 
        select * from pg_create_physical_replication_slot('theslave');

    sudo service postgresql restart

Slave Machine 10.0.0.2

   sudo vim /etc/postgresql/9.4/main/postgresql.conf
       listen_addresses = 'localhost,10.0.0.2'  
       wal_level = hot_standby
       hot_standby = on
       hot_standby_feedback = on

   sudo service postgresql stop

   sudo su - postgres
       cd ~/9.4
       rm -rf main
       pg_basebackup -v -D main -R -P -h 10.0.0.1

   sudo su postgresql start

Well using this there works a beauty, however I found that the banks that I have to perform the replication are not on the default port 5432 of postgres are on port 9700, 9701 and 9702. In other words, I have to replicate the data from the databases which are on port 9700, 9701, and 9702 on the master computer for the slave computer on its ports 9700, 9701, and 9702.

What change should I make?

    
asked by anonymous 23.04.2018 / 15:11

1 answer

0

Set the data to connect to the master server at recovery.conf " of the slave server. This is where you tell your replica which port it will connect to:

standby_mode = 'on'
primary_conninfo = 'host=10.0.0.1 port=9700 user=foo password=foopass' 
primary_slot_name = 'theslave'

Likewise, when running pg_basebackup , specify the port using flag -p :

pg_basebackup -v -D main -R -P -h 10.0.0.1 -p 9700.

Of course, to replicate three PostgreSQL clusters that listen on three separate ports, you also need three other slave servers, each configured to replicate from a compliant port above.

    
25.04.2018 / 15:01