Performing a `pg_basebackup` against the GitLab’s managed PostgreSQL database

One can perform a « live-backup » of a PostgreSQL cluster using pg_basebackup.

GitLab (installed from .deb packages) installs and manages a PostgreSQL cluster autonomously and by default a pg_basebackup will fail (and is not authorized).

To perform a live pg_basebackup against the GitLab’s managed PostgreSQL server, one needs to enable replication and authorize the gitlab-psql user to perform the replication:

Setup GitLab’s PostgreSQL for replication in /etc/gitlab/gitlab.rb:

postgresql['wal_level'] = "replica"
postgresql['max_wal_senders'] = 10
postgresql['max_replication_slots'] = 10
postgresql['custom_pg_hba_entries'] = {
  PG_BASEBACKUP: [
    {
      type: "local",
      database: "replication",
      user: "gitlab-psql",
      cidr: "",
      method: "peer"
    }
  ]
}

This will enable replication in PostgreSQL (in postgresql.conf) and allow local connections for replication (in pg_hba.conf).

Reconfigure and restart the postgresql service:

gitlab-ctl reconfigure
gitlab-ctl restart postgresql

From now on, you should be able to perform a pg_basebackup:

runuser -u gitlab-psql -- /opt/gitlab/embedded/bin/pg_basebackup -h /var/opt/gitlab/postgresql --checkpoint=fast --format=p --pgdata "/tmp/pg_basebackup.$(date +%Y-%m-%d).data"

Ce contenu a été publié dans Uncategorized. Vous pouvez le mettre en favoris avec ce permalien.

Laisser un commentaire

Votre adresse e-mail ne sera pas publiée. Les champs obligatoires sont indiqués avec *

*