User Tools

Site Tools


how_to:postgresql_replication

This is an old revision of the document!


PostgreSQL Replication

PostgreSQL 9.1 (used in VPOP3 5 and later) supports replication from a 'Master' to a 'Slave' database server. This can be used with VPOP3 for having a near-realtime backup of your settings & messages.

To use the replication, you need to have a file share which is accessible from both PCs. The thing to watch out for is that the PostgreSQL services may be running as a different user from the currently logged in user, so make sure that the user(s) which the PostgreSQL services are running as have full access to the network share. The network share can be on either of the computers involved in the replication, or on a totally different PC.

For the sake of this article, we will have a Master PC, on IP address 192.168.1.10, a Slave PC on IP address 192.168.1.20, and a file share at \\192.168.1.10\pgsql\db_replication (note that you need to access the share using the UNC path, mapped drives will not work). VPOP3 is installed in c:\vpop3 on both PCs

Both the Master and Slave PCs should have VPOP3 installed into the same location (eg c:\vpop3 or d:\vpop3, etc), or settings relating to paths will not work if you have to fail over to the Slave PC. Alternatively, you could use the Command Line Settings Tool to change the paths as part of your fail over procedure.

On the Master PC

  • In the VPOP3\pgsql\data folder, find the file postgresql.conf and edit it using Notepad or another text editor. At the bottom of the file add the lines:\

wal_level = hot_standby

archive_mode = on
archive_command = 'copy %p \\\\192.168.1.10\pgsql\\db_replication'
max_wal_senders = 5
wal_keep_segments = 128
listen_addresses = '*'
hot_standby = on

(Note that the archive_command has doubled up the \ characters)

  • Edit the file pg_hba.conf using Notepad or another text editor, and add the lines:

host replication postgres 192.168.1.10/32 trust

host replication postgres 192.168.1.20/32 trust
  • Restart the VPOP3 and VPOP3DB services to load this new configuration
  • You should see files starting to appear in the share directory as the master starts copying its transaction log files there
  • Make sure that port 5433 is allowed through any firewall on the master PC

On the Slave PC

  • Install the same version of VPOP3 as on the master PC
  • Stop the VPOP3 service, and Disable it
  • Stop the VPOP3DB service (do not disable it)
  • Rename the c:\vpop3\pgsql\data folder

Go to a command prompt in the VPOP3\pgsql\bin folder and run

pg_basebackup -D c:/vpop3/pgsql/data -P -v -p 5433 -x -h 192.168.1.10 -U postgres

This will make a copy of the database folder on the slave PC

how_to/postgresql_replication.1372421305.txt.gz · Last modified: 2018/11/14 10:44 (external edit)