February 2020
Intermediate to advanced
734 pages
38h 13m
English
Relying on transaction log files is a risky endeavor. If the primary server deletes one before a replica can process it, we may need to rebuild the replica outright. If we're using PostgreSQL 9.4 or higher, we can prevent that kind of mishap by using replication slots instead.
We would need to create a replication slot on the primary server itself with this SQL:
SELECT * FROM pg_create_physical_replication_slot('pg2_slot');
Then, on the replica, we would add this line to its postgresql.conf (12+) or recovery.conf files before starting (or restarting) the instance:
primary_slot_name = 'pg2_slot'
Now our replica can't fall behind. We should be careful that replica outages are limited, otherwise, the primary could accumulate ...
Read now
Unlock full access