Questions And Answers

More Tutorials

postgreSQL High Availability


Replication in PostgreSQL

Configuring the Primary Server


○ Replication User for replication activities
○ Directory to store the WAL archives

○Create Replication user

createuser -U postgres replication -P -c 5 --replication

 + option -P will prompt you for new password
 + option -c is for maximum connections. 5 connections are enough for replication
 + -replication will grant replication privileges to the user

○Create a archive directory in data directory

mkdir $PGDATA/archive

○Edit the pg_hba.conf file

This is host base authentication file, contains the setting for client autherntication. Add below entry:

#hosttype database_name user_name hostname/IP method
 host replication replication <slave-IP>/32 md5

○Edit the postgresql.conf file

This is the configuration file of PostgreSQL.

wal_level = hot_standby

This parameter decides the behavior of slave server.

 `hot_standby` logs what is required to accept read only queries on slave server.
 `streaming` logs what is required to just apply the WAL's on slave.
 `archive` which logs what is required for archiving.


This parameters allows to send WAL segments to archive location using archive_command parameter.

archive_command = 'test ! -f /path/to/archivedir/%f && cp %p /path/to/archivedir/%f'

Basically what above archive_command does is it copies the WAL segments to archive directory.

wal_senders = 5 This is maximum number of WAL sender processes.

Now restart the primary server.


In this page (written and validated by ) you learned about postgreSQL High Availability . What's Next? If you are interested in completing postgreSQL tutorial, your next topic will be learning about: postgreSQL Programming with PL pgSQL.

Incorrect info or code snippet? We take very seriously the accuracy of the information provided on our website. We also make sure to test all snippets and examples provided for each section. If you find any incorrect information, please send us an email about the issue:

Share On:

Mockstacks was launched to help beginners learn programming languages; the site is optimized with no Ads as, Ads might slow down the performance. We also don't track any personal information; we also don't collect any kind of data unless the user provided us a corrected information. Almost all examples have been tested. Tutorials, references, and examples are constantly reviewed to avoid errors, but we cannot warrant full correctness of all content. By using, you agree to have read and accepted our terms of use, cookies and privacy policy.