<commit_before>---
owner_slack: "#2ndline"
title: Set up PostgreSQL replication
section: Databases
layout: manual_layout
parent: "/manual.html"
old_path_in_opsmanual: "../opsmanual/infrastructure/howto/setup-postgresql-replication.md"
last_reviewed_on: 2017-02-26
review_in: 6 months
---

> **This page was imported from [the opsmanual on GitHub Enterprise](https://github.com/alphagov/govuk-legacy-opsmanual)**.
It hasn't been reviewed for accuracy yet.
[View history in old opsmanual](https://github.com/alphagov/govuk-legacy-opsmanual/tree/master/infrastructure/howto/setup-postgresql-replication.md)


This how-to guide explains how to set-up PostgreSQL replication.

New servers can be created using the `govuk_postgresql::server::primary`
and `govuk_postgresql::server::standby` classes. This will prepare them,
but replication has to be initiated manually.

## Syncing a standby

To sync (or indeed resync) a standby from a primary run
`sudo pg_resync_slave`.

By default, you should **not** be prompted for a password. If you are
prompted, then this password is stored in the [govuk-secrets
repo](https://github.com/alphagov/govuk-secrets) under the
`govuk::node::s_postgresql_primary::standby_password` key and can be
read with:

`bundle exec rake 'eyaml:modify[edit,staging]'`

Where staging is the environment the server is in. This will sync data
from the primary and restart (resulting in some downtime) the service on<commit_msg>Update review date for postgres replication docs<commit_after>---
owner_slack: "#2ndline"
title: Set up PostgreSQL replication
section: Databases
layout: manual_layout
parent: "/manual.html"
old_path_in_opsmanual: "../opsmanual/infrastructure/howto/setup-postgresql-replication.md"
last_reviewed_on: 2017-10-04
review_in: 6 months
---

> **This page was imported from [the opsmanual on GitHub Enterprise](https://github.com/alphagov/govuk-legacy-opsmanual)**.
It hasn't been reviewed for accuracy yet.
[View history in old opsmanual](https://github.com/alphagov/govuk-legacy-opsmanual/tree/master/infrastructure/howto/setup-postgresql-replication.md)


This how-to guide explains how to set-up PostgreSQL replication.

New servers can be created using the `govuk_postgresql::server::primary`
and `govuk_postgresql::server::standby` classes. This will prepare them,
but replication has to be initiated manually.

## Syncing a standby

To sync (or indeed resync) a standby from a primary run
`sudo pg_resync_slave`.

By default, you should **not** be prompted for a password. If you are
prompted, then this password is stored in the [govuk-secrets
repo](https://github.com/alphagov/govuk-secrets) under the
`govuk::node::s_postgresql_primary::standby_password` key and can be
read with:

`bundle exec rake 'eyaml:modify[edit,staging]'`

Where staging is the environment the server is in. This will sync data
from the primary and restart (resulting in some downtime) the service on
{'fraction_non_alphanumeric': 0.09654228004108183, 'fraction_numerical': 0.006846970215679562, 'mean_word_length': 5.5369127516778525, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 6, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2007224', 'n_tokens_mistral': 946, 'n_tokens_neox': 885, 'n_words': 307}