postgresqlreplication
Differences
This shows you the differences between two versions of the page.
| Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
| postgresqlreplication [2021/08/25 13:54] – z0hpvk | postgresqlreplication [2025/03/08 22:24] (current) – external edit 127.0.0.1 | ||
|---|---|---|---|
| Line 44: | Line 44: | ||
| pg_basebackup -D < | pg_basebackup -D < | ||
| + | -D Data Directory | ||
| -v Verbose | -v Verbose | ||
| -P Progress Reporting | -P Progress Reporting | ||
| Line 51: | Line 52: | ||
| </ | </ | ||
| - | Once the copy has completed, you will see the following message | + | Once the copy has completed, you will see the following message: \\ |
| < | < | ||
| pg_basebackup: | pg_basebackup: | ||
| Line 60: | Line 61: | ||
| < | < | ||
| hot_standby = on | hot_standby = on | ||
| + | </ | ||
| + | |||
| + | ==== Create a Replication Slot on the Primary ==== | ||
| + | < | ||
| + | SELECT * FROM pg_create_physical_replication_slot(' | ||
| </ | </ | ||
| Line 66: | Line 72: | ||
| standby_mode = on | standby_mode = on | ||
| primary_conninfo = ' | primary_conninfo = ' | ||
| + | primary_slot_name = ' | ||
| </ | </ | ||
| Line 76: | Line 83: | ||
| ==== Check Replication Progress ==== | ==== Check Replication Progress ==== | ||
| < | < | ||
| + | cd $HOME/ | ||
| ls -lrt $(ps -ef | grep postgres | grep recovering | grep -v grep | awk {' | ls -lrt $(ps -ef | grep postgres | grep recovering | grep -v grep | awk {' | ||
| Line 88: | Line 96: | ||
| select TXID_CURRENT_SNAPSHOT(); | select TXID_CURRENT_SNAPSHOT(); | ||
| select * from PG_LAST_XACT_REPLAY_TIMESTAMP(); | select * from PG_LAST_XACT_REPLAY_TIMESTAMP(); | ||
| + | select pg_wal_replay_pause(); | ||
| + | select pg_wal_replay_resume(); | ||
| -- Note some function names changed in PostgreSQL 10 | -- Note some function names changed in PostgreSQL 10 | ||
| + | -- Run on subscriber server | ||
| select pg_is_in_recovery(), | select pg_is_in_recovery(), | ||
| pg_is_wal_replay_paused(), | pg_is_wal_replay_paused(), | ||
| Line 128: | Line 139: | ||
| CREATE ROLE repuser REPLICATION LOGIN PASSWORD '< | CREATE ROLE repuser REPLICATION LOGIN PASSWORD '< | ||
| </ | </ | ||
| + | To copy the initial table data, the replication role must have SELECT privileges on all of the tables (or be a superuser).\\ | ||
| ==== Create Publisher on Primary ==== | ==== Create Publisher on Primary ==== | ||
| < | < | ||
| + | -- All Tables | ||
| CREATE PUBLICATION pub_upgrade FOR ALL TABLES; | CREATE PUBLICATION pub_upgrade FOR ALL TABLES; | ||
| + | -- Selected Tables | ||
| + | CREATE PUBLICATION pub_upgrade; | ||
| + | ALTER PUBLICATION pub_upgrade ADD TABLE customers; | ||
| + | ALTER PUBLICATION pub_upgrade ADD TABLE orders; | ||
| </ | </ | ||
| This needs to be done on every database in the instance.\\ | This needs to be done on every database in the instance.\\ | ||
| Line 143: | Line 160: | ||
| ==== Check Replication Progress ==== | ==== Check Replication Progress ==== | ||
| - | < | + | < |
| - | -- On Primary / Standby | + | -- On Publisher |
| - | \dRp / \dRs | + | \dRp |
| + | SELECT * FROM PG_REPLICATION_SLOTS; | ||
| + | SELECT * FROM PG_STAT_REPLICATION; | ||
| + | |||
| + | -- On Subscriber | ||
| + | \dRs | ||
| </ | </ | ||
| + | |||
| + | ==== Issues ==== | ||
| + | DDL changes will not be replicated to the subscriber.\\ | ||
| + | May be possible to replicate via an Event Trigger?\\ | ||
| + | [[https:// | ||
| + | [[https:// | ||
postgresqlreplication.1629899691.txt.gz · Last modified: (external edit)
