Create a user for the replication:
$ psql postgres
postgres=# CREATE USER replica REPLICATION LOGIN ENCRYPTED PASSWORD 'so-secret';
Change your postgres.conf:
$ sudo vim /etc/postgresql/12/main/postgresql.conf
Set this:
listen_addresses = '*'
wal_level = replica
max_wal_senders = 3
wal_keep_segments = 64
Change your pg_hba.conf:
$ sudo vim /etc/postgresql/12/main/pg_hba.conf
Add at the end of the file:
host replication replica <slave-ip-address>/32 md5
Restart your master server:
$ sudo systemctl restart postgresql
Stop postgres server:
$ sudo systemctl stop postgresql
As postgres user:
$ sudo -i
$ su - postgres
$ rm -rf /var/lib/postgresql/12/main/*
$ pg_basebackup -h <master-ip-address> -D /var/lib/postgresql/12/main/ -Fp -Xs -P -R
Password: so-secret
Start postgres:
$ sudo systemctl start postgresql