Site icon Database Tutorials

What is PgBackRest and PgBackRest Installation in PostgreSQL 12

What is pgBackRest

pgBackRest is a backup/restore tool in postgresql.

PostgreSQL Backup Types

In Postgresql, we create backups in two ways: logical and physical.

Replication mechanism is not a baclıup method!

pgBackRest software is classified as “physical backup / restore”.

What can you do with pgBackRest?

Time Information
Size Information
Required segment files
Backup type

PgBackRest Backup Types

Full backup: All data in the PostgreSQL Cluster is backed up.

Differential backup: Backups files that have changed from the last full backup.

Incremental backup: Backups the files that have changed from the last backup.

PgBackRest Installation

In this section, we will install PgBackRest and create backups with pgBackRest in the following ways.

First, according to the architecture you choose, we install pgBackrest on the PostgreSQL server and/or on all servers where the backup we create is stored:

Install PgBackRest on Debian and its derivatives

Install PgBackRest on RedHat and its derivatives

PgBackRest uses archive_mode and archive_command in postgresql.conf to track wal. We set these parameters on all database servers.

Change Parameters on postgresql.conf to Track WALs

By connecting to PostgreSQL, you can do the same with the following commands;
Restart PostgreSQL to enable the change to the archive_mode parameter.

Create PostgreSQL Cluster Backup with pgBackRest on the Same Server

If you want to create a backup on the master server,

Configuration of pgBackRest

Create PostgreSQL Cluster Backup with pgBackRest to Backup Server

If you want to create a backup to backup server,

Configuration of pgBackRest on Master

Configuration of pgBackRest on Backup Server

Create PostgreSQL Cluster Backup From Replication with pgBackRest

In this scenario, we will create a backup from Replika to backup server.

Configurations of pgbackrest on Master and Replica

Configuration of pgBackRest on Backup Server

Backup PostgreSQL Cluster with PgBackRest

Check PgBackRest Configurations

We need to create a backup catalog first. Next, we need to check that the pgBackRest configurations are correct.

We can create a backup 🙂

pgBackRest creates a full backup by default on the first backup. You can specify the backup type with –type(full, diff, or incr).

The sample command and output are as follows:

List the backup catalog and the backups

Restore PostgreSQL Cluster with PgBackRest

When the PostgreSQL service is closed on the server we want to restore, we run the following command:

pgBackRest returns the most recent backup by default.

In this article I talked about backing up with basic-level configurations.

Exit mobile version