0
votes

scroll to bottom for an update

This is my first time configuring replication on a production server that is already replicating to a server. I'm adding an additional server. Replication is working in the existing environment but the additional server I added is not working. Since I don't want to break my existing replication, I created a new user on the master for the additional server. This is version 9.3.5 on both master and slave.

psql -c "CREATE USER rep REPLICATION LOGIN CONNECTION LIMIT 1 ENCRYPTED PASSWORD 'yourpassword';"

On the slave I created a recovery file and placed it in the data directory

standby_mode = 'on'
primary_conninfo = 'host=master_IP_address port=5432 user=rep 
password=yourpassword'
trigger_file = '/tmp/postgresql.trigger.5432'

On the master, I started the initial backup.

psql -c "select pg_start_backup('initial_backup');"

Copied the data via rsync.

rsync -cva --inplace --exclude=*pg_xlog* /var/lib/postgresql/9.1/main/ slave_IP_address:/var/lib/postgresql/9.1/main/

Once rsync completed, I issued the following command.

psql -c "select pg_stop_backup();"

primary server - posgresql.conf

listen_addresses = '*'           

max_connections = 1000                  
unix_socket_directories = ''           


shared_buffers = 1024MB                 

temp_buffers = 1024MB                   
work_mem = 64MB                         
maintenance_work_mem = 512MB            
max_stack_depth = 31MB                  

wal_level = hot_standby                 


wal_buffers = -1                         

checkpoint_segments = 512                
checkpoint_timeout = 1h                 

# - Archiving -

archive_mode = on               

archive_command = 'cd .'

max_wal_senders = 5             

primary server - pg_hba.conf

# TYPE  DATABASE        USER            ADDRESS                 METHOD

# "local" is for Unix domain socket connections only
local   all             all                                        trust
# IPv4 local connections:
host    all             all              127.0.0.1/8               trust
host    all             all              192.168.10.10/32          trust
host    all             all              ny-node0.xxx.net          trust
# below is the existing replication server that works.
host    all             all              ny-node1.xxx.net          trust

# IPv6 local connections:
host    all             all             ::1/128                    trust

# Allow replication connections from localhost, by a user with the
# replication privilege.

local   replication     postgres                                trust
host    replication     postgres        127.0.0.1/8             trust

host    replication     postgres        ny-node1.xxx.net        trust
host    replication     rep             IP-OF-NEW-SLAVE/32      trust   
host    replication     postgres        IP-OF-MASTER/32         trust

slave postgresql.conf

listen_addresses = '*' 
max_connections = 100                   
shared_buffers = 128MB                 
wal_level = hot_standby                 
archive_command = 'cd .'                 
logfile segment
max_wal_senders = 1             
hot_standby = on                
hot_standby_feedback = on               
wal_receiver_timeout = 60s              
log_destination = 'stderr'              
logging_collector = on          
log_directory = 'pg_log'                 
log_filename = 'postgresql-%Y-%m-%d_%H%M%S.log' 
log_timezone = 'UTC'
datestyle = 'iso, mdy'
timezone = 'UTC'
lc_messages = 'en_US.UTF-8'                      
lc_monetary = 'en_US.UTF-8'                      

lc_numeric = 'en_US.UTF-8'                        
lc_time = 'en_US.UTF-8'                         
default_text_search_config = 'pg_catalog.english'

pg_hba.conf of slave

# TYPE  DATABASE        USER            ADDRESS                 METHOD

# "local" is for Unix domain socket connections only
local   all             all                                     trust
# IPv4 local connections:
host    all             all             127.0.0.1/32            trust
# IPv6 local connections:
host    all             all             ::1/128                 trust
# Allow replication connections from localhost, by a user with the
# replication privilege.
#local   replication     postgres                                md5
host    replication     rep             IP-OF-MASTER/32        trust
#host    replication     postgres        ::1/128                 md5

I restarted postgres on the master and slave and when I created a database on the master, it doesn't replicate to the new slave.

I made some progress (update)

I tweaked the pg_hba.conf on the slave and only left lines that is associated to the new user I created for replication which is called 'rep'.

#local   replication     rep                                     md5
host    replication      rep             ip_of_slave/32        trust
host    replication      rep             ip_of_master/32       trust

I also tweaked my recovery.conf and placed it in the data directory. Since I have a trust relationship between master and slave, I removed the password in the recovery.conf.

standby_mode = 'on'
primary_conninfo = 'host=ip_of_master port=5432 user=rep'
trigger_file = '/tmp/postgresql.trigger.5432'

Now my logs indicate:

LOG:  database system was shut down in recovery at 2019-09-02 20:02:04 UTC
LOG:  entering standby mode
LOG:  contrecord is requested by 26/78000028
LOG:  started streaming WAL from primary at 26/78000000 on timeline 7
LOG:  contrecord is requested by 26/78000028
FATAL:  terminating walreceiver process due to administrator command
LOG:  contrecord is requested by 26/78000028
LOG:  contrecord is requested by 26/78000028
LOG:  contrecord is requested by 26/78000028
LOG:  contrecord is requested by 26/78000028
LOG:  contrecord is requested by 26/78000028
1
Are you aware that Postgres 9.3 is no longer supported? You should plan an upgrade as soon as possible. - a_horse_with_no_name

1 Answers

2
votes

It seems that you started the slave server before you put recovery.conf in the data directory. In that case, PostgreSQL will come up as a standalone database after recovery rather than become a standby server.

Once that has happened, you have to discard the slave and start over.

The correct order of operations is:

  • SELECT pg_start_backup('label');

  • perform the rsync

  • SELECT pg_stop_backup();

  • put recovery.conf with standby_mode = 'on' into the slave's data directory

  • start the slave