Skip to main content

Installing pgBackRest on Linux (RHEL 9 / Rocky / AlmaLinux)

 When you work with PostgreSQL in real environments, one thing becomes very clear very quickly:

Backups are not optional.

It doesn’t matter how stable your database is — failures happen.

  • Disks crash

  • Files get corrupted

  • Someone runs the wrong delete query

  • A patch goes wrong

  • A standby needs rebuilding.

So having a proper backup strategy is not just good practice, it’s survival.

That’s exactly why tools like pgBackRest are so widely used in PostgreSQL production systems.

In this post, I’ll walk through a simple installation of pgBackRest on a Linux server (RHEL 9 / Rocky Linux / AlmaLinux).

Why pgBackRest?

PostgreSQL already provides tools like:

  • pg_dump

  • pg_basebackup

And yes, they work.

But once your database grows, or you start managing HA setups, these tools start feeling limited.

pgBackRest is built for serious PostgreSQL backup requirements.

Some of the reasons it stands out:

  • Supports full, differential, and incremental backups

  • Built-in compression and encryption

  • Handles WAL archiving cleanly

  • Faster backups using parallel processing

  • Supports retention policies automatically

  • Makes restores much easier and safer

In short, pgBackRest is what you want when backups need to be reliable, repeatable, and production-ready.

Installing pgBackRest on Linux

Let’s get into the setup.

Step 1: Enable the EPEL Repository

On RHEL-based systems, pgBackRest depends on a few packages that are available through EPEL.

So the first step is enabling it:

sudo dnf install -y https://dl.fedoraproject.org/pub/epel/epel-release-latest-9.noarch.rpm 


Once this is installed, your system can access extra enterprise packages that aren’t available in the default repo.

Step 2: Install libssh2 Dependency

pgBackRest uses libssh2 especially when you work with remote repositories or SSH-based setups.

Install it with:

sudo dnf install -y libssh2


Step 3: Install pgBackRest

Now that the dependency is ready, install pgBackRest itself:

sudo dnf install -y pgBackRest



This will pull the required packages and set up the utility on your server.

Step 4: Verify the Installation

After installation, it’s always a good idea to confirm the command is working:

pgbackrest version


At this stage, you might not see much backup information yet (because the repository isn’t configured), but the command should run successfully.

That confirms pgBackRest is installed properly.

What Makes pgBackRest Better Than Traditional Tools?

This is where pgBackRest really shines compared to the basic PostgreSQL utilities.

Incremental Backups

Unlike pg_basebackup, pgBackRest doesn’t copy the entire database every single time.

It can take:

  • Full backup (first time)

  • Differential backup (changes since last full)

  • Incremental backup (changes since last backup)

This saves a lot of storage and time.

WAL Archiving + Point-in-Time Recovery

pgBackRest handles WAL archiving in a clean way, which makes PITR (Point-in-Time Recovery) much easier.

If something breaks at 2:37 PM, you can restore exactly up to 2:36 PM.

That’s a huge advantage in production.

Compression and Encryption Built In

With pgBackRest you don’t need external scripts for compression.

It supports:

  • Compressed backups

  • Encrypted backups

Which is very useful when backups are stored remotely or in cloud storage.

Parallel Backup and Restore

For large databases, pgBackRest is significantly faster because it supports parallel processing.

Backups that take hours with traditional tools can be completed much quicker.


Backup Validation and Retention Policies

pgBackRest can automatically:

  • Validate backups

  • Expire old backups

  • Maintain retention rules

So you don’t end up with hundreds of old backups eating up storage.

Final Thoughts

If you are working with PostgreSQL seriously — especially in production or HA environments — pgBackRest is one of the best tools you can add to your setup.

Installation is simple, and once configured properly, it gives you:

  • Reliable backups

  • Faster restores

  • PITR support

  • Automation and safety

In the next post, I’ll cover:

✅ Configuring the backup repository
✅ Setting up WAL archiving
✅ Taking the first full backup
✅ Restore testing

Comments

Popular posts from this blog

πŸš€ Automating Oracle Database Patching with Ansible: A Complete Guide

Oracle database patching has long been the bane of DBAs everywhere. It's a critical task that requires precision, expertise, and often results in extended maintenance windows. What if I told you that you could automate this entire process, reducing both risk and downtime while ensuring consistency across your Oracle estate? πŸ’‘ In this comprehensive guide, I'll walk you through a production-ready Ansible playbook that completely automates Oracle patch application using OPatch. Whether you're managing a single Oracle instance or hundreds of databases across your enterprise, this solution will transform your patch management strategy! 🎯 πŸ”₯ The Challenge: Why Oracle Patching is Complex Before diving into the solution, let's understand why Oracle patching is so challenging: πŸ”— Multiple dependencies : OPatch versions, Oracle Home configurations, running processes ⚠️ Risk of corruption : Incorrect patch application can render databases unusable ⏰ Downtime requirements : Da...

Oracle RAC Switchover & Switchback: Step-by-Step Guide

 Ensuring business continuity requires regular Disaster Recovery (DR) drills. This guide covers the Switchover and Switchback process between Primary (DC) and Standby (DR) databases . Pre-checks Before Performing Switchover Before starting the activity, ensure there are no active sessions in the database. If any are found, share the session details with the application team, get their confirmation, and terminate the sessions. Primary Database Name: PRIMARY Standby Database Name: STANDBY  Identify Active Sessions set lines 999 pages 999 col machine for a30 col username for a30 col program for a30 compute sum of count on report break on report select inst_id,username,osuser,machine,program,status,count(1) "count" from gv$session where inst_id=1 and program like 'JDBC%' group by inst_id,username,osuser,machine,program,status order by 1,2; select inst_id,username,osuser,machine,program,status,count(1) "count" from gv$session where inst_id=2 and program lik...

Mastering Oracle RAC with SRVCTL Commands

Oracle Real Application Clusters (RAC) provide high availability, scalability, and manageability for databases. One of the most powerful tools for managing RAC databases is srvctl , a command-line utility that allows administrators to control various database services. This blog explores essential srvctl commands to help you efficiently manage Oracle RAC environments. 1. Checking Database Configuration and Status  List all available databases on the host:                  srvctl config database   Check the status of a specific database and its instances:                    srvctl status database -d <database_name>   Retrieve detailed status information about a database, including its instances and states:                    srvctl status database -d <database_name> -v 2. Stopping and Starting Databases   ...