04-07-2026, 03:58 AM
PostgreSQL with Barman Backup Setup Guide
Environment Setup
Architecture Overview
Step 1 - Install PostgreSQL
Run on: PostgreSQL Server (10.10.x.x)
Step 2 - Configure postgresql.conf
Run on: PostgreSQL Server (10.10.x.x)
Add the following lines:
Step 3 - Configure pg_hba.conf
Run on: PostgreSQL Server (10.10.x.x)
Add the following line:
Step 4 - Restart PostgreSQL
Run on: PostgreSQL Server (10.10.x.x)
Step 5 - Install Barman
Run on: Barman Backup Server (10.10.x.x)
Step 6 - SSH Key Setup
Run on: Barman Backup Server (10.10.x.x)
Generate SSH key on Barman server:
Copy key to PostgreSQL server:
Test SSH connection:
Step 7 - Configure Barman
Run on: Barman Backup Server (10.10.x.x)
Add the following:
Step 8 - Create Barman User in PostgreSQL
Run on: PostgreSQL Server (10.10.x.x)
Step 9 - Verify Setup
Run on: Barman Backup Server (10.10.x.x)
Expected Output:
Step 10 - Take First Backup
Run on: Barman Backup Server (10.10.x.x)
List backups:
Summary
Environment Setup
- PostgreSQL Database Server IP: 10.10.x.x
- Barman Backup Server IP: 10.10.x.x
- PostgreSQL Version: 14
- Barman Version: 3.11.1
- OS: Ubuntu 20.04 / 22.04
Architecture Overview
Code:
[ PostgreSQL Server 10.10.x.x ] ----WAL Archive----> [ Barman Server 10.10.x.x ]
(Database) (Backup)Step 1 - Install PostgreSQL
Run on: PostgreSQL Server (10.10.x.x)
Code:
sudo apt update
sudo apt install postgresql-14Step 2 - Configure postgresql.conf
Run on: PostgreSQL Server (10.10.x.x)
Code:
sudo nano /etc/postgresql/14/main/postgresql.confCode:
wal_level = replica
archive_mode = on
archive_command = 'rsync -a %p barman@BARMAN_IP:/var/lib/barman/main-db-server/incoming/%f'
max_wal_senders = 3
wal_keep_size = 256MBStep 3 - Configure pg_hba.conf
Run on: PostgreSQL Server (10.10.x.x)
Code:
sudo nano /etc/postgresql/14/main/pg_hba.confCode:
host all barman BARMAN_IP/32 md5Step 4 - Restart PostgreSQL
Run on: PostgreSQL Server (10.10.x.x)
Code:
sudo systemctl restart postgresql
sudo systemctl status postgresqlStep 5 - Install Barman
Run on: Barman Backup Server (10.10.x.x)
Code:
sudo apt update
sudo apt install barmanStep 6 - SSH Key Setup
Run on: Barman Backup Server (10.10.x.x)
Generate SSH key on Barman server:
Code:
sudo -i -u barman
ssh-keygen -t rsa -b 4096 -f ~/.ssh/id_rsa -N ""Copy key to PostgreSQL server:
Code:
ssh-copy-id -i ~/.ssh/id_rsa.pub postgres@POSTGRES_IPTest SSH connection:
Code:
ssh postgres@POSTGRES_IPStep 7 - Configure Barman
Run on: Barman Backup Server (10.10.x.x)
Code:
sudo nano /etc/barman.d/main-db-server.confCode:
[main-db-server]
description = "Main PostgreSQL Server"
conninfo = host=POSTGRES_IP user=barman password=YOUR_PASSWORD port=5432 dbname=postgres
ssh_command = ssh postgres@POSTGRES_IP
retention_policy_mode = auto
retention_policy = RECOVERY WINDOW OF 7 days
backup_method = rsync
archiver = on
compression = gzip
parallel_jobs = 4Step 8 - Create Barman User in PostgreSQL
Run on: PostgreSQL Server (10.10.x.x)
Code:
sudo -i -u postgres
psql -c "CREATE USER barman WITH REPLICATION LOGIN ENCRYPTED PASSWORD 'YOUR_PASSWORD';"
psql -c "ALTER USER barman WITH SUPERUSER;"Step 9 - Verify Setup
Run on: Barman Backup Server (10.10.x.x)
Code:
sudo -u barman barman check main-db-serverExpected Output:
Code:
Server main-db-server:
PostgreSQL: OK
superuser or standard user with backup privileges: OK
wal_level: OK
directories: OK
retention policy settings: OK
archive_mode: OK
archive_command: OK
continuous archiving: OK
ssh: OKStep 10 - Take First Backup
Run on: Barman Backup Server (10.10.x.x)
Code:
sudo -u barman barman backup main-db-serverList backups:
Code:
sudo -u barman barman list-backup main-db-serverSummary
- PostgreSQL Server - Sends WAL logs to Barman via rsync
- Barman Server - Receives and stores backups with 7 day retention
- SSH - Used for secure communication between both servers
- Always test restore procedure after setup

