Guest User

Untitled

a guest
May 3rd, 2018
126
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.20 KB | None | 0 0
  1. # Setup master server:
  2.  
  3. Create a user for the replication:
  4.  
  5. ```
  6. $ psql postgres
  7. postgres=# CREATE USER replica REPLICATION LOGIN ENCRYPTED PASSWORD 'so-secret';
  8. ```
  9.  
  10. Change your postgres.conf:
  11.  
  12. ```
  13. $ sudo vim /etc/postgresql/10/main/postgresql.conf
  14. ```
  15.  
  16. Set this:
  17.  
  18. ```
  19. listen_addresses = '*'
  20. wal_level = replica
  21. max_wal_senders = 3
  22. wal_keep_segments = 64
  23. ```
  24.  
  25. Change your pg_hba.conf:
  26.  
  27. ```
  28. $ sudo vim /etc/postgresql/10/main/pg_hba.conf
  29. ```
  30.  
  31. Add at the end of the file:
  32.  
  33. ```
  34. host replication replica <slave-ip-address>/32 md5
  35. ```
  36.  
  37. Restart your master server:
  38.  
  39. ```
  40. $ sudo systemctl restart postgresql
  41. ```
  42.  
  43.  
  44. # Setup slave server:
  45.  
  46. Stop postgres server:
  47.  
  48. ```
  49. $ sudo systemctl stop postgresql
  50. ```
  51.  
  52. As postgres user:
  53.  
  54. ```
  55. $ sudo -i
  56. $ su - postgres
  57. $ rm -rf /var/lib/postgresql/10/main/*
  58. $ pg_basebackup -h <master-ip-address> -D /var/lib/postgresql/10/main/ -P -U replica --wal-method=stream
  59. Password: so-secret
  60. $ vim /var/lib/postgresql/10/main/recovery.conf
  61. ```
  62.  
  63. Add this:
  64.  
  65. ```
  66. standby_mode = 'on'
  67. primary_conninfo = 'host=<master-ip-address> port=5432 user=replica password=so-secret'
  68. trigger_file = '/tmp/MasterNow'
  69. ```
  70.  
  71. Start postgres:
  72.  
  73. ```
  74. $ sudo systemctl start postgresql
  75. ```
Add Comment
Please, Sign In to add comment