Sunday , November 24 2024

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.

  • Logical Backup (pg_dump, pg_dumpall)
  • Physical Backup (base backup)

Replication mechanism is not a baclıup method!

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

What can you do with pgBackRest?

  • You can create backups on the same server or on a different server.
  • You can create a backup from Replication. pgBackRest allows you to create backups on a backup server connected with master and replica. pgBackRest backs up data that is not available in Replica from the master. All remaining backup operations are performed from Replica. Thus, you do not create a backup cost on the master server.
  • You can perform all backup and restore operations in parallel.
  • pgBackRest compresses and sends data when creating backups. Thus, you do not overload the network traffic. This makes backup/restore faster.
  • pgBackRest maintains a catalog of backups;

Time Information
Size Information
Required segment files
Backup type

  • pgBackRest has 3 backup types.

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 tracks wal files. It uses the archive_command parameter in Postgresql.conf. It deletes old backups and old wal files. Incremental backups related to full and diff backups are also automatically deleted.
  • pgBackRest stores the number of full and differential backups you specify.
  • pgBackRest supports PostgreSQL 12 with the latest version v2.18.

PgBackRest Installation

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

  • Create PostgreSQL Cluster Backup with pgBackRest on the Same Server
  • Create PostgreSQL Cluster Backup with pgBackRest to Backup Server
  • Create PostgreSQL Cluster Backup From Replication with pgBackRest

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.

Loading

About Zekiye AYDEMİR

8 comments

  1. how to install in windows server

  2. How to take incremental and differential backups.

    • Make sure you have taken full backup first.
      Then second time, when you run the the above command, change – -type = Incr (for incremental) or – -type = diff (for differential)

  3. It also provides functionality of PITR too

  4. By default pgBackRest will attempt to perform an incremental backup. However, an incremental backup must be based on a full backup and since no full backup existed pgBackRest ran a full backup instead.

  5. Really brief- clear content Thx

Leave a Reply

Your email address will not be published. Required fields are marked *