Db2 installation RHEL 10.1

Installing IBM Db2 12.1.6 Community Edition on RHEL 10.1 – Setup and DBA / DevOps Tasks

In March 2025 I described the installation of Db2 12.1.1 on Oracle Linux 9. In the meantime IBM released several mod packs, and since Db2 12.1.4 Red Hat Enterprise Linux 10 is supported for single node and DPF deployments. In this blog post, we will install IBM Db2 12.1.6 Community Edition on a RHEL 10.1 virtual machine and set up a test server that can be used for development and testing.

After the base installation we create a Db2 instance and a database, allow remote connections and then walk through typical DBA and DevOps tasks: configuration, backup and recovery (including a point-in-time recovery), monitoring, maintenance and updating Db2 to a new mod pack.

Read More

0
pgBackRest Backup and Recovery

pgBackRest Backup and Recovery for an EPAS 18 EFM Cluster

In the previous posts we installed EDB Postgres Advanced Server 18 (EPAS) on RHEL 10, turned it into a high availability cluster with EDB Failover Manager (EFM). High availability is no replacement for backups – a DROP TABLE is replicated to the standby within milliseconds. So in this post we add pgBackRest, one of the most popular open source backup tools for Postgres. It fits an EFM cluster particularly well, because it knows both database nodes, finds the current primary by itself and can take the backups from the standby.

We build on the EFM cluster from the EFM post: lin8 (primary), lin7 (standby) and lin6 (witness). The witness also becomes the pgBackRest repository host. We take a full backup from the standby, add differential and block incremental backups, recover an “accidentally” dropped table with point-in-time recovery (PITR) and finally rebuild the standby from the backup repository instead of the primary.

pgBackRest or Barman? Both are mature, open source and supported by EDB for EPAS. Barman (see separate post) streams WAL with pg_receivewal and takes base backups with pg_basebackup. pgBackRest does not use pg_basebackup at all: it starts a backup with pg_backup_start(), copies and compresses the files itself with several parallel processes and stops the backup with pg_backup_stop(). WAL files are archived through archive_command. Its incremental backups are file or block based and independent of the incremental backup feature introduced in PostgreSQL 17, so no summarize_wal is required.

EPAS 16 and 17: All steps work the same way on EPAS 16 and 17. Only replace the version number in the paths (/usr/edb/as16, /var/lib/edb/as16/data) and in the service name (edb-as-16), and set pg-version-force in the pgBackRest configuration to the major version (chapter 3).

Architecture and Prerequisites

HostRoleIP addressSoftware
lin8Primary11.1.1.196EPAS 18, EFM 5.5, pgBackRest
lin7Standby11.1.1.195EPAS 18, EFM 5.5, pgBackRest
lin6Witness and pgBackRest repository host11.1.1.186EFM 5.5, pgBackRest
VIPAlways points to the current primary11.1.1.200–
RequirementDetails
EFM ClusterA healthy three node EFM cluster as described in the EFM post. efm cluster-status efm must show the standby in sync.
pgBackRestpgBackRest 2.60.1 (current version at the time of writing) from the PostgreSQL community (PGDG) repository. EDB supports pgBackRest for EPAS but uses the community packages.
EPELAlready enabled on all nodes in the EFM post (pgBackRest needs some libraries from EPEL).
Disk SpaceThe repository on lin6 needs room for the backups and WAL files of the retention period. Plan with at least 2–3 times the database size.
NetworkSSH (TCP port 22) from lin6 to lin8/lin7 and back. No additional database port is needed: pgBackRest connects to Postgres through the local socket on each node.
Root/Sudo AccessFull administrative privileges on all VMs.

How It Works

  • The repository host lin6 owns the backups and WAL archive in /var/lib/pgbackrest (OS user pgbackrest). Backups are started on lin6; pgBackRest connects via SSH to the database nodes as enterprisedb and starts a pgBackRest process there.
  • WAL archiving runs on the database nodes: archive_command calls pgbackrest archive-push, which sends the WAL files via SSH to lin6. Both nodes get the same configuration, so archiving continues automatically after a switchover or failover.
  • With backup from standby, pg_backup_start() and pg_backup_stop() run on the primary, but the data files are copied from the standby. This keeps the I/O load away from the primary.
  • Restores are started on the database node that receives the data. The restored cluster fetches the WAL files it needs with pgbackrest archive-get as restore_command.
  • A stanza is pgBackRest’s name for the configuration of one Postgres cluster. Our stanza is called epas18.

1. Install pgBackRest

1.1 Add the PGDG repository and install the package

pgBackRest is installed on all three nodes. We add the PGDG repository, import its GPG key once (otherwise dnf asks for it for every PGDG repository) and restrict the repository to pgBackRest and its dependencies – the client library and pgdg-libssh2, PGDG’s own build of libssh2 that pgBackRest requires. This way a later dnf update does not replace EDB packages with community builds of the same name:

# run as root on lin8, lin7 and lin6
dnf install -y https://download.postgresql.org/pub/repos/yum/reporpms/EL-10-x86_64/pgdg-redhat-repo-latest.noarch.rpm
rpm --import /etc/pki/rpm-gpg/PGDG-RPM-GPG-KEY-RHEL
# use the PGDG repositories only for pgBackRest and its dependencies
# (the first sed removes old filter lines, so the block can be run again)
sed -i '/^includepkgs=/d' /etc/yum.repos.d/pgdg-redhat-all.repo
sed -i '/^\[pgdg/a includepkgs=pgbackrest* pgdg-libssh2* libpq5*' /etc/yum.repos.d/pgdg-redhat-all.repo
dnf list pgbackrest
dnf -y install pgbackrest
pgbackrest version
Sample Output (click to expand):
[root@lin7 ~]# # run as root on lin8, lin7 and lin6
dnf install -y https://download.postgresql.org/pub/repos/yum/reporpms/EL-10-x86_64/pgdg-redhat-repo-latest.noarch.rpm
rpm --import /etc/pki/rpm-gpg/PGDG-RPM-GPG-KEY-RHEL
# use the PGDG repositories only for pgBackRest and its dependencies
# (the first sed removes old filter lines, so the block can be run again)
sed -i '/^includepkgs=/d' /etc/yum.repos.d/pgdg-redhat-all.repo
sed -i '/^\[pgdg/a includepkgs=pgbackrest* pgdg-libssh2* libpq5*' /etc/yum.repos.d/pgdg-redhat-all.repo
dnf list pgbackrest
dnf -y install pgbackrest
pgbackrest version
Updating Subscription Management repositories.
enterprisedb-enterprise                                                                        1.2 kB/s | 659  B     00:00
enterprisedb-enterprise-noarch                                                                 1.0 kB/s | 659  B     00:00
enterprisedb-enterprise-source                                                                 1.0 kB/s | 659  B     00:00
pgdg-redhat-repo-latest.noarch.rpm                                                             193 kB/s |  15 kB     00:00
Dependencies resolved.
===============================================================================================================================
 Package                          Architecture           Version                            Repository                    Size
===============================================================================================================================
Installing:
 pgdg-redhat-repo                 noarch                 42.0-71.rhel10PGDG                 @commandline                  15 k

Transaction Summary
===============================================================================================================================
Install  1 Package

Total size: 15 k
Installed size: 21 k
Downloading Packages:
Running transaction check
Transaction check succeeded.
Running transaction test
Transaction test succeeded.
Running transaction
  Preparing        :                                                                                                       1/1
  Installing       : pgdg-redhat-repo-42.0-71.rhel10PGDG.noarch                                                            1/1
  Running scriptlet: pgdg-redhat-repo-42.0-71.rhel10PGDG.noarch                                                            1/1
Installed products updated.

Installed:
  pgdg-redhat-repo-42.0-71.rhel10PGDG.noarch

Complete!
Updating Subscription Management repositories.
PostgreSQL common RPMs for RHEL / Rocky Linux / AlmaLinux 10.3 - x86_64                        5.1 kB/s | 659  B     00:00
PostgreSQL common RPMs for RHEL / Rocky Linux / AlmaLinux 10.3 - x86_64                        2.4 MB/s | 2.4 kB     00:00
Importing GPG key 0x08B40D20:
 Userid     : "PostgreSQL RPM Repository <pgsql-pkg-yum@lists.postgresql.org>"
 Fingerprint: D4BF 08AE 67A0 B4C7 A1DB CCD2 40BC A2B4 08B4 0D20
 From       : /etc/pki/rpm-gpg/PGDG-RPM-GPG-KEY-RHEL
Is this ok [y/N]: y
PostgreSQL common RPMs for RHEL / Rocky Linux / AlmaLinux 10.3 - x86_64                        340 kB/s |  85 kB     00:00
PostgreSQL 19 for RHEL / Rocky Linux / AlmaLinux 10.3 - x86_64                                 5.0 kB/s | 659  B     00:00
PostgreSQL 19 for RHEL / Rocky Linux / AlmaLinux 10.3 - x86_64                                 2.4 MB/s | 2.4 kB     00:00
Importing GPG key 0x08B40D20:
 Userid     : "PostgreSQL RPM Repository <pgsql-pkg-yum@lists.postgresql.org>"
 Fingerprint: D4BF 08AE 67A0 B4C7 A1DB CCD2 40BC A2B4 08B4 0D20
 From       : /etc/pki/rpm-gpg/PGDG-RPM-GPG-KEY-RHEL
Is this ok [y/N]: y
PostgreSQL 19 for RHEL / Rocky Linux / AlmaLinux 10.3 - x86_64                                 257 kB/s |  56 kB     00:00
PostgreSQL 18 for RHEL / Rocky Linux / AlmaLinux 10.3 - x86_64                                 5.2 kB/s | 659  B     00:00
PostgreSQL 18 for RHEL / Rocky Linux / AlmaLinux 10.3 - x86_64                                 2.4 MB/s | 2.4 kB     00:00
Importing GPG key 0x08B40D20:
 Userid     : "PostgreSQL RPM Repository <pgsql-pkg-yum@lists.postgresql.org>"
 Fingerprint: D4BF 08AE 67A0 B4C7 A1DB CCD2 40BC A2B4 08B4 0D20
 From       : /etc/pki/rpm-gpg/PGDG-RPM-GPG-KEY-RHEL
Is this ok [y/N]: y
PostgreSQL 18 for RHEL / Rocky Linux / AlmaLinux 10.3 - x86_64                                 338 kB/s |  72 kB     00:00
PostgreSQL 17 for RHEL / Rocky Linux / AlmaLinux 10.3 - x86_64                                 5.1 kB/s | 659  B     00:00
PostgreSQL 17 for RHEL / Rocky Linux / AlmaLinux 10.3 - x86_64                                 2.4 MB/s | 2.4 kB     00:00
Importing GPG key 0x08B40D20:
 Userid     : "PostgreSQL RPM Repository <pgsql-pkg-yum@lists.postgresql.org>"
 Fingerprint: D4BF 08AE 67A0 B4C7 A1DB CCD2 40BC A2B4 08B4 0D20
 From       : /etc/pki/rpm-gpg/PGDG-RPM-GPG-KEY-RHEL
Is this ok [y/N]: y
PostgreSQL 17 for RHEL / Rocky Linux / AlmaLinux 10.3 - x86_64                                 320 kB/s |  72 kB     00:00
PostgreSQL 16 for RHEL / Rocky Linux / AlmaLinux 10.3 - x86_64                                 5.0 kB/s | 659  B     00:00
PostgreSQL 16 for RHEL / Rocky Linux / AlmaLinux 10.3 - x86_64                                 2.4 MB/s | 2.4 kB     00:00
Importing GPG key 0x08B40D20:
 Userid     : "PostgreSQL RPM Repository <pgsql-pkg-yum@lists.postgresql.org>"
 Fingerprint: D4BF 08AE 67A0 B4C7 A1DB CCD2 40BC A2B4 08B4 0D20
 From       : /etc/pki/rpm-gpg/PGDG-RPM-GPG-KEY-RHEL
Is this ok [y/N]: y
PostgreSQL 16 for RHEL / Rocky Linux / AlmaLinux 10.3 - x86_64                                 306 kB/s |  71 kB     00:00
PostgreSQL 15 for RHEL / Rocky Linux / AlmaLinux 10.3 - x86_64                                 5.0 kB/s | 659  B     00:00
PostgreSQL 15 for RHEL / Rocky Linux / AlmaLinux 10.3 - x86_64                                 2.4 MB/s | 2.4 kB     00:00
Importing GPG key 0x08B40D20:
 Userid     : "PostgreSQL RPM Repository <pgsql-pkg-yum@lists.postgresql.org>"
 Fingerprint: D4BF 08AE 67A0 B4C7 A1DB CCD2 40BC A2B4 08B4 0D20
 From       : /etc/pki/rpm-gpg/PGDG-RPM-GPG-KEY-RHEL
Is this ok [y/N]: y
PostgreSQL 15 for RHEL / Rocky Linux / AlmaLinux 10.3 - x86_64                                 305 kB/s |  68 kB     00:00
PostgreSQL 14 for RHEL / Rocky Linux / AlmaLinux 10.3 - x86_64                                 5.2 kB/s | 659  B     00:00
PostgreSQL 14 for RHEL / Rocky Linux / AlmaLinux 10.3 - x86_64                                 2.4 MB/s | 2.4 kB     00:00
Importing GPG key 0x08B40D20:
 Userid     : "PostgreSQL RPM Repository <pgsql-pkg-yum@lists.postgresql.org>"
 Fingerprint: D4BF 08AE 67A0 B4C7 A1DB CCD2 40BC A2B4 08B4 0D20
 From       : /etc/pki/rpm-gpg/PGDG-RPM-GPG-KEY-RHEL
Is this ok [y/N]: y
PostgreSQL 14 for RHEL / Rocky Linux / AlmaLinux 10.3 - x86_64                                 300 kB/s |  67 kB     00:00
Available Packages
pgbackrest.x86_64                                       2.60.1-1PGDG.rhel10.3                                       pgdg-common
Updating Subscription Management repositories.
Last metadata expiration check: 0:00:06 ago on Sat 28 Nov 2026 07:51:05 AM CET.
Dependencies resolved.
===============================================================================================================================
 Package                      Architecture           Version                                 Repository                   Size
===============================================================================================================================
Installing:
 pgbackrest                   x86_64                 2.60.1-1PGDG.rhel10.3                   pgdg-common                 586 k
Installing dependencies:
 pgdg-libssh2                 x86_64                 1.11.1-1PGDG.rhel10.3                   pgdg-common                 143 k

Transaction Summary
===============================================================================================================================
Install  2 Packages

Total download size: 729 k
Installed size: 1.7 M
Downloading Packages:
(1/2): pgdg-libssh2-1.11.1-1PGDG.rhel10.3.x86_64.rpm                                           869 kB/s | 143 kB     00:00
(2/2): pgbackrest-2.60.1-1PGDG.rhel10.3.x86_64.rpm                                             2.8 MB/s | 586 kB     00:00
-------------------------------------------------------------------------------------------------------------------------------
Total                                                                                          3.5 MB/s | 729 kB     00:00
Running transaction check
Transaction check succeeded.
Running transaction test
Transaction test succeeded.
Running transaction
  Preparing        :                                                                                                       1/1
  Installing       : pgdg-libssh2-1.11.1-1PGDG.rhel10.3.x86_64                                                             1/2
  Running scriptlet: pgbackrest-2.60.1-1PGDG.rhel10.3.x86_64                                                               2/2
Creating group 'postgres' with GID 26.
Creating user 'postgres' (PostgreSQL Server) with UID 26 and GID 26.

  Installing       : pgbackrest-2.60.1-1PGDG.rhel10.3.x86_64                                                               2/2
  Running scriptlet: pgbackrest-2.60.1-1PGDG.rhel10.3.x86_64                                                               2/2
Installed products updated.

Installed:
  pgbackrest-2.60.1-1PGDG.rhel10.3.x86_64                       pgdg-libssh2-1.11.1-1PGDG.rhel10.3.x86_64

Complete!
pgBackRest 2.60.1
[root@lin7 ~]#

The package creates the directories /var/lib/pgbackrest (repository), /var/log/pgbackrest (logs) and /var/spool/pgbackrest (asynchronous archiving), all owned by postgres. The OS user postgres is created by the package as well but is not used in our setup.

1.2 Users and directory permissions

On the repository host we create the dedicated OS user pgbackrest. EDB and the pgBackRest documentation recommend not to use postgres or enterprisedb as repository owner. On the database nodes, pgBackRest runs as the cluster owner enterprisedb:

# run as root on lin6
id pgbackrest &>/dev/null || useradd -m -s /bin/bash pgbackrest
chown -R pgbackrest:pgbackrest /var/lib/pgbackrest /var/log/pgbackrest /var/spool/pgbackrest
chmod 750 /var/lib/pgbackrest
id pgbackrest
ls -ld /var/lib/pgbackrest /var/log/pgbackrest
# run as root on lin8 and lin7
chown -R enterprisedb:enterprisedb /var/lib/pgbackrest /var/log/pgbackrest /var/spool/pgbackrest
ls -ld /var/lib/pgbackrest /var/log/pgbackrest /var/spool/pgbackrest

2. Passwordless SSH

pgBackRest needs SSH with public key authentication in both directions: pgbackrest@lin6 → enterprisedb@lin8/lin7 for backups and enterprisedb@lin8/lin7 → pgbackrest@lin6 for archiving and restores. The obvious tool would be ssh-copy-id, but it does not work for enterprisedb: the EPAS packages create the account without a password, so it is locked for password logins. Instead, we install the public keys via root. You will be asked for the root password of the remote host.

2.1 From the repository host to the database nodes

# run as root on lin6
su - pgbackrest -c "[ -f ~/.ssh/id_ed25519 ] || ssh-keygen -t ed25519 -N '' -f ~/.ssh/id_ed25519"
for h in lin8 lin7; do
  cat ~pgbackrest/.ssh/id_ed25519.pub | ssh root@$h '
    install -d -m 700 -o enterprisedb -g enterprisedb ~enterprisedb/.ssh &&
    cat >> ~enterprisedb/.ssh/authorized_keys &&
    chown enterprisedb:enterprisedb ~enterprisedb/.ssh/authorized_keys &&
    chmod 600 ~enterprisedb/.ssh/authorized_keys &&
    restorecon -R ~enterprisedb/.ssh'
done
# test: must print the host names without a password prompt
su - pgbackrest -c "ssh -o StrictHostKeyChecking=accept-new enterprisedb@lin8 hostname"
su - pgbackrest -c "ssh -o StrictHostKeyChecking=accept-new enterprisedb@lin7 hostname"

2.2 From the database nodes to the repository host

# run as root on lin8 and lin7
su - enterprisedb -c "[ -f ~/.ssh/id_ed25519 ] || ssh-keygen -t ed25519 -N '' -f ~/.ssh/id_ed25519"
cat ~enterprisedb/.ssh/id_ed25519.pub | ssh root@lin6 '
  install -d -m 700 -o pgbackrest -g pgbackrest ~pgbackrest/.ssh &&
  cat >> ~pgbackrest/.ssh/authorized_keys &&
  chown pgbackrest:pgbackrest ~pgbackrest/.ssh/authorized_keys &&
  chmod 600 ~pgbackrest/.ssh/authorized_keys &&
  restorecon -R ~pgbackrest/.ssh'
# test: must print "lin6" without a password prompt
su - enterprisedb -c "ssh -o StrictHostKeyChecking=accept-new pgbackrest@lin6 hostname"

-o StrictHostKeyChecking=accept-new stores the host key of the remote host on the first connection. Without it, the first archive-push would fail with Host key verification failed, because nobody can answer the prompt.

3. Configure pgBackRest

pgBackRest reads /etc/pgbackrest/pgbackrest.conf. If this file does not exist, it falls back to the old location /etc/pgbackrest.conf, which the package may have created. To avoid confusion we move the old file away and use only the new location.

3.1 Check the socket directory

pgBackRest connects to Postgres through the Unix socket of the local node. EPAS uses port 5444 and the database edb instead of the community defaults 5432 and postgres, and its socket directory may differ from the default that pgBackRest expects. Check it on lin8 and use the first directory in the list for pg1-socket-path below (default for EPAS: /tmp):

# run as root on lin8
su - enterprisedb -c "psql -d edb -Atc 'show unix_socket_directories' -c 'show port'"
Sample Output (click to expand):
[root@lin8 ~]# # run as root on lin8
su - enterprisedb -c "psql -d edb -Atc 'show unix_socket_directories' -c 'show port'"
/tmp
5444
[root@lin8 ~]#

3.2 Repository host lin6

# run as root on lin6
[ -f /etc/pgbackrest.conf ] && mv /etc/pgbackrest.conf /etc/pgbackrest.conf.orig
mkdir -p /etc/pgbackrest
cat > /etc/pgbackrest/pgbackrest.conf << 'EOF'
[global]
repo1-path=/var/lib/pgbackrest
repo1-retention-full=2
repo1-bundle=y
repo1-block=y
compress-type=zst
process-max=2
start-fast=y
backup-standby=prefer
log-level-console=info
log-level-file=detail

[epas18]
pg-version-force=18
pg1-host=lin8
pg1-host-user=enterprisedb
pg1-path=/var/lib/edb/as18/data
pg1-port=5444
pg1-socket-path=/tmp
pg1-database=edb
pg2-host=lin7
pg2-host-user=enterprisedb
pg2-path=/var/lib/edb/as18/data
pg2-port=5444
pg2-socket-path=/tmp
pg2-database=edb
EOF
chown pgbackrest:pgbackrest /etc/pgbackrest/pgbackrest.conf
chmod 640 /etc/pgbackrest/pgbackrest.conf
OptionMeaning
repo1-pathDirectory of the repository on lin6.
repo1-retention-full=2Keep two full backups (plus the differential and incremental backups and the WAL files that belong to them). Older backups are expired automatically after each successful backup.
repo1-bundle / repo1-blockBundle small files into larger repository files and enable block incremental backups: changed files are split into blocks and only the changed blocks are stored. repo1-block requires repo1-bundle.
compress-type=zstZstandard compression – faster and better than the default gz.
process-max=2Number of parallel processes for compression and transfer. Increase it for large databases, but not so far that the database host suffers.
start-fast=yRequest an immediate checkpoint at backup start instead of waiting for the next regular checkpoint.
backup-standby=preferCopy the files from the standby if one is available, otherwise from the primary. With y the backup fails if no standby is available.
pg-version-force=18Required for EPAS: EPAS adds fields to pg_control, so its layout differs from community PostgreSQL and pgBackRest reports calculated pg_control checksum does not match expected value. With a forced version, pgBackRest searches the file for the checksum. Set it on all nodes, to the EPAS major version.
pg1-* / pg2-*Both database nodes of the EFM cluster. pgBackRest determines which one is the primary on every run, so no change is necessary after a switchover or failover.

3.3 Database nodes lin8 and lin7

Both nodes get the same file. archive-async=y enables asynchronous archiving: archive_command returns quickly, and a background process pushes the WAL files in parallel and with a persistent SSH connection.

# run as root on lin8 and lin7
[ -f /etc/pgbackrest.conf ] && mv /etc/pgbackrest.conf /etc/pgbackrest.conf.orig
mkdir -p /etc/pgbackrest
cat > /etc/pgbackrest/pgbackrest.conf << 'EOF'
[global]
repo1-host=lin6
repo1-host-user=pgbackrest
archive-async=y
spool-path=/var/spool/pgbackrest
compress-type=zst
process-max=2
log-level-console=info
log-level-file=detail

[epas18]
pg-version-force=18
pg1-path=/var/lib/edb/as18/data
pg1-port=5444
pg1-socket-path=/tmp
pg1-database=edb
EOF
chown enterprisedb:enterprisedb /etc/pgbackrest/pgbackrest.conf
chmod 640 /etc/pgbackrest/pgbackrest.conf

4. Create the Stanza

stanza-create initializes the repository for the cluster. It connects to both nodes, identifies the primary and stores the system identifier and the Postgres version. Always run pgBackRest as pgbackrest on lin6 and as enterprisedb on the database nodes, never as root.

# run as root on lin6
su - pgbackrest -c "pgbackrest --stanza=epas18 stanza-create"
Sample Output (click to expand):
[root@lin6 ~]# # run as root on lin6
su - pgbackrest -c "pgbackrest --stanza=epas18 stanza-create"
2026-11-28 08:10:43.402 P00   INFO: stanza-create command begin 2.60.1: --exec-id=10209-58e31a57 --log-level-console=info --log-level-file=detail --pg1-database=edb --pg2-database=edb --pg1-host=lin8 --pg2-host=lin7 --pg1-host-user=enterprisedb --pg2-host-user=enterprisedb --pg1-path=/var/lib/edb/as18/data --pg2-path=/var/lib/edb/as18/data --pg1-port=5444 --pg2-port=5444 --pg1-socket-path=/tmp --pg2-socket-path=/tmp --pg-version-force=18 --repo1-path=/var/lib/pgbackrest --stanza=epas18
2026-11-28 08:10:44.659 P00   INFO: stanza-create for stanza 'epas18' on repo1
2026-11-28 08:10:44.909 P00   INFO: stanza-create command end: completed successfully (1511ms)
[root@lin6 ~]#

5. Enable WAL Archiving

5.1 Set archive_mode and archive_command

We set the parameters with ALTER SYSTEM on both database nodes. On the standby the command only writes postgresql.auto.conf; a standby with archive_mode = on does not archive as long as it is in recovery, but it will start archiving as soon as it is promoted.

# run as root on lin8 and lin7
su - enterprisedb -c 'psql -d edb -v ON_ERROR_STOP=1' << 'EOF'
ALTER SYSTEM SET archive_mode = 'on';
ALTER SYSTEM SET archive_command = 'pgbackrest --stanza=epas18 archive-push %p';
SELECT pg_reload_conf();
SELECT name, setting, pending_restart FROM pg_settings
WHERE name IN ('archive_mode', 'archive_command');
EOF
Sample Output (click to expand):
[root@lin8 ~]# # run as root on lin8 and lin7
su - enterprisedb -c 'psql -d edb -v ON_ERROR_STOP=1' << 'EOF'
ALTER SYSTEM SET archive_mode = 'on';
ALTER SYSTEM SET archive_command = 'pgbackrest --stanza=epas18 archive-push %p';
SELECT pg_reload_conf();
SELECT name, setting, pending_restart FROM pg_settings
WHERE name IN ('archive_mode', 'archive_command');
EOF
ALTER SYSTEM
ALTER SYSTEM
 pg_reload_conf
----------------
 t
(1 row)

      name       |  setting   | pending_restart
-----------------+------------+-----------------
 archive_command | (disabled) | f
 archive_mode    | off        | f
(2 rows)

[root@lin8 ~]#

5.2 Restart both nodes with two EFM switchovers

archive_command is active after the reload, but archive_mode requires a restart. Restarting the primary behind EFM’s back is not a good idea – the agent would treat it as a database failure. Instead we use two planned switchovers from the EFM post: a switchover promotes the standby and restarts the old primary as a standby. After two switchovers both nodes have been restarted and lin8 is the primary again. Each switchover causes only a few seconds of downtime.

# run as root on any node
/usr/edb/efm-5.5/bin/efm promote efm -switchover   # lin7 becomes primary, lin8 is restarted as standby
sleep 10
/usr/edb/efm-5.5/bin/efm cluster-status efm
# wait until the standby is in sync, then switch back
/usr/edb/efm-5.5/bin/efm promote efm -switchover   # lin8 becomes primary, lin7 is restarted as standby
sleep 10
/usr/edb/efm-5.5/bin/efm cluster-status efm
Sample Output (click to expand):
[root@lin6 ~]# # run as root on any node
/usr/edb/efm-5.5/bin/efm promote efm -switchover   # lin7 becomes primary, lin8 is restarted as standby
sleep 10
/usr/edb/efm-5.5/bin/efm cluster-status efm
# wait until the standby is in sync, then switch back
/usr/edb/efm-5.5/bin/efm promote efm -switchover   # lin8 becomes primary, lin7 is restarted as standby
sleep 10
/usr/edb/efm-5.5/bin/efm cluster-status efm
Promote/switchover command accepted by local agent. Proceeding with promotion and will reconfigure original primary. Run the 'cluster-status' command for information about the new cluster state.
Cluster Status: efm

        Agent Type  Address              DB       VIP
        ----------------------------------------------------------------
        Witness     11.1.1.186           N/A      11.1.1.200
        Primary     11.1.1.195           UP       11.1.1.200*
        Standby     11.1.1.196           UP       11.1.1.200

Allowed node host list:
        11.1.1.196 11.1.1.195 11.1.1.186

Membership coordinator: 11.1.1.196

Standby priority host list:
        11.1.1.196

Promote Status:

        DB Type     Address              WAL Received LSN   WAL Replayed LSN   Info
        ---------------------------------------------------------------------------
        Primary     11.1.1.195                              0/80001E0
        Standby     11.1.1.196           0/80001E0          0/80001E0

        Standby database(s) in sync with primary. It is safe to promote.
Promote/switchover command accepted by local agent. Proceeding with promotion and will reconfigure original primary. Run the 'cluster-status' command for information about the new cluster state.
Cluster Status: efm

        Agent Type  Address              DB       VIP
        ----------------------------------------------------------------
        Witness     11.1.1.186           N/A      11.1.1.200
        Standby     11.1.1.195           UP       11.1.1.200
        Primary     11.1.1.196           UP       11.1.1.200*

Allowed node host list:
        11.1.1.196 11.1.1.195 11.1.1.186

Membership coordinator: 11.1.1.196

Standby priority host list:
        11.1.1.195

Promote Status:

        DB Type     Address              WAL Received LSN   WAL Replayed LSN   Info
        ---------------------------------------------------------------------------
        Primary     11.1.1.196                              0/90001E0
        Standby     11.1.1.195           0/90001E0          0/90001E0

        Standby database(s) in sync with primary. It is safe to promote.
[root@lin6 ~]#

# run as root on lin8 and lin7: archive_mode must be "on", pending_restart "f"
su - enterprisedb -c "psql -d edb -c \"SELECT name, setting, pending_restart FROM pg_settings WHERE name = 'archive_mode';\""
Sample Output (click to expand)
[root@lin8 ~]# # run as root on lin8 and lin7: archive_mode must be "on", pending_restart "f"
su - enterprisedb -c "psql -d edb -c \"SELECT name, setting, pending_restart FROM pg_settings WHERE name = 'archive_mode';\""
     name     | setting | pending_restart
--------------+---------+-----------------
 archive_mode | on      | f
(1 row)

[root@lin8 ~]#
[root@lin7 ~]# # run as root on lin8 and lin7: archive_mode must be "on", pending_restart "f"
su - enterprisedb -c "psql -d edb -c \"SELECT name, setting, pending_restart FROM pg_settings WHERE name = 'archive_mode';\""
     name     | setting | pending_restart
--------------+---------+-----------------
 archive_mode | on      | f
(1 row)

[root@lin7 ~]#

5.3 Check the configuration

The check command verifies the configuration of both nodes, forces a WAL switch on the primary and waits until the WAL file has arrived in the repository:

# run as root on lin6
su - pgbackrest -c "pgbackrest --stanza=epas18 check"
Sample Output (click to expand):
[root@lin6 ~]# # run as root on lin6
su - pgbackrest -c "pgbackrest --stanza=epas18 check"
2026-11-28 08:21:18.502 P00   INFO: check command begin 2.60.1: --backup-standby=prefer --exec-id=12469-0a49e6c2 --log-level-console=info --log-level-file=detail --pg1-database=edb --pg2-database=edb --pg1-host=lin8 --pg2-host=lin7 --pg1-host-user=enterprisedb --pg2-host-user=enterprisedb --pg1-path=/var/lib/edb/as18/data --pg2-path=/var/lib/edb/as18/data --pg1-port=5444 --pg2-port=5444 --pg1-socket-path=/tmp --pg2-socket-path=/tmp --pg-version-force=18 --repo1-path=/var/lib/pgbackrest --stanza=epas18
2026-11-28 08:21:19.923 P00   INFO: check repo1 (standby)
2026-11-28 08:21:19.924 P00   INFO: switch wal not performed because this is a standby
2026-11-28 08:21:19.924 P00   INFO: check repo1 configuration (primary)
2026-11-28 08:21:19.981 P00   INFO: check repo1 archive for WAL (primary)
2026-11-28 08:21:21.095 P00   INFO: WAL segment 000000070000000000000009 successfully archived to '/var/lib/pgbackrest/archive/epas18/18-1/0000000700000000/000000070000000000000009-bb1004f4342630c7a6afeb67f438edddbf8a191d.zst' on repo1
2026-11-28 08:21:21.298 P00   INFO: check command end: completed successfully (2799ms)
[root@lin6 ~]#

6. Backups

6.1 Create some test data

A small table records in which phase each row was inserted, so we can verify the restores later:

# run as root on lin8
su - enterprisedb -c 'psql -d edb -v ON_ERROR_STOP=1' << 'EOF'
CREATE TABLE pgbr_test (id integer GENERATED ALWAYS AS IDENTITY, phase varchar2(30), created timestamp DEFAULT clock_timestamp());
INSERT INTO pgbr_test (phase) SELECT 'before full backup' FROM generate_series(1, 1000);
EOF

6.2 Full backup from the standby

# run as root on lin6
su - pgbackrest -c "pgbackrest --stanza=epas18 --type=full backup"
Sample Output (click to expand):
[root@lin6 ~]# # run as root on lin6
su - pgbackrest -c "pgbackrest --stanza=epas18 --type=full backup"
2026-11-28 08:29:17.597 P00   INFO: backup command begin 2.60.1: --backup-standby=prefer --compress-type=zst --exec-id=12634-b9d7a7f8 --log-level-console=info --log-level-file=detail --pg1-database=edb --pg2-database=edb --pg1-host=lin8 --pg2-host=lin7 --pg1-host-user=enterprisedb --pg2-host-user=enterprisedb --pg1-path=/var/lib/edb/as18/data --pg2-path=/var/lib/edb/as18/data --pg1-port=5444 --pg2-port=5444 --pg1-socket-path=/tmp --pg2-socket-path=/tmp --pg-version-force=18 --process-max=2 --repo1-block --repo1-bundle --repo1-path=/var/lib/pgbackrest --repo1-retention-full=2 --stanza=epas18 --start-fast --type=full
2026-11-28 08:29:18.941 P00   INFO: execute backup start: backup begins after the requested immediate checkpoint completes
2026-11-28 08:29:19.088 P00   INFO: backup start archive = 00000007000000000000000B, lsn = 0/B000028
2026-11-28 08:29:19.088 P00   INFO: wait for replay on the standby to reach 0/B000028
2026-11-28 08:29:19.254 P00   INFO: replay on the standby reached 0/B000028
2026-11-28 08:29:19.254 P00   INFO: check archive for prior segment 00000007000000000000000A
2026-11-28 08:29:23.539 P00   INFO: execute backup stop and wait for all WAL segments to archive
2026-11-28 08:29:23.572 P00   INFO: backup stop archive = 00000007000000000000000B, lsn = 0/B000158
2026-11-28 08:29:23.577 P00   INFO: check archive for segment(s) 00000007000000000000000B:00000007000000000000000B
2026-11-28 08:29:24.718 P00   INFO: new backup label = 20261128-082918F
2026-11-28 08:29:24.777 P00   INFO: full backup size = 58.1MB, file total = 1658
2026-11-28 08:29:24.777 P00   INFO: backup command end: completed successfully (7183ms)
2026-11-28 08:29:24.777 P00   INFO: expire command begin 2.60.1: --exec-id=12634-b9d7a7f8 --log-level-console=info --log-level-file=detail --repo1-path=/var/lib/pgbackrest --repo1-retention-full=2 --stanza=epas18
2026-11-28 08:29:24.777 P00   INFO: expire command end: completed successfully (0ms)
[root@lin6 ~]#

The log shows that the backup was started on the primary lin8, waited until the standby lin7 had replayed the start position of the backup and then copied the files from lin7. Only the few files that are not replicated to the standby are read from lin8. If data checksums are enabled (the default for new clusters since version 18), pgBackRest also validates the page checksums of every data file during the backup and reports damaged pages as warnings.

6.3 Differential and incremental backups

pgBackRest has three backup types: full, differential (changes since the last full backup) and incremental (changes since the last backup of any type). Without --type, an incremental backup is taken – or a full backup if none exists yet.

# run as root on lin8
su - enterprisedb -c "psql -d edb -c \"INSERT INTO pgbr_test (phase) SELECT 'after full backup' FROM generate_series(1, 500);\""
# run as root on lin6
su - pgbackrest -c "pgbackrest --stanza=epas18 --type=diff backup"
Sample Output (click to expand):
[root@lin6 ~]# # run as root on lin6
su - pgbackrest -c "pgbackrest --stanza=epas18 --type=diff backup"
2026-11-28 08:31:25.356 P00   INFO: backup command begin 2.60.1: --backup-standby=prefer --compress-type=zst --exec-id=12890-a11f17d5 --log-level-console=info --log-level-file=detail --pg1-database=edb --pg2-database=edb --pg1-host=lin8 --pg2-host=lin7 --pg1-host-user=enterprisedb --pg2-host-user=enterprisedb --pg1-path=/var/lib/edb/as18/data --pg2-path=/var/lib/edb/as18/data --pg1-port=5444 --pg2-port=5444 --pg1-socket-path=/tmp --pg2-socket-path=/tmp --pg-version-force=18 --process-max=2 --repo1-block --repo1-bundle --repo1-path=/var/lib/pgbackrest --repo1-retention-full=2 --stanza=epas18 --start-fast --type=diff
2026-11-28 08:31:26.871 P00   INFO: last backup label = 20261128-082918F, version = 2.60.1
2026-11-28 08:31:26.871 P00   INFO: execute backup start: backup begins after the requested immediate checkpoint completes
2026-11-28 08:31:26.958 P00   INFO: backup start archive = 00000007000000000000000D, lsn = 0/D000028
2026-11-28 08:31:26.958 P00   INFO: wait for replay on the standby to reach 0/D000028
2026-11-28 08:31:27.085 P00   INFO: replay on the standby reached 0/D000028
2026-11-28 08:31:27.085 P00   INFO: check archive for prior segment 00000007000000000000000C
2026-11-28 08:31:30.012 P00   INFO: execute backup stop and wait for all WAL segments to archive
2026-11-28 08:31:30.033 P00   INFO: backup stop archive = 00000007000000000000000D, lsn = 0/D000120
2026-11-28 08:31:30.038 P00   INFO: check archive for segment(s) 00000007000000000000000D:00000007000000000000000D
2026-11-28 08:31:31.279 P00   INFO: new backup label = 20261128-082918F_20261128-083126D
2026-11-28 08:31:31.339 P00   INFO: diff backup size = 569.4KB, file total = 1658
2026-11-28 08:31:31.339 P00   INFO: backup command end: completed successfully (5986ms)
2026-11-28 08:31:31.339 P00   INFO: expire command begin 2.60.1: --exec-id=12890-a11f17d5 --log-level-console=info --log-level-file=detail --repo1-path=/var/lib/pgbackrest --repo1-retention-full=2 --stanza=epas18
2026-11-28 08:31:31.340 P00   INFO: expire command end: completed successfully (1ms)
[root@lin6 ~]#

# run as root on lin8
su - enterprisedb -c "psql -d edb -c \"INSERT INTO pgbr_test (phase) SELECT 'after diff backup' FROM generate_series(1, 200);\""
# run as root on lin6
su - pgbackrest -c "pgbackrest --stanza=epas18 --type=incr backup"
Sample Output (click to expand):
[root@lin6 ~]# # run as root on lin6
su - pgbackrest -c "pgbackrest --stanza=epas18 --type=incr backup"
2026-11-28 08:32:10.998 P00   INFO: backup command begin 2.60.1: --backup-standby=prefer --compress-type=zst --exec-id=13116-8964532d --log-level-console=info --log-level-file=detail --pg1-database=edb --pg2-database=edb --pg1-host=lin8 --pg2-host=lin7 --pg1-host-user=enterprisedb --pg2-host-user=enterprisedb --pg1-path=/var/lib/edb/as18/data --pg2-path=/var/lib/edb/as18/data --pg1-port=5444 --pg2-port=5444 --pg1-socket-path=/tmp --pg2-socket-path=/tmp --pg-version-force=18 --process-max=2 --repo1-block --repo1-bundle --repo1-path=/var/lib/pgbackrest --repo1-retention-full=2 --stanza=epas18 --start-fast --type=incr
2026-11-28 08:32:12.307 P00   INFO: last backup label = 20261128-082918F_20261128-083126D, version = 2.60.1
2026-11-28 08:32:12.307 P00   INFO: execute backup start: backup begins after the requested immediate checkpoint completes
2026-11-28 08:32:12.380 P00   INFO: backup start archive = 00000007000000000000000F, lsn = 0/F000028
2026-11-28 08:32:12.380 P00   INFO: wait for replay on the standby to reach 0/F000028
2026-11-28 08:32:12.500 P00   INFO: replay on the standby reached 0/F000028
2026-11-28 08:32:12.500 P00   INFO: check archive for prior segment 00000007000000000000000E
2026-11-28 08:32:14.955 P00   INFO: execute backup stop and wait for all WAL segments to archive
2026-11-28 08:32:14.972 P00   INFO: backup stop archive = 00000007000000000000000F, lsn = 0/F000120
2026-11-28 08:32:14.977 P00   INFO: check archive for segment(s) 00000007000000000000000F:00000007000000000000000F
2026-11-28 08:32:16.204 P00   INFO: new backup label = 20261128-082918F_20261128-083212I
2026-11-28 08:32:16.263 P00   INFO: incr backup size = 635.6KB, file total = 1659
2026-11-28 08:32:16.263 P00   INFO: backup command end: completed successfully (5269ms)
2026-11-28 08:32:16.263 P00   INFO: expire command begin 2.60.1: --exec-id=13116-8964532d --log-level-console=info --log-level-file=detail --repo1-path=/var/lib/pgbackrest --repo1-retention-full=2 --stanza=epas18
2026-11-28 08:32:16.264 P00   INFO: expire command end: completed successfully (1ms)
[root@lin6 ~]#

6.4 Inspect the repository

# run as root on lin6
su - pgbackrest -c "pgbackrest --stanza=epas18 info"
# details of a single backup: enter a label from the info output above
{ read -r -p "Backup label: " LABEL < /dev/tty
  su - pgbackrest -c "pgbackrest --stanza=epas18 --set=$LABEL info"; }
Sample Output (click to expand):
[root@lin6 ~]# # run as root on lin6
su - pgbackrest -c "pgbackrest --stanza=epas18 info"
# details of a single backup: enter a label from the info output above
{ read -r -p "Backup label: " LABEL < /dev/tty
  su - pgbackrest -c "pgbackrest --stanza=epas18 --set=$LABEL info"; }
stanza: epas18
    status: ok
    cipher: none

    db (current)
        wal archive min/max (18): 000000030000000000000005/00000007000000000000000F

        full backup: 20261128-082918F
            timestamp start/stop: 2026-11-28 08:29:18+01 / 2026-11-28 08:29:23+01
            wal start/stop: 00000007000000000000000B / 00000007000000000000000B
            database size: 58.1MB, database backup size: 58.1MB
            repo1: backup size: 8.3MB

        diff backup: 20261128-082918F_20261128-083126D
            timestamp start/stop: 2026-11-28 08:31:26+01 / 2026-11-28 08:31:30+01
            wal start/stop: 00000007000000000000000D / 00000007000000000000000D
            database size: 58.2MB, database backup size: 569.4KB
            repo1: backup size: 15.4KB
            backup reference total: 1 full

        incr backup: 20261128-082918F_20261128-083212I
            timestamp start/stop: 2026-11-28 08:32:12+01 / 2026-11-28 08:32:14+01
            wal start/stop: 00000007000000000000000F / 00000007000000000000000F
            database size: 58.2MB, database backup size: 635.6KB
            repo1: backup size: 18.1KB
            backup reference total: 1 full, 1 diff
Backup label: 20261128-082918F_20261128-083126D
stanza: epas18
    status: ok
    cipher: none

    db (current)
        wal archive min/max (18): 000000030000000000000005/00000007000000000000000F

        diff backup: 20261128-082918F_20261128-083126D
            timestamp start/stop: 2026-11-28 08:31:26+01 / 2026-11-28 08:31:30+01
            wal start/stop: 00000007000000000000000D / 00000007000000000000000D
            lsn start/stop: 0/D000028 / 0/D000120
            database size: 58.2MB, database backup size: 569.4KB
            repo1: backup size: 15.4KB
            backup reference list: 20261128-082918F
            database list: edb (15403), postgres (5)
[root@lin6 ~]#

The backup labels show the type: 20261128-082918F is a full backup, 20261128-082918F_20261128-083126D a differential and …I an incremental backup based on it. info also shows the WAL range of the archive, the size of each backup in the database and in the repository and the backup reference list. Thanks to block incremental, the differential and incremental backups of our small test changes are only a few kilobytes in the repository.

7. Point-in-Time Recovery (PITR)

7.1 Simulate the user error

# run as root on lin8
su - enterprisedb -c 'psql -d edb -v ON_ERROR_STOP=1' << 'EOF'
INSERT INTO pgbr_test (phase) SELECT 'before drop' FROM generate_series(1, 100);
SELECT clock_timestamp() AS pitr_target;
SELECT pg_sleep(5);
DROP TABLE pgbr_test;
EOF
Sample Output (click to expand):
[root@lin8 ~]# # run as root on lin8
su - enterprisedb -c 'psql -d edb -v ON_ERROR_STOP=1' << 'EOF'
INSERT INTO pgbr_test (phase) SELECT 'before drop' FROM generate_series(1, 100);
SELECT clock_timestamp() AS pitr_target;
SELECT pg_sleep(5);
DROP TABLE pgbr_test;
EOF
INSERT 0 100
           pitr_target
----------------------------------
 28-NOV-26 08:41:39.863657 +01:00
(1 row)

 pg_sleep
----------

(1 row)

DROP TABLE
[root@lin8 ~]#

Write down the timestamp returned by clock_timestamp(). Then we make sure that the WAL file with the DROP TABLE is complete and archived – check does exactly that:

# run as root on lin6
su - pgbackrest -c "pgbackrest --stanza=epas18 check"

7.2 Restore to the point in time

We restore into a separate directory on lin8 and start the restored cluster on port 5446 next to the production cluster. The restore runs on the database node as enterprisedb:

  • --pg1-path overrides the data directory from the configuration file.
  • --type=time with --target sets the recovery target. Include the time zone. pgBackRest automatically selects the latest backup that finished before the target time.
  • --target-action=promote opens the cluster for read/write access when the target is reached.
  • --archive-mode=off is important: the restored cluster must not push its WAL files into the repository of the production cluster.
# run as root on lin8
install -d -m 700 -o enterprisedb -g enterprisedb /var/lib/edb/as18/restore
# replace the timestamp with the value from step 7.1
su - enterprisedb -c "pgbackrest --stanza=epas18 --pg1-path=/var/lib/edb/as18/restore \
  --type=time --target='2026-11-28 08:41:39+01' --target-action=promote \
  --archive-mode=off restore"
grep -E 'restore_command|recovery_target|archive_mode' /var/lib/edb/as18/restore/postgresql.auto.conf
Sample Output (click to expand):
[root@lin8 ~]# # run as root on lin8
install -d -m 700 -o enterprisedb -g enterprisedb /var/lib/edb/as18/restore
# replace the timestamp with the value from step 7.1
su - enterprisedb -c "pgbackrest --stanza=epas18 --pg1-path=/var/lib/edb/as18/restore \
  --type=time --target='2026-11-28 08:41:39+01' --target-action=promote \
  --archive-mode=off restore"
grep -E 'restore_command|recovery_target|archive_mode' /var/lib/edb/as18/restore/postgresql.auto.conf
2026-11-28 08:46:29.243 P00   INFO: restore command begin 2.60.1: --archive-mode=off --exec-id=17771-c71068dd --log-level-console=info --log-level-file=detail --pg1-path=/var/lib/edb/as18/restore --pg-version-force=18 --process-max=2 --repo1-host=lin6 --repo1-host-user=pgbackrest --spool-path=/var/spool/pgbackrest --stanza=epas18 --target="2026-11-28 08:41:39+01" --target-action=promote --type=time
2026-11-28 08:46:30.077 P00   INFO: repo1: restore backup set 20261128-082918F_20261128-083212I, recovery will start at 2026-11-28 08:32:12
2026-11-28 08:46:30.077 P00   INFO: remap data directory to '/var/lib/edb/as18/restore'
2026-11-28 08:46:32.828 P00   INFO: write updated /var/lib/edb/as18/restore/postgresql.auto.conf
2026-11-28 08:46:32.838 P00   INFO: restore global/pg_control (performed last to ensure aborted restores cannot be started)
2026-11-28 08:46:32.839 P00   INFO: restore size = 58.2MB, file total = 1659
2026-11-28 08:46:32.839 P00   INFO: restore command end: completed successfully (3601ms)
archive_mode = 'on'
archive_mode = 'off'
restore_command = 'pgbackrest --pg1-path=/var/lib/edb/as18/restore --stanza=epas18 archive-get %f "%p"'
recovery_target_time = '2026-11-28 08:41:39+01'
recovery_target_action = 'promote'
[root@lin8 ~]#

7.3 Start the cluster and verify the data

# run as root on lin8
su - enterprisedb -c "pg_ctl -D /var/lib/edb/as18/restore -o '-p 5446' -l /var/lib/edb/as18/restore/startup.log start"
su - enterprisedb -c "psql -p 5446 -d edb -c \"SELECT phase, count(*) FROM pgbr_test GROUP BY phase ORDER BY min(id);\""
Sample Output (click to expand):
[root@lin8 ~]# # run as root on lin8
su - enterprisedb -c "pg_ctl -D /var/lib/edb/as18/restore -o '-p 5446' -l /var/lib/edb/as18/restore/startup.log start"
su - enterprisedb -c "psql -p 5446 -d edb -c \"SELECT phase, count(*) FROM pgbr_test GROUP BY phase ORDER BY min(id);\""
waiting for server to start....... done
server started
       phase        | count
--------------------+-------
 before full backup |  1000
 after full backup  |   500
 after diff backup  |   200
(3 rows)

[root@lin8 ~]#

The table is back, including the 100 rows inserted shortly before the drop. We copy it back into the production cluster and clean up:

# run as root on lin8
su - enterprisedb -c "pg_dump -p 5446 -d edb -t pgbr_test | psql -d edb"
su - enterprisedb -c "psql -d edb -c \"SELECT phase, count(*) FROM pgbr_test GROUP BY phase ORDER BY min(id);\""
su - enterprisedb -c "pg_ctl -D /var/lib/edb/as18/restore stop"
rm -rf /var/lib/edb/as18/restore
Sample Output (click to expand)
[root@lin8 ~]# # run as root on lin8
su - enterprisedb -c "pg_dump -p 5446 -d edb -t pgbr_test | psql -d edb"
su - enterprisedb -c "psql -d edb -c \"SELECT phase, count(*) FROM pgbr_test GROUP BY phase ORDER BY min(id);\""
su - enterprisedb -c "pg_ctl -D /var/lib/edb/as18/restore stop"
rm -rf /var/lib/edb/as18/restore
SET
SET
SET
SET
SET
SET
SET
SET
 set_config
------------

(1 row)

SET
SET
SET
SET
SET
SET
SET
CREATE TABLE
ALTER TABLE
ALTER TABLE
COPY 1700
 setval
--------
   1832
(1 row)

       phase        | count
--------------------+-------
 before full backup |  1000
 after full backup  |   500
 after diff backup  |   200
(3 rows)

waiting for server to shut down.... done
server stopped
[root@lin8 ~]#

Tip: Besides --type=time, pgBackRest supports --type=xid, --type=lsn, --type=name (restore points created with pg_create_restore_point()) and --type=immediate (end of the backup). With --target-action=pause the cluster stays read-only at the target until you check the data and call pg_wal_replay_resume().

8. Rebuild the Standby from the Backup

In the EFM post we rebuilt nodes with efm create-standby, which copies the whole database from the primary with pg_basebackup. With pgBackRest, a standby can be built from the repository instead: the primary is not loaded at all, the restore runs with several parallel processes, and the standby catches up with the WAL files from the archive before it switches to streaming replication. For large databases this is often much faster.

8.1 Simulate the loss of the standby

We stop the EFM agent on lin7 first, so that EFM does not report a database failure, and then remove the data directory – as if the disk of the standby had failed. The cluster keeps working with the primary and the witness.

Warning: The following commands delete the data directory. Check twice that you are on the standby lin7 and that efm cluster-status efm shows lin8 as primary.

# run as root on lin7
/usr/edb/efm-5.5/bin/efm cluster-status efm
systemctl stop edb-efm-5.5
systemctl stop edb-as-18
find /var/lib/edb/as18/data -mindepth 1 -delete
ls -la /var/lib/edb/as18/data
Sample Output (click to expand)
[root@lin7 ~]# # run as root on lin7
/usr/edb/efm-5.5/bin/efm cluster-status efm
systemctl stop edb-efm-5.5
systemctl stop edb-as-18
find /var/lib/edb/as18/data -mindepth 1 -delete
ls -la /var/lib/edb/as18/data
Cluster Status: efm

        Agent Type  Address              DB       VIP
        ----------------------------------------------------------------
        Witness     11.1.1.186           N/A      11.1.1.200
        Standby     11.1.1.195           UP       11.1.1.200
        Primary     11.1.1.196           UP       11.1.1.200*

Allowed node host list:
        11.1.1.196 11.1.1.195 11.1.1.186

Membership coordinator: 11.1.1.196

Standby priority host list:
        11.1.1.195

Promote Status:

        DB Type     Address              WAL Received LSN   WAL Replayed LSN   Info
        ---------------------------------------------------------------------------
        Primary     11.1.1.196                              0/11057BC0
        Standby     11.1.1.195           0/11057BC0         0/11057BC0

        Standby database(s) in sync with primary. It is safe to promote.
total 0
drwx------ 2 enterprisedb enterprisedb  6 Nov 28 09:04 .
drwx------ 4 enterprisedb enterprisedb 33 Nov 27 10:22 ..
[root@lin7 ~]#

8.2 Restore as a standby

--type=standby creates standby.signal, and --recovery-option writes primary_conninfo into postgresql.auto.conf. The password of repuser comes from ~/.pgpass of enterprisedb, which we created in the EFM post. application_name matches the property application.name of the EFM configuration on lin7.

# run as root on lin7
su - enterprisedb -c "pgbackrest --stanza=epas18 --type=standby \
  --recovery-option=primary_conninfo='host=lin8 port=5444 user=repuser application_name=lin7' \
  restore"
cat /var/lib/edb/as18/data/postgresql.auto.conf
ls -l /var/lib/edb/as18/data/standby.signal
Sample Output (click to expand):
[root@lin7 ~]# # run as root on lin7
su - enterprisedb -c "pgbackrest --stanza=epas18 --type=standby \
  --recovery-option=primary_conninfo='host=lin8 port=5444 user=repuser application_name=lin7' \
  restore"
cat /var/lib/edb/as18/data/postgresql.auto.conf
ls -l /var/lib/edb/as18/data/standby.signal
2026-11-28 09:06:14.829 P00   INFO: restore command begin 2.60.1: --exec-id=14512-9cf17f94 --log-level-console=info --log-level-file=detail --pg1-path=/var/lib/edb/as18/data --pg-version-force=18 --process-max=2 --recovery-option="primary_conninfo=host=lin8 port=5444 user=repuser application_name=lin7" --repo1-host=lin6 --repo1-host-user=pgbackrest --spool-path=/var/spool/pgbackrest --stanza=epas18 --type=standby
2026-11-28 09:06:15.766 P00   INFO: repo1: restore backup set 20261128-082918F_20261128-083212I, recovery will start at 2026-11-28 08:32:12
2026-11-28 09:06:18.355 P00   INFO: write updated /var/lib/edb/as18/data/postgresql.auto.conf
2026-11-28 09:06:18.361 P00   INFO: restore global/pg_control (performed last to ensure aborted restores cannot be started)
2026-11-28 09:06:18.362 P00   INFO: restore size = 58.2MB, file total = 1659
2026-11-28 09:06:18.362 P00   INFO: restore command end: completed successfully (3537ms)
# Do not edit this file manually!
# It will be overwritten by the ALTER SYSTEM command.
wal_log_hints = 'on'
wal_keep_size = '1GB'
archive_mode = 'on'
archive_command = 'pgbackrest --stanza=epas18 archive-push %p'
primary_conninfo = 'user=repuser passfile=''/var/lib/edb/.pgpass'' channel_binding=prefer host=11.1.1.195 port=5444 sslmode=prefer sslnegotiation=postgres sslcompression=0 sslcertmode=allow sslsni=1 ssl_min_protocol_version=TLSv1.2 gssencmode=prefer krbsrvname=postgres gssdelegation=0 target_session_attrs=any load_balance_hosts=disable application_name=''lin8'''

# Recovery settings generated by pgBackRest restore on 2026-11-28 09:06:18
primary_conninfo = 'host=lin8 port=5444 user=repuser application_name=lin7'
restore_command = 'pgbackrest --stanza=epas18 archive-get %f "%p"'
-rw------- 1 enterprisedb enterprisedb 0 Nov 28 09:06 /var/lib/edb/as18/data/standby.signal
[root@lin7 ~]#

8.3 Start the standby and the EFM agent

# run as root on lin7
systemctl start edb-as-18
su - enterprisedb -c "psql -d edb -c 'SELECT pg_is_in_recovery(), pg_last_wal_replay_lsn();'"
systemctl start edb-efm-5.5
/usr/edb/efm-5.5/bin/efm cluster-status efm
Sample Output (click to expand):
[root@lin7 ~]# # run as root on lin7
systemctl start edb-as-18
su - enterprisedb -c "psql -d edb -c 'SELECT pg_is_in_recovery(), pg_last_wal_replay_lsn();'"
systemctl start edb-efm-5.5
/usr/edb/efm-5.5/bin/efm cluster-status efm
 pg_is_in_recovery | pg_last_wal_replay_lsn
-------------------+------------------------
 t                 | 0/10002EB0
(1 row)

Cluster Status: efm

        Agent Type  Address              DB       VIP
        ----------------------------------------------------------------
        Witness     11.1.1.186           N/A      11.1.1.200
        Standby     11.1.1.195           UP       11.1.1.200
        Primary     11.1.1.196           UP       11.1.1.200*

Allowed node host list:
        11.1.1.196 11.1.1.195 11.1.1.186

Membership coordinator: 11.1.1.196

Standby priority host list:
        (List is empty.)

Promote Status:

        DB Type     Address              WAL Received LSN   WAL Replayed LSN   Info
        ---------------------------------------------------------------------------
        Primary     11.1.1.196                              0/11057BC0
        Standby     11.1.1.195           0/11057BC0         0/11057BC0

        Standby database(s) in sync with primary. It is safe to promote.
[root@lin7 ~]#

# run as root on lin8
su - enterprisedb -c "psql -d edb -c 'SELECT client_addr, application_name, state, sync_state FROM pg_stat_replication;'"
Sample Output (click to expand):
[root@lin8 ~]# # run as root on lin8
su - enterprisedb -c "psql -d edb -c 'SELECT client_addr, application_name, state, sync_state FROM pg_stat_replication;'"
 client_addr | application_name |   state   | sync_state
-------------+------------------+-----------+------------
 11.1.1.195  | lin7             | streaming | async
(1 row)

[root@lin8 ~]#

state = streaming on the primary and Standby database(s) in sync with primary in the cluster status show that lin7 is a healthy standby again. The same approach works for an old primary after a failover: add --delta and pgBackRest keeps the existing files in the data directory, compares them with the backup by checksum and restores only the files that differ.

9. Scheduling and Retention

pgBackRest has no scheduler of its own. A cron job on the repository host with a weekly full backup and daily differential backups is a good start:

# run as root on lin6
cat > /etc/cron.d/pgbackrest << 'EOF'
# weekly full backup on Sunday, differential backups Monday to Saturday
30 2 * * 0   pgbackrest /usr/bin/pgbackrest --stanza=epas18 --type=full backup
30 2 * * 1-6 pgbackrest /usr/bin/pgbackrest --stanza=epas18 --type=diff backup
EOF

After each successful backup, pgBackRest runs expire automatically and removes the backups and WAL files that are no longer covered by repo1-retention-full=2. Because the cron job runs on lin6 and the stanza contains both database nodes, it does not have to be changed after a switchover or failover. For monitoring, pgbackrest --stanza=epas18 info --output=json returns machine-readable output, e.g. the time of the last backup.

10. From the Lab to Production

  • Encryption: set repo1-cipher-type=aes-256-cbc and a long repo1-cipher-pass on the repository host before running stanza-create. Keep the passphrase in a safe place – without it, the backups are worthless.
  • Second repository: pgBackRest can write to several repositories at once, e.g. repo2 in S3, Azure or GCS compatible object storage as an off-site copy.
  • Repository host: in the lab the witness doubles as backup server. In production, use a dedicated backup server or object storage and size it for the retention period.
  • TLS instead of SSH: the pgBackRest TLS server (repo1-host-type=tls) avoids the SSH keys in both directions.
  • Archive queue: if the repository host is unavailable, WAL files accumulate in pg_wal. Monitor archiving (pg_stat_archiver) and consider archive-push-queue-max as an emergency brake.
  • Test restores regularly, ideally automated on a separate server, and measure how long a full restore takes.

Troubleshooting Common Issues

ProblemSolution
unable to connect to 'dbname='edb' port=5444' / socket not foundCheck pg1-port, pg1-socket-path and pg1-database on all nodes (chapter 3.1). EPAS uses port 5444 and the database edb.
calculated pg_control checksum does not match expected value, followed by unable to find primary clusterThe pg_control layout of EPAS differs from community PostgreSQL. Set pg-version-force to the EPAS major version in the stanza section on all nodes (chapter 3).
Host key verification failedThe user cannot answer the host key prompt. Connect once with -o StrictHostKeyChecking=accept-new (chapter 2).
Permission denied (publickey,…)Check the permissions of ~/.ssh (700) and authorized_keys (600) and the SELinux labels (restorecon -R).
check fails with WAL segment … was not archived before the 60000ms timeoutCheck archive_mode (restart required, chapter 5.2), archive_command and the log /var/log/pgbackrest/epas18-archive-push-async.log on the primary. Test SSH from enterprisedb to pgbackrest@lin6.
unable to find primary clusterBoth pg1 and pg2 must be configured on lin6, and the primary must be running. Check efm cluster-status efm.
Backup fails with backup-standby=yNo standby is available. Use backup-standby=prefer to fall back to the primary.
Restore: unable to restore to path … not emptyThe target directory must be empty – or use --delta to restore into an existing data directory.
PITR: recovery ended before configured recovery target was reachedThe WAL after the target time was not archived yet. Run pgbackrest --stanza=epas18 check and restore again.
Files in the repository owned by rootA pgBackRest command was run as root. Always use su - pgbackrest on lin6 and su - enterprisedb on the database nodes; fix the ownership with chown -R.

Resources

Conclusion

Our EPAS 18 EFM cluster is now protected by pgBackRest with a repository on the witness node. Here is a quick recap:

  • One stanza contains both database nodes – pgBackRest finds the current primary by itself, so backups and archiving keep working after a switchover or failover.
  • With backup-standby=prefer the data files are copied from the standby and the primary is spared.
  • Full, differential and block incremental backups with zstd compression keep the repository small.
  • A PITR into a separate directory with --archive-mode=off recovers single objects without touching the production cluster.
  • A standby can be rebuilt from the repository with --type=standby (and --delta for an old primary) instead of copying everything from the primary.

Next Steps:

  • Put EDB PgBouncer in front of the cluster and let EFM re-point it after a failover (follow-up post).
  • Add a second repository in object storage for off-site copies.
  • Monitor backups and archiving with Postgres Enterprise Manager (PEM) or your existing monitoring.
0
PostgreSQL backup with barman

Backup and Recovery of EDB Postgres Advanced Server 18 (EPAS) with Barman – Full, Incremental and Point-in-Time Recovery

In the previous post we installed EDB Postgres Advanced Server 18 (EPAS) on Red Hat Enterprise Linux 10 and created a cluster in the Oracle compatible Redwood mode. A database is only as good as its last tested restore, so the next step is a proper backup and recovery setup. In this post we use Barman (Backup and Recovery Manager), the open source backup tool maintained by EDB, on a dedicated backup server.

We will take a full backup and two block-level incremental backups of the Redwood cluster, restore the latest incremental backup and finally perform a point-in-time recovery (PITR) after an “accidental” DROP TABLE.

Prerequisites

EPAS Serverlin8: RHEL 10 with EPAS 18 and the Redwood cluster in /var/lib/edb/as18/data (port 5444), installed as described in the previous post.
Backup Serverlin6: a second RHEL 10 VM (minimum 2 vCPUs, 4GB RAM). Plan the backup storage with at least 2–3 times the database size for base backups and WAL files.
BarmanBarman 3.21 (current version at the time of writing) from the EDB repository.
EDB AccountThe EDB repository token from the previous post.
Name ResolutionBoth hosts can resolve each other by name (DNS or /etc/hosts).
Root/Sudo AccessFull administrative privileges on both VMs.

How It Works

Barman supports several backup methods. We use backup_method = postgres, the streaming setup recommended for current Postgres versions:

  • Base backups are taken with pg_basebackup over the streaming replication protocol. No SSH connection is needed for backups.
  • WAL files are streamed continuously with pg_receivewal through a replication slot. No archive_command is needed and the potential data loss (RPO) is close to zero.
  • Incremental backups use the native block-level incremental backup feature introduced in PostgreSQL 17. The server tracks changed blocks via WAL summarization (summarize_wal), and pg_basebackup --incremental copies only the blocks changed since the parent backup.
  • Restores of incremental backups are done by combining the chain (full backup + incrementals) with pg_combinebackup. The restored files are copied with rsync over SSH to the target server.

1. Prepare the EPAS Server (lin8)

1.1 Enable WAL summarization

Block-level incremental backups require summarize_wal = on, and it must be enabled before the first full backup is taken. The parameter only needs a reload. The other relevant parameters (wal_level = replica, max_wal_senders, max_replication_slots) already have suitable default values.

# run as root on lin8
su - enterprisedb -c "psql -d edb -c \"alter system set summarize_wal = on;\""
su - enterprisedb -c "psql -d edb -c \"select pg_reload_conf();\""
su - enterprisedb -c "psql -d edb -c \"show summarize_wal;\""
Sample Output (click to expand):
[root@lin8 ~]# # run as root on lin8
su - enterprisedb -c "psql -d edb -c \"alter system set summarize_wal = on;\""
su - enterprisedb -c "psql -d edb -c \"select pg_reload_conf();\""
su - enterprisedb -c "psql -d edb -c \"show summarize_wal;\""
ALTER SYSTEM
 pg_reload_conf
----------------
 t
(1 row)

 summarize_wal
---------------
 on
(1 row)

[root@lin8 ~]#

1.2 Create the Barman database users

Barman uses two database users: barman for the regular connection (it does not need to be a superuser, only some privileges to control backups) and streaming_barman with the REPLICATION attribute for pg_basebackup and pg_receivewal:

# run as root on lin8
su - enterprisedb -c "psql -d edb" <<'EOF'
create user barman password 'changeme';
grant execute on function pg_backup_start(text, boolean) to barman;
grant execute on function pg_backup_stop(boolean) to barman;
grant execute on function pg_switch_wal() to barman;
grant execute on function pg_create_restore_point(text) to barman;
grant pg_read_all_settings to barman;
grant pg_read_all_stats to barman;
grant pg_checkpoint to barman;
create user streaming_barman replication password 'changeme';
EOF
Sample Output (click to expand):
[root@lin8 ~]# # run as root on lin8
su - enterprisedb -c "psql -d edb" <<'EOF'
create user barman password 'changeme';
grant execute on function pg_backup_start(text, boolean) to barman;
grant execute on function pg_backup_stop(boolean) to barman;
grant execute on function pg_switch_wal() to barman;
grant execute on function pg_create_restore_point(text) to barman;
grant pg_read_all_settings to barman;
grant pg_read_all_stats to barman;
grant pg_checkpoint to barman;
create user streaming_barman replication password 'changeme';
EOF
CREATE ROLE
GRANT
GRANT
GRANT
GRANT
GRANT ROLE
GRANT ROLE
GRANT ROLE
CREATE ROLE
[root@lin8 ~]#

1.3 Allow connections from the backup server

The pg_hba.conf from the previous post only contains the line host all all 0.0.0.0/0 scram-sha-256. The keyword all in the database column does not match replication connections, so we need an additional entry for the streaming user:

# run as root on lin8
cat >> /var/lib/edb/as18/data/pg_hba.conf <<'EOF'
# Barman streaming connections from the backup server lin6
host replication streaming_barman 11.1.1.186/32 scram-sha-256
EOF
su - enterprisedb -c "psql -d edb -c \"select pg_reload_conf();\""

1.4 Install rsync

For restores Barman copies the files with rsync over SSH, so rsync is needed on the EPAS server as well:

# run as root on lin8
dnf -y install rsync

2. Install and Configure Barman (lin6)

2.1 Prepare the OS and add the EDB repository

Prepare the backup server exactly like the EPAS server in steps 1.2 and 1.3 of the previous post (EPEL, CodeReady Builder and the EDB “enterprise” repository with your token). Barman is available both in the EDB repositories and in the PGDG repositories. Stick to one source: the packages from different repositories use different configuration layouts and should not be mixed.

2.2 Install Barman and the EPAS client tools

Barman calls pg_basebackup, pg_receivewal and, for incremental restores, pg_combinebackup. We install the EPAS 18 client package so that the tools match the server version:

# run as root on lin6
dnf -y install barman edb-as18-server-client rsync
barman --version
ls -l /usr/edb/as18/bin/{pg_basebackup,pg_receivewal,pg_combinebackup}
cat /etc/cron.d/barman
Sample Output (click to expand):
[root@lin6 ~]# # run as root on lin6
dnf -y install barman edb-as18-server-client rsync
barman --version
ls -l /usr/edb/as18/bin/{pg_basebackup,pg_receivewal,pg_combinebackup}
cat /etc/cron.d/barman
Updating Subscription Management repositories.
Extra Packages for Enterprise Linux 10 - x86_64                                                                                 3.5 MB/s | 7.3 MB     00:02
Red Hat CodeReady Linux Builder for RHEL 10 x86_64 (RPMs)                                                                       1.1 MB/s | 1.7 MB     00:01
Red Hat Enterprise Linux 10 for x86_64 - AppStream (RPMs)                                                                        11 kB/s | 4.1 kB     00:00
Red Hat Enterprise Linux 10 for x86_64 - BaseOS (RPMs)                                                                           12 kB/s | 4.1 kB     00:00
Package rsync-3.5.0-4.el10_3.x86_64 is already installed.
Dependencies resolved.
================================================================================================================================================================
 Package                                    Architecture               Version                                Repository                                   Size
================================================================================================================================================================
Installing:
 barman                                     x86_64                     3.21.0-1.el10                          enterprisedb-enterprise                     244 k
 edb-as18-server-client                     x86_64                     18.7.0-1.el10                          enterprisedb-enterprise                     2.0 M
Installing dependencies:
 edb-as18-server-libs                       x86_64                     18.7.0-1.el10                          enterprisedb-enterprise                     705 k
 edb-python312                              x86_64                     3.12.16-2edb.el10                      enterprisedb-enterprise                      17 M
 edb-python312-barman                       x86_64                     3.21.0-1.el10                          enterprisedb-enterprise                      36 M

Transaction Summary
================================================================================================================================================================
Install  5 Packages

Total size: 56 M
Total download size: 54 M
Installed size: 260 M
Downloading Packages:
[SKIPPED] edb-as18-server-client-18.7.0-1.el10.x86_64.rpm: Already downloaded
[SKIPPED] edb-as18-server-libs-18.7.0-1.el10.x86_64.rpm: Already downloaded
(3/5): barman-3.21.0-1.el10.x86_64.rpm                                                                                          345 kB/s | 244 kB     00:00
(4/5): edb-python312-3.12.16-2edb.el10.x86_64.rpm                                                                               5.3 MB/s |  17 MB     00:03
(5/5): edb-python312-barman-3.21.0-1.el10.x86_64.rpm                                                                            5.9 MB/s |  36 MB     00:06
----------------------------------------------------------------------------------------------------------------------------------------------------------------
Total                                                                                                                           8.5 MB/s |  54 MB     00:06
Running transaction check
Transaction check succeeded.
Running transaction test
Transaction test succeeded.
Running transaction
  Preparing        :                                                                                                                                        1/1
  Installing       : edb-as18-server-libs-18.7.0-1.el10.x86_64                                                                                              1/5
  Running scriptlet: edb-as18-server-libs-18.7.0-1.el10.x86_64                                                                                              1/5
  Installing       : edb-python312-3.12.16-2edb.el10.x86_64                                                                                                 2/5
  Installing       : edb-python312-barman-3.21.0-1.el10.x86_64                                                                                              3/5
  Running scriptlet: barman-3.21.0-1.el10.x86_64                                                                                                            4/5
  Installing       : barman-3.21.0-1.el10.x86_64                                                                                                            4/5
  Installing       : edb-as18-server-client-18.7.0-1.el10.x86_64                                                                                            5/5
  Running scriptlet: edb-as18-server-client-18.7.0-1.el10.x86_64                                                                                            5/5
Installed products updated.

Installed:
  barman-3.21.0-1.el10.x86_64                       edb-as18-server-client-18.7.0-1.el10.x86_64            edb-as18-server-libs-18.7.0-1.el10.x86_64
  edb-python312-3.12.16-2edb.el10.x86_64            edb-python312-barman-3.21.0-1.el10.x86_64

Complete!
3.21.0 Barman by EnterpriseDB (www.enterprisedb.com)
-rwxr-xr-x 1 root root 147168 Nov 10 01:00 /usr/edb/as18/bin/pg_basebackup
-rwxr-xr-x 1 root root 125296 Nov 10 01:00 /usr/edb/as18/bin/pg_combinebackup
-rwxr-xr-x 1 root root  92032 Nov 10 01:00 /usr/edb/as18/bin/pg_receivewal
# m h  dom mon dow   user     command
  * *    *   *   *   barman   [ -x /usr/bin/barman ] && /usr/bin/barman -q cron

[root@lin6 ~]#

If the client package has a different name in your repository, dnf search edb-as18 shows the available packages. The installation creates the OS user barman with the home directory /var/lib/barman, the main configuration file /etc/barman.conf, the directory /etc/barman.d for the server configurations and a cron job that runs barman cron every minute.

2.3 Store the passwords

Barman connects with libpq, so the passwords are stored in the .pgpass file of the barman user. Afterwards we test both connections:

# run as root on lin6
cat > /var/lib/barman/.pgpass <<'EOF'
lin8:5444:*:barman:changeme
lin8:5444:*:streaming_barman:changeme
EOF
chown barman:barman /var/lib/barman/.pgpass
chmod 600 /var/lib/barman/.pgpass
# test the regular and the replication connection
su - barman -c "/usr/edb/as18/bin/psql -h lin8 -p 5444 -U barman -d edb -c 'select version();'"
su - barman -c "/usr/edb/as18/bin/psql 'host=lin8 port=5444 user=streaming_barman replication=true' -c 'IDENTIFY_SYSTEM;'"
Sample Output (click to expand):
[root@lin6 ~]# # run as root on lin6
cat > /var/lib/barman/.pgpass <<'EOF'
lin8:5444:*:barman:changeme
lin8:5444:*:streaming_barman:changeme
EOF
chown barman:barman /var/lib/barman/.pgpass
chmod 600 /var/lib/barman/.pgpass
# test the regular and the replication connection
su - barman -c "/usr/edb/as18/bin/psql -h lin8 -p 5444 -U barman -d edb -c 'select version();'"
su - barman -c "/usr/edb/as18/bin/psql 'host=lin8 port=5444 user=streaming_barman replication=true' -c 'IDENTIFY_SYSTEM;'"
                                                                    version
------------------------------------------------------------------------------------------------------------------------------------------------
 PostgreSQL 18.7 (EnterpriseDB Advanced Server 18.7.0) on x86_64-pc-linux-gnu, compiled by gcc (GCC) 14.3.1 20251022 (Red Hat 14.3.1-4), 64-bit
(1 row)

      systemid       | timeline |  xlogpos  | dbname
---------------------+----------+-----------+--------
 7711382709664784657 |        1 | 0/3626F00 |
(1 row)

[root@lin6 ~]#

2.4 Configure the EPAS server in Barman

Each Postgres server gets its own configuration file in /etc/barman.d. The section name (epas18) is the name we use in all Barman commands:

# run as root on lin6
cat > /etc/barman.d/epas18.conf <<'EOF'
[epas18]
description = "EPAS 18 Redwood cluster on lin8"
conninfo = host=lin8 port=5444 user=barman dbname=edb
streaming_conninfo = host=lin8 port=5444 user=streaming_barman
backup_method = postgres
streaming_archiver = on
slot_name = barman
create_slot = auto
path_prefix = /usr/edb/as18/bin
staging_path = /var/lib/barman/staging
staging_location = local
retention_policy = RECOVERY WINDOW OF 7 DAYS
EOF
mkdir -p /var/lib/barman/staging
chown barman:barman /var/lib/barman/staging
backup_method = postgresBase backups with pg_basebackup. Required for block-level incremental backups.
streaming_archiver = onWAL files are streamed with pg_receivewal instead of being shipped by an archive_command.
slot_name / create_slot = autoBarman creates and uses the replication slot barman, so the EPAS server keeps WAL files until Barman has received them.
path_prefixUse the EPAS 18 client binaries.
staging_path / staging_location = localDirectory on the Barman server where the backup chain is combined with pg_combinebackup during the restore of an incremental backup.
retention_policyKeep all backups and WAL files needed to recover to any point in time of the last 7 days.

Note: The slot keeps WAL files on the EPAS server as long as Barman has not received them. If the backup server is down for a long time, pg_wal on lin8 grows. Consider setting max_slot_wal_keep_size on the EPAS server and monitor the slot.

2.5 Start WAL streaming and check the configuration

barman cron creates the replication slot and starts receive-wal in the background (the cron job would do this within a minute as well). barman switch-wal forces a WAL switch on the EPAS server and waits until the WAL file has arrived in the Barman archive. Finally, barman check must report OK for all checks:

# run as root on lin6
su - barman -c "barman cron"
su - barman -c "barman switch-wal --force --archive epas18"
su - barman -c "barman check epas18"
Sample Output (click to expand):
[root@lin6 ~]# # run as root on lin6
su - barman -c "barman cron"
su - barman -c "barman switch-wal --force --archive epas18"
su - barman -c "barman check epas18"
Starting WAL archiving for server epas18
The WAL file 000000010000000000000003 has been closed on server 'epas18'
Waiting for the WAL file 000000010000000000000003 from server 'epas18' (max: 30 seconds)
Processing xlog segments from streaming for epas18 (batch size: 1)
        000000010000000000000003
Server epas18:
        PostgreSQL: OK
        superuser or standard user with backup privileges: OK
        PostgreSQL streaming: OK
        wal_level: OK
        replication slot: OK
        directories: OK
        retention policy settings: OK
        backup maximum age: OK (no last_backup_maximum_age provided)
        backup minimum size: OK (0 B)
        wal maximum age: OK (no last_wal_maximum_age provided)
        wal size: OK (0 B)
        compression settings: OK
        failed backups: OK (there are 0 failed backups)
        minimum redundancy requirements: OK (have 0 non-incremental backups, expected at least 0)
        pg_basebackup: OK
        pg_basebackup compatible: OK
        pg_basebackup supports tablespaces mapping: OK
        systemid coherence: OK (no system Id stored on disk)
        pg_receivexlog: OK
        pg_receivexlog compatible: OK
        receive-wal running: OK
        archiver errors: OK
[root@lin6 ~]#

3. Full Backup

3.1 Create some test data

To verify the restores later, we create a small table and record in which phase each row was inserted. Thanks to the Redwood mode we can use Oracle data types:

# run as root on lin8
su - enterprisedb -c "psql -d edb" <<'EOF'
create table bkp_test (id integer generated always as identity, phase varchar2(30), created timestamp default clock_timestamp());
insert into bkp_test (phase) select 'before full backup' from generate_series(1, 1000);
EOF

3.2 Take the full backup

The option --wait makes Barman wait until all WAL files required to make the backup consistent have been archived:

# run as root on lin6
su - barman -c "barman backup epas18 --wait"
su - barman -c "barman list-backups epas18"
Sample Output (click to expand):
[root@lin6 ~]# # run as root on lin6
su - barman -c "barman backup epas18 --wait"
su - barman -c "barman list-backups epas18"
Starting backup using postgres method for server epas18 in /var/lib/barman/epas18/base/20261124T091230
Backup start at LSN: 0/4047AE0 (000000010000000000000004, 00047AE0)
Starting backup copy via pg_basebackup for 20261124T091230
Copy done (time: 7 seconds)
Finalising the backup.
This is the first backup for server epas18
WAL segments preceding the current backup have been found:
        000000010000000000000003 from server epas18 has been removed
Backup size: 58.3 MiB
Backup end at LSN: 0/6000060 (000000010000000000000006, 00000060)
Backup completed (start time: 2026-11-24 09:12:30.377039, elapsed time: 8 seconds)
Waiting for the WAL file 000000010000000000000006 from server 'epas18'
Processing xlog segments from streaming for epas18 (batch size: 3)
        000000010000000000000004
        000000010000000000000005
        000000010000000000000006
epas18 20261124T091230 - F - Tue Nov 24 09:12:37 2026 - Size: 90.3 MiB - WAL Size: 0 B
[root@lin6 ~]#

The backup ID is a timestamp such as 20261124T091230. Instead of the ID you can use shortcuts like latest, oldest or latest-full in most Barman commands.

3.3 Inspect the backup

# run as root on lin6
su - barman -c "barman show-backup epas18 latest"
Sample Output (click to expand):
[root@lin6 ~]# # run as root on lin6
su - barman -c "barman show-backup epas18 latest"
Backup 20261124T091230:
  Server Name            : epas18
  System Id              : 7711382709664784657
  Status                 : DONE
  PostgreSQL Version     : 180007
  PGDATA directory       : /var/lib/edb/as18/data
  Estimated Cluster Size : 58.6 MiB

  Server information:
    Checksums            : on
    WAL summarizer       : on

  Base backup information:
    Backup Method        : postgres
    Backup Type          : full
    Backup Size          : 58.3 MiB (90.3 MiB with WALs)
    WAL Size             : 32.0 MiB
    Timeline             : 1
    Begin WAL            : 000000010000000000000005
    End WAL              : 000000010000000000000006
    Number of WALs       : 2
    Begin time           : 2026-11-24 09:12:30.371778+01:00
    End time             : 2026-11-24 09:12:37.770082+01:00
    Copy time            : 7 seconds
    Estimated throughput : 7.9 MiB/s
    Begin Offset         : 40
    End Offset           : 96
    Begin LSN            : 0/5000028
    End LSN              : 0/6000060

  WAL information:
    Number of files      : 0
    Disk usage           : 0 B
    WAL rate             : 7142.83/hour
    Last available       : 000000010000000000000006

  Catalog information:
    Retention Policy     : VALID
    Previous Backup      : - (this is the oldest base backup)
    Next Backup          : - (this is the latest base backup)
[root@lin6 ~]#

Among other things, show-backup shows the backup method (postgres), the backup type (full), the size, the begin and end WAL and the timeline of the backup.

4. Incremental Backups

An incremental backup needs a parent backup taken with backup_method = postgres. The parent can be a full backup or another incremental backup, so we can build a chain: full → incremental 1 → incremental 2.

4.1 First incremental backup

# run as root on lin8
su - enterprisedb -c "psql -d edb -c \"insert into bkp_test (phase) select 'after full backup' from generate_series(1, 500);\""
Sample Output (click to expand):
[root@lin8 ~]# # run as root on lin8
su - enterprisedb -c "psql -d edb -c \"insert into bkp_test (phase) select 'after full backup' from generate_series(1, 500);\""
INSERT 0 500
[root@lin8 ~]#


# run as root on lin6
su - barman -c "barman backup --incremental latest-full epas18 --wait"
Sample Output (click to expand):
[root@lin6 ~]#
# run as root on lin6
su - barman -c "barman backup --incremental latest-full epas18 --wait"
Starting backup using postgres method for server epas18 in /var/lib/barman/epas18/base/20261124T091746
Backup start at LSN: 0/701F2A0 (000000010000000000000007, 0001F2A0)
Starting backup copy via pg_basebackup for 20261124T091746
Copy done (time: less than one second)
Finalising the backup.
Backup size: 5.2 MiB
Backup end at LSN: 0/9000000 (000000010000000000000008, 00000000)
Backup completed (start time: 2026-11-24 09:17:46.532623, elapsed time: 1 second)
Waiting for the WAL file 000000010000000000000008 from server 'epas18'
Processing xlog segments from streaming for epas18 (batch size: 2)
        000000010000000000000007
        000000010000000000000008
[root@lin6 ~]#

4.2 Second incremental backup

This time the parent is the latest backup, i.e. the first incremental backup:

# run as root on lin8
su - enterprisedb -c "psql -d edb -c \"insert into bkp_test (phase) select 'after incremental 1' from generate_series(1, 200);\""

Sample Output (click to expand):
[root@lin8 ~]# # run as root on lin8
su - enterprisedb -c "psql -d edb -c \"insert into bkp_test (phase) select 'after incremental 1' from generate_series(1, 200);\""

INSERT 0 200
[root@lin8 ~]#


# run as root on lin6
su - barman -c "barman backup --incremental latest epas18 --wait"
Sample Output (click to expand):
[root@lin6 ~]#
# run as root on lin6
su - barman -c "barman backup --incremental latest epas18 --wait"
Starting backup using postgres method for server epas18 in /var/lib/barman/epas18/base/20261124T091958
Backup start at LSN: 0/902CD38 (000000010000000000000009, 0002CD38)
Starting backup copy via pg_basebackup for 20261124T091958
Copy done (time: 3 seconds)
Finalising the backup.
Backup size: 5.2 MiB
Backup end at LSN: 0/B000000 (00000001000000000000000A, 00000000)
Backup completed (start time: 2026-11-24 09:19:59.002741, elapsed time: 4 seconds)
Waiting for the WAL file 00000001000000000000000A from server 'epas18'
Processing xlog segments from streaming for epas18 (batch size: 1)
        00000001000000000000000A
[root@lin6 ~]#

4.3 Compare the backups

# run as root on lin6
su - barman -c "barman list-backups epas18"
su - barman -c "barman show-backup epas18 latest"
Sample Output (click to expand):
[root@lin6 ~]# # run as root on lin6
su - barman -c "barman list-backups epas18"
su - barman -c "barman show-backup epas18 latest"
epas18 20261124T091958 - I - Tue Nov 24 09:20:02 2026 - Size: 21.2 MiB - WAL Size: 0 B
epas18 20261124T091746 - I - Tue Nov 24 09:17:47 2026 - Size: 21.2 MiB - WAL Size: 32.0 MiB
epas18 20261124T091230 - F - Tue Nov 24 09:12:37 2026 - Size: 90.3 MiB - WAL Size: 32.0 MiB
Backup 20261124T091958:
  Server Name            : epas18
  System Id              : 7711382709664784657
  Status                 : DONE
  PostgreSQL Version     : 180007
  PGDATA directory       : /var/lib/edb/as18/data
  Estimated Cluster Size : 58.7 MiB

  Server information:
    Checksums            : on
    WAL summarizer       : on

  Base backup information:
    Backup Method        : postgres
    Backup Type          : incremental
    Backup Size          : 5.2 MiB (21.2 MiB with WALs)
    WAL Size             : 16.0 MiB
    Resources saved      : 53.5 MiB (91.14%)
    Timeline             : 1
    Begin WAL            : 00000001000000000000000A
    End WAL              : 00000001000000000000000A
    Number of WALs       : 1
    Begin time           : 2026-11-24 09:19:58.996984+01:00
    End time             : 2026-11-24 09:20:02.630878+01:00
    Copy time            : 3 seconds
    Estimated throughput : 1.4 MiB/s
    Begin Offset         : 40
    End Offset           : 0
    Begin LSN            : 0/A000028
    End LSN              : 0/B000000

  WAL information:
    Number of files      : 0
    Disk usage           : 0 B
    Last available       : 00000001000000000000000A

  Catalog information:
    Retention Policy     : VALID
    Previous Backup      : 20261124T091746
    Next Backup          : - (this is the latest base backup)
    Root Backup          : 20261124T091230
    Parent Backup        : 20261124T091746
    Backup chain size    : 3
[root@lin6 ~]#

For an incremental backup show-backup reports the backup type incremental, the parent backup and an estimation of the resources saved compared to a full backup. Keep in mind that the backups of a chain depend on each other: if you delete a full backup, Barman deletes all incremental backups based on it as well, and barman keep can only be applied to full backups (it then also keeps the dependent incrementals).

5. Prepare the Restores

Never restore into the data directory of a running cluster. In this lab we restore into a new directory on lin8 and start the restored cluster on port 5446 next to the production cluster. In a real disaster you would stop the cluster and restore into its (empty) data directory instead.

5.1 SSH key from barman@lin6 to enterprisedb@lin8

Remote restores use SSH with public key authentication: Barman connects from lin6 as OS user barman to lin8 as enterprisedb.

The obvious tool would be ssh-copy-id, but it does not work here: the EPAS packages create the enterprisedb user without a password, so the account is locked for password logins. Instead, we create the key pair as barman and use root on lin8 to put the public key into enterprisedb’s authorized_keys. You will be asked once for the root password of lin8 (on my test VM: changeme).

# run as root on lin6

# 1. create the key pair for the barman user
su - barman -c "ssh-keygen -t ed25519 -N '' -f ~/.ssh/id_ed25519"

# 2. install the public key for enterprisedb on lin8 (via root on lin8)
cat /var/lib/barman/.ssh/id_ed25519.pub | ssh root@lin8 '
  install -d -m 700 -o enterprisedb -g enterprisedb ~enterprisedb/.ssh &&
  cat >> ~enterprisedb/.ssh/authorized_keys &&
  chown enterprisedb:enterprisedb ~enterprisedb/.ssh/authorized_keys &&
  chmod 600 ~enterprisedb/.ssh/authorized_keys &&
  restorecon -R ~enterprisedb/.ssh'

# 3. test: accepts lin8's host key and must print "lin8" without a password prompt
su - barman -c "ssh -o StrictHostKeyChecking=accept-new enterprisedb@lin8 hostname"

Notes:

  • ~enterprisedb is expanded on lin8, so the command works regardless of the user’s home directory (usually /var/lib/edb).
  • restorecon restores the SELinux labels – with wrong labels sshd ignores authorized_keys and falls back to asking for a password.
  • -o StrictHostKeyChecking=accept-new adds lin8 to barman’s known_hosts without a prompt. Without it, the first connection fails with “Host key verification failed”.
  • Alternatively you could set a password with passwd enterprisedb and use ssh-copy-id – not recommended, as it opens password logins for the database owner.

5.2 Create the target directory on lin8

Barman refuses to restore into a directory that is not empty, so we create a fresh one:

# run as root on lin8
mkdir -p /var/lib/edb/as18/restore
chown enterprisedb:enterprisedb /var/lib/edb/as18/restore
chmod 700 /var/lib/edb/as18/restore

6. Restore the Latest Incremental Backup

When restoring an incremental backup, Barman combines the full backup and all incremental backups of the chain with pg_combinebackup in the staging directory on lin6 (staging_location = local), copies the result with rsync to lin8 and adds the WAL files required for the recovery:

# run as root on lin6
su - barman -c "barman restore --remote-ssh-command 'ssh enterprisedb@lin8' epas18 latest /var/lib/edb/as18/restore"
Sample Output (click to expand):
[root@lin6 ~]# # run as root on lin6
su - barman -c "barman restore --remote-ssh-command 'ssh enterprisedb@lin8' epas18 latest /var/lib/edb/as18/restore"
Starting remote restore for server epas18 using backup 20261124T091958
Destination directory: /var/lib/edb/as18/restore
Remote command: ssh enterprisedb@lin8
Copying the base backup.
Start combining backup via pg_combinebackup for backup 20261124T091958 on /var/lib/barman/staging/barman-combine5259/20261124T091958/data
End combining backup via pg_combinebackup for backup 20261124T091958
Copying required WAL segments.
Generating archive status files
Identify dangerous settings in destination directory.

Restore operation completed (start time: 2026-11-24 09:42:52.636255+01:00, elapsed time: 14 seconds)
Your PostgreSQL server has been successfully prepared for recovery!
[root@lin6 ~]#

Now we start the restored cluster on port 5446 and check the test table. We expect the rows of all three phases:

# run as root on lin8
su - enterprisedb -c "pg_ctl -D /var/lib/edb/as18/restore -o '-p 5446' -l /var/lib/edb/as18/restore/startup.log start"
su - enterprisedb -c "psql -p 5446 -d edb -c \"select phase, count(*) from bkp_test group by phase order by min(id);\""
Sample Output (click to expand):
[root@lin8 ~]# # run as root on lin8
su - enterprisedb -c "pg_ctl -D /var/lib/edb/as18/restore -o '-p 5446' -l /var/lib/edb/as18/restore/startup.log start"
su - enterprisedb -c "psql -p 5446 -d edb -c \"select phase, count(*) from bkp_test group by phase order by min(id);\""
waiting for server to start.... done
server started
        phase        | count
---------------------+-------
 before full backup  |  1000
 after full backup   |   500
 after incremental 1 |   200
(3 rows)

[root@lin8 ~]#

Stop the restored cluster and empty the target directory before the next test:

# run as root on lin8
su - enterprisedb -c "pg_ctl -D /var/lib/edb/as18/restore stop"
rm -rf /var/lib/edb/as18/restore
mkdir -p /var/lib/edb/as18/restore
chown enterprisedb:enterprisedb /var/lib/edb/as18/restore
chmod 700 /var/lib/edb/as18/restore

7. Point-in-Time Recovery (PITR)

Now the classic scenario: someone drops a table by accident, and we want to recover the database to the point in time right before the drop.

7.1 Simulate the user error

We insert some more rows, note the current time and drop the table a few seconds later:

# run as root on lin8
su - enterprisedb -c "psql -d edb" <<'EOF'
insert into bkp_test (phase) select 'before drop' from generate_series(1, 100);
select clock_timestamp() as pitr_target;
select pg_sleep(5);
drop table bkp_test;
EOF
Sample Output (click to expand):
[root@lin8 ~]# # run as root on lin8
su - enterprisedb -c "psql -d edb" <<'EOF'
insert into bkp_test (phase) select 'before drop' from generate_series(1, 100);
select clock_timestamp() as pitr_target;
select pg_sleep(5);
drop table bkp_test;
EOF
INSERT 0 100
           pitr_target
---------------------------------
 24-NOV-26 09:50:03.09303 +01:00
(1 row)

 pg_sleep
----------

(1 row)

DROP TABLE
[root@lin8 ~]#

Write down the timestamp returned by clock_timestamp(). Then we make sure the WAL file containing the DROP TABLE is complete and has arrived in the Barman archive:

# run as root on lin6
su - barman -c "barman switch-wal --force --archive epas18"

7.2 Restore to the point in time

With --target-time we specify the recovery target. Include the time zone, otherwise the time zone of the Barman server is used. Instead of a backup ID we use auto: Barman then selects the most recent backup that finished before the target time. --target-action promote opens the cluster for read/write access as soon as the target is reached.

# run as root on lin6
# replace the timestamp with the value from step 7.1
su - barman -c "barman restore --remote-ssh-command 'ssh enterprisedb@lin8' --target-time '2026-11-23 21:40:12+01' --target-action promote epas18 auto /var/lib/edb/as18/restore"
Sample Output (click to expand):
[root@lin6 ~]# # run as root on lin6
# replace the timestamp with the value from step 7.1
su - barman -c "barman restore --remote-ssh-command 'ssh enterprisedb@lin8' --target-time '2026-11-24 09:50:03+01' --target-action promote epas18 auto /var/lib/edb/as18/restore"
Starting remote restore for server epas18 using backup 20261124T091958
Destination directory: /var/lib/edb/as18/restore
Remote command: ssh enterprisedb@lin8
Doing PITR. Recovery target time: '2026-11-24 09:50:03+01:00'
Copying the base backup.
Start combining backup via pg_combinebackup for backup 20261124T091958 on /var/lib/barman/staging/barman-combine5510/20261124T091958/data
End combining backup via pg_combinebackup for backup 20261124T091958
Copying required WAL segments.
Generating recovery configuration
Identify dangerous settings in destination directory.

Restore operation completed (start time: 2026-11-24 09:52:42.639678+01:00, elapsed time: 12 seconds)
Your PostgreSQL server has been successfully prepared for recovery!
[root@lin6 ~]#

Tip: If you are not sure about the exact time, use --target-action pause. The cluster then stays in recovery at the target and you can check the data read-only before you finish the recovery with select pg_wal_replay_resume();. Besides a timestamp, Barman also supports a transaction ID (--target-xid), an LSN (--target-lsn) and named restore points (--target-name) created with pg_create_restore_point(), e.g. right before a risky deployment.

7.3 Start the cluster and verify the data

# run as root on lin8
su - enterprisedb -c "pg_ctl -D /var/lib/edb/as18/restore -o '-p 5446' -l /var/lib/edb/as18/restore/startup.log start"
su - enterprisedb -c "psql -p 5446 -d edb -c \"select phase, count(*) from bkp_test group by phase order by min(id);\""
Sample Output (click to expand):
[root@lin8 ~]# # run as root on lin8
su - enterprisedb -c "pg_ctl -D /var/lib/edb/as18/restore -o '-p 5446' -l /var/lib/edb/as18/restore/startup.log start"
su - enterprisedb -c "psql -p 5446 -d edb -c \"select phase, count(*) from bkp_test group by phase order by min(id);\""
waiting for server to start.... done
server started
        phase        | count
---------------------+-------
 before full backup  |  1000
 after full backup   |   500
 after incremental 1 |   200
(3 rows)

[root@lin8 ~]#

The table is back, including the 100 rows inserted shortly before the drop. Since the production cluster is still running, we do not need to switch to the restored cluster. We simply copy the table back with pg_dump and clean up afterwards:

# run as root on lin8
su - enterprisedb -c "pg_dump -p 5446 -d edb -t bkp_test | psql -d edb"
su - enterprisedb -c "psql -d edb -c \"select phase, count(*) from bkp_test group by phase order by min(id);\""
su - enterprisedb -c "pg_ctl -D /var/lib/edb/as18/restore stop"
rm -rf /var/lib/edb/as18/restore
Sample Output (click to expand):
[root@lin8 ~]# # run as root on lin8
su - enterprisedb -c "pg_dump -p 5446 -d edb -t bkp_test | psql -d edb"
su - enterprisedb -c "psql -d edb -c \"select phase, count(*) from bkp_test group by phase order by min(id);\""
su - enterprisedb -c "pg_ctl -D /var/lib/edb/as18/restore stop"
rm -rf /var/lib/edb/as18/restore
SET
SET
SET
SET
SET
SET
SET
SET
 set_config
------------

(1 row)

SET
SET
SET
SET
SET
SET
SET
CREATE TABLE
ALTER TABLE
ALTER TABLE
COPY 1700
 setval
--------
   1832
(1 row)

        phase        | count
---------------------+-------
 before full backup  |  1000
 after full backup   |   500
 after incremental 1 |   200
(3 rows)

waiting for server to shut down.... done
server stopped
[root@lin8 ~]#

8. Scheduling and Retention

The cron job installed with the package runs barman cron every minute. It keeps receive-wal running and applies the retention policy, but it does not take backups. A simple schedule with a weekly full backup and daily incremental backups looks like this:

# run as root on lin6
cat > /etc/cron.d/barman-backups <<'EOF'
# weekly full backup on Sunday, incremental backups Monday to Saturday
30 1 * * 0   barman /usr/bin/barman -q backup epas18
30 1 * * 1-6 barman /usr/bin/barman -q backup --incremental latest epas18
EOF

Every incremental backup in a chain has to be combined during a restore, so long chains make restores slower and depend on more backups. A full backup every week keeps the chains short. Backups and WAL files that are no longer needed for the 7-day recovery window are removed automatically by barman cron. For monitoring, barman check epas18 --nagios returns output in Nagios format.

Troubleshooting Common Issues

no pg_hba.conf entry for replication connectionAdd the host replication streaming_barman … line to pg_hba.conf on lin8 and reload the configuration (step 1.3).
barman check: receive-wal running: FAILED or replication slot: FAILEDRun barman cron as user barman and check the Barman log /var/log/barman/barman.log. The slot can also be created manually with barman receive-wal --create-slot epas18.
barman check: WAL archive: FAILEDNo WAL file has been archived yet. Run barman switch-wal --force --archive epas18.
Incremental backup fails because of WAL summarizationsummarize_wal must be on on the EPAS server before the parent backup is taken. Enable it (step 1.1) and take a new full backup.
Restore fails because of a missing staging path or pg_combinebackupCheck staging_path, staging_location and path_prefix in /etc/barman.d/epas18.conf and that the EPAS client package is installed.
Restore fails because the destination directory is not emptyBarman does not overwrite existing files. Empty or recreate the target directory (step 5.2).
PITR fails with recovery ended before configured recovery target was reachedThe WAL after the target time is not yet archived. Run barman switch-wal --force --archive epas18 and restore again.
ssh-copy-id: Host key verification failedThe barman user cannot answer the host key prompt. Connect once with -o StrictHostKeyChecking=accept-new (step 5.1).
enterprisedb@lin8: Permission denied (publickey,…,password)The enterprisedb user has no password, so ssh-copy-id cannot log in. Install the public key via root on lin8 (step 5.1).

Resources

Conclusion

With a dedicated Barman server our EPAS 18 Redwood cluster is now protected by streaming base backups and continuous WAL archiving. Here is a quick recap:

  • summarize_wal = on on the EPAS server enables native block-level incremental backups.
  • backup_method = postgres with streaming_archiver = on needs no SSH for backups and keeps the potential data loss close to zero.
  • barman backup --incremental builds chains of incremental backups on top of a full backup; Barman combines them with pg_combinebackup during the restore.
  • barman restore --target-time (or --target-xid, --target-lsn, --target-name) performs a point-in-time recovery, and auto selects the right backup.
  • Restoring into a separate directory on a different port is a safe way to test restores and to recover single objects without touching the production cluster.

Next Steps:

  • Test restores regularly, ideally automated on a separate test server.
  • Copy the backups to a second location, e.g. object storage with Barman’s cloud features or a geo-redundant Barman server.
  • Combine Barman with a high availability setup (EDB Failover Manager or Patroni) as described in the previous post.
  • Monitor Barman and the replication slot with Postgres Enterprise Manager (PEM) or your existing monitoring.
0
EDB Failover Manager

EDB Failover Manager for EPAS 18 on RHEL 10: Setup and Failover Tests

In my previous post we installed EDB Postgres Advanced Server 18 (EPAS) on a RHEL 10 virtual machine (lin8). A single database server is a single point of failure, so in this post we turn it into a high availability cluster with EDB Failover Manager (EFM): we add a streaming replication standby (lin7) and a witness node (lin6), let a virtual IP address (VIP) follow the primary and then break things on purpose to see how EFM reacts.

EFM is EDB’s high availability tool for primary/standby clusters that use Postgres streaming replication. A Java based agent runs on every node, the agents talk to each other via JGroups, monitor the local databases and, when the primary fails, promote a standby, move the VIP and fence the old primary. At the time of writing the current release is EFM 5.5. Version 5.0 was the first new major release in years: it changed how cluster size and quorum are calculated and introduced the efm create-standby command, which we will use to rebuild nodes after the failover tests.

Why a witness node? EFM needs at least three agents to have a quorum. With only a primary and a standby, the standby cannot distinguish a dead primary from a network split between the two nodes. A third node – either another standby or a lightweight witness that runs only the EFM agent and no database – breaks the tie.

What about pgBouncer? In production, clients often connect through a connection pooler that EFM re-points after a failover. To keep this post focused on EFM itself, clients will use the VIP here. The integration of EDB PgBouncer with EFM, including its own failover tests, will follow in a separate post.

Read More

0
Installing EDB

Installing EnterpriseDB (EDB) Postgres Advanced Server 18 (EPAS) on RHEL 10 – Redwood and Postgres Mode

EDB (EnterpriseDB) is one of the largest contributors to PostgreSQL and offers its own enterprise distributions on top of community PostgreSQL. The most prominent one is EDB Postgres Advanced Server (EPAS), which adds a large set of Oracle compatibility features (PL/SQL syntax, packages, Oracle data types and data dictionary views) as well as additional enterprise tooling. This makes EPAS a popular target for Oracle to Postgres migrations, but it can also be run as a “pure” Postgres server.

In this blog post, we will install EPAS 18 on a Red Hat Enterprise Linux 10 virtual machine. After the base installation we will create two database clusters: one in the Oracle-compatible Redwood mode (the default) and one in Postgres mode. Finally we will compare both modes with a few practical examples.

Read More

0
PostgreSQL IO monitoring

Measuring PostgreSQL per process I/O throughput

PostgreSQL provides excellent monitoring capabilities, but sometimes you need to know something more specific:

Which PostgreSQL process is responsible for the current disk I/O?

With two small Checkmk scripts, you can monitor the I/O throughput of individual PostgreSQL processes and visualize the results directly in Checkmk.

Why monitor PostgreSQL process I/O?

Looking only at the overall database I/O can make it difficult to understand what is happening on a busy PostgreSQL server. Different PostgreSQL processes have very different responsibilities. For example:

  • client_backend processes handle client connections
  • checkpointer writes dirty buffers to disk
  • bgwriter performs background writes
  • walwriter writes WAL data
  • walsender processes handle WAL streaming
  • autovacuum_worker processes perform automatic maintenance
  • parallel workers and PostgreSQL I/O workers can also contribute significantly to the I/O load

Having these processes visible separately in Checkmk makes unusual I/O activity much easier to identify.

The Checkmk local check

The first script is:

/usr/lib/check_mk_agent/local/check_pg_process_io.sh

The script reads the Linux process I/O counters from:

/proc/<pid>/io

For each PostgreSQL process, it determines the process role, for example checkpointer, walwriter, autovacuum_worker or client_backend.

Processes belonging to the same role are aggregated. The script stores the previous cumulative counters and calculates the difference over time to determine the current I/O throughput in bytes per second.

Both read and write throughput are exported as Checkmk performance data.

Script: (click to expand)
#!/usr/bin/bash
# ---------------------------------------------------------------------------
# Checkmk local check: per-process disk I/O for all PostgreSQL processes.
#
# Emits ONE service whose perfdata contains both read and write metrics:
#   read_bytes_<role>   -> graph "PostgreSQL process read I/O"
#   write_bytes_<role>  -> graph "PostgreSQL process write I/O"
# One line per PostgreSQL role in each graph.
#
# IMPORTANT: perfdata items are separated by '|' (pipe), as required by the
# Checkmk local check protocol.
#
# Install: /usr/lib/check_mk_agent/local/check_pg_process_io.sh  (chmod 0700)
# Requires: bash 4+, Checkmk agent running as root (to read /proc/<pid>/io)
# ---------------------------------------------------------------------------

# ---------------------------- CONFIG ---------------------------------------
PG_USER="postgres"
WARN_BPS=$((10 * 1024 * 1024))     # 10 MB/s per series
CRIT_BPS=$((50 * 1024 * 1024))     # 50 MB/s per series
SKIP_NON_SERVER_PROCS="true"       # true  -> drop psql / bash / (sd-pam)
STATE_ROOT="/var/lib/check_mk_agent/pg_proc_io"
SERVICE_NAME="PostgreSQL process I/O"
# ---------------------------------------------------------------------------

NOW=$(date +%s)
mkdir -p "$STATE_ROOT/read_bytes" "$STATE_ROOT/write_bytes" 2>/dev/null

# Map a cmdline like "postgres: 18/main: checkpointer process" to a stable
# role label such as "checkpointer". Handles PG 9.x .. 18+ naming schemes,
# PG 18 io workers / walsummarizer, and PG 18 client backends (which no
# longer use the "client backend" keyword on the cmdline).
#
# Returns non-zero if the process should be skipped.
normalize_role() {
    local cmd
    cmd=$(printf '%s' "$1" \
        | sed -E 's/^postgres:[[:space:]]*//' \
        | sed -E 's/^[0-9]+(\/[^:[:space:]]+)?:[[:space:]]*//' \
        | sed -E 's/[[:space:]]+process$//' \
        | sed -E 's/[[:space:]]+$//')

    case "$cmd" in
        # --- named PostgreSQL roles -------------------------------------
        "background writer")                     echo "bgwriter";;
        "autovacuum worker"*)                    echo "autovacuum_worker";;
        "autovacuum launcher")                   echo "autovacuum_launcher";;
        "logical replication launcher")          echo "logical_replication_launcher";;
        "logical replication tablesync worker"*) echo "logical_replication_tablesync_worker";;
        "logical replication worker"*)           echo "logical_replication_worker";;
        "parallel worker"*)                      echo "parallel_worker";;
        "checkpointer")                          echo "checkpointer";;
        "walwriter")                             echo "walwriter";;
        "walsender")                             echo "walsender";;
        "walreceiver")                           echo "walreceiver";;
        "archiver")                              echo "archiver";;
        "startup")                               echo "startup";;

        # --- PostgreSQL 18+ new process types ---------------------------
        "io worker "*)                           echo "$(printf '%s' "$cmd" | tr ' ' '_')";;
        "walsummarizer")                         echo "walsummarizer";;

        # --- postmaster (raw binary path, no "postgres:" prefix) -------
        */bin/postgres\ -*)                      echo "postmaster";;
        "postgres"|"")                           echo "postmaster";;

        # --- non-server processes owned by the postgres user -----------
        "psql"*|"bash"|"sh"|"-bash"|"-sh"|"(sd-pam)"|"sd-pam")
            if [ "$SKIP_NON_SERVER_PROCS" = "true" ]; then
                return 1
            fi
            printf '%s' "$cmd" | sed 's/[^A-Za-z0-9_]/_/g'
            ;;

        # --- anything else with multiple fields = client backend --------
        *[[:space:]]*)                           echo "client_backend";;

        # --- truly unknown: sanitised as-is ----------------------------
        *) printf '%s' "$cmd" | sed 's/[^A-Za-z0-9_]/_/g';;
    esac
}

# -------- Collect cumulative read/write counters per role --------
declare -A READ_TOTALS=()
declare -A WRITE_TOTALS=()

for PID in $(pgrep -u "$PG_USER" 2>/dev/null); do
    IO_FILE="/proc/$PID/io"
    [ -r "$IO_FILE" ] || continue

    R=$(awk '/^read_bytes:/  {print $2}' "$IO_FILE" 2>/dev/null)
    W=$(awk '/^write_bytes:/ {print $2}' "$IO_FILE" 2>/dev/null)
    [ -z "$R" ] && continue
    [ -z "$W" ] && W=0

    CMD=$(tr '\0' ' ' < "/proc/$PID/cmdline" 2>/dev/null | sed 's/[[:space:]]*$//')
    [ -z "$CMD" ] && CMD=$(cat "/proc/$PID/comm" 2>/dev/null)

    ROLE=$(normalize_role "$CMD") || continue

    # All PIDs of the same role are summed into one metric.
    READ_TOTALS[$ROLE]=$(( ${READ_TOTALS[$ROLE]:-0} + R ))
    WRITE_TOTALS[$ROLE]=$(( ${WRITE_TOTALS[$ROLE]:-0} + W ))
done

if [ "${#READ_TOTALS[@]}" -eq 0 ]; then
    echo "3 \"$SERVICE_NAME\" - No readable PostgreSQL processes (agent must run as root)"
    exit 0
fi

# -------- Compute rates and build perfdata --------
# Perfdata items are separated by '|' (pipe), as required by Checkmk.
PERFDATA=""
WORST=0

compute_rate() {
    local STATE_FILE="$1" CUR="$2"
    local LAST=0 LAST_TS=0
    if [ -f "$STATE_FILE" ]; then
        read -r LAST LAST_TS < "$STATE_FILE" 2>/dev/null || true
        LAST=${LAST:-0}; LAST_TS=${LAST_TS:-0}
    fi
    printf '%s %s\n' "$CUR" "$NOW" > "$STATE_FILE"
    [ "$LAST_TS" -eq 0 ] && return
    local DT=$((NOW - LAST_TS))
    [ "$DT" -le 0 ] && return
    local DB=$((CUR - LAST))
    [ "$DB" -lt 0 ] && DB=0
    echo $((DB / DT))
}

for ROLE in "${!READ_TOTALS[@]}"; do
    R_RATE=$(compute_rate "$STATE_ROOT/read_bytes/$ROLE"  "${READ_TOTALS[$ROLE]}")
    W_RATE=$(compute_rate "$STATE_ROOT/write_bytes/$ROLE" "${WRITE_TOTALS[$ROLE]:-0}")

    [ -n "$R_RATE" ] && PERFDATA="${PERFDATA}read_bytes_${ROLE}=${R_RATE}B/s;${WARN_BPS};${CRIT_BPS}|"
    [ -n "$W_RATE" ] && PERFDATA="${PERFDATA}write_bytes_${ROLE}=${W_RATE}B/s;${WARN_BPS};${CRIT_BPS}|"

    for RATE in "$R_RATE" "$W_RATE"; do
        [ -z "$RATE" ] && continue
        if   [ "$RATE" -ge "$CRIT_BPS" ]; then WORST=2
        elif [ "$RATE" -ge "$WARN_BPS" ] && [ "$WORST" -lt 2 ]; then WORST=1
        fi
    done
done

# -------- Drop state for roles that no longer exist --------
for METRIC_DIR in "$STATE_ROOT/read_bytes" "$STATE_ROOT/write_bytes"; do
    for f in "$METRIC_DIR"/*; do
        [ -f "$f" ] || continue
        base=$(basename "$f")
        keep=0
        for ROLE in "${!READ_TOTALS[@]}"; do
            [ "$ROLE" = "$base" ] && keep=1 && break
        done
        [ "$keep" -eq 0 ] && rm -f "$f"
    done
done

case $WORST in
    2) TXT="CRITICAL";;
    1) TXT="WARNING";;
    *) TXT="OK";;
esac

if [ -z "$PERFDATA" ]; then
    echo "0 \"$SERVICE_NAME\" - Initializing (waiting for second sample)"
    exit 0
fi

# Strip the trailing pipe
PERFDATA="${PERFDATA%|}"

echo "$WORST \"$SERVICE_NAME\" ${PERFDATA} ${TXT} - read/write bytes/s per PostgreSQL process"

Configurable thresholds

The script uses configurable warning and critical thresholds:

WARN_MBPS=10
CRIT_MBPS=50

This allows Checkmk to report a warning or critical state when an individual PostgreSQL process role exceeds the configured I/O throughput.

The Checkmk agent must run with sufficient privileges to read /proc/<pid>/io.

The Checkmk graphing plugin

The second script is:

~/local/lib/python3/cmk_addons/plugins/pg_process_io/graphing/pg_process_io.py (owner: mon group: mon file mode: 0600)

This Python plugin defines the Checkmk metrics for the different PostgreSQL process roles and creates two graphs.

Script: (click to expand):
#!/usr/bin/env python3
# ~/local/lib/python3/cmk_addons/plugins/pg_process_io/graphing/pg_process_io.py
# s.a. https://docs.checkmk.com/plugin-api/latest/cmk.graphing/v1.graphs.html#cmk.graphing.v1.graphs.Graph

from cmk.graphing.v1 import Title
from cmk.graphing.v1.graphs import Graph, MinimalRange
from cmk.graphing.v1.metrics import Color, IECNotation, Metric, Unit

UNIT_BPS = Unit(IECNotation("B/s"))

# ---------------------------------------------------------------
# Read metrics (one per PostgreSQL role)
# ---------------------------------------------------------------
metric_read_bytes_postmaster = Metric(
    name="read_bytes_postmaster",
    title=Title("Read postmaster"),
    unit=UNIT_BPS,
    color=Color.LIGHT_RED,
)
metric_read_bytes_checkpointer = Metric(
    name="read_bytes_checkpointer",
    title=Title("Read checkpointer"),
    unit=UNIT_BPS,
    color=Color.RED,
)
metric_read_bytes_bgwriter = Metric(
    name="read_bytes_bgwriter",
    title=Title("Read bgwriter"),
    unit=UNIT_BPS,
    color=Color.DARK_RED,
)
metric_read_bytes_walwriter = Metric(
    name="read_bytes_walwriter",
    title=Title("Read walwriter"),
    unit=UNIT_BPS,
    color=Color.LIGHT_ORANGE,
)
metric_read_bytes_walsender = Metric(
    name="read_bytes_walsender",
    title=Title("Read walsender"),
    unit=UNIT_BPS,
    color=Color.ORANGE,
)
metric_read_bytes_walreceiver = Metric(
    name="read_bytes_walreceiver",
    title=Title("Read walreceiver"),
    unit=UNIT_BPS,
    color=Color.DARK_ORANGE,
)
metric_read_bytes_archiver = Metric(
    name="read_bytes_archiver",
    title=Title("Read archiver"),
    unit=UNIT_BPS,
    color=Color.LIGHT_YELLOW,
)
metric_read_bytes_startup = Metric(
    name="read_bytes_startup",
    title=Title("Read startup"),
    unit=UNIT_BPS,
    color=Color.YELLOW,
)
metric_read_bytes_io_worker_0 = Metric(
    name="read_bytes_io_worker_0",
    title=Title("Read io_worker_0"),
    unit=UNIT_BPS,
    color=Color.DARK_YELLOW,
)
metric_read_bytes_io_worker_1 = Metric(
    name="read_bytes_io_worker_1",
    title=Title("Read io_worker_1"),
    unit=UNIT_BPS,
    color=Color.LIGHT_GREEN,
)
metric_read_bytes_io_worker_2 = Metric(
    name="read_bytes_io_worker_2",
    title=Title("Read io_worker_2"),
    unit=UNIT_BPS,
    color=Color.GREEN,
)
metric_read_bytes_walsummarizer = Metric(
    name="read_bytes_walsummarizer",
    title=Title("Read walsummarizer"),
    unit=UNIT_BPS,
    color=Color.DARK_GREEN,
)
metric_read_bytes_autovacuum_launcher = Metric(
    name="read_bytes_autovacuum_launcher",
    title=Title("Read autovacuum_launcher"),
    unit=UNIT_BPS,
    color=Color.LIGHT_BLUE,
)
metric_read_bytes_autovacuum_worker = Metric(
    name="read_bytes_autovacuum_worker",
    title=Title("Read autovacuum_worker"),
    unit=UNIT_BPS,
    color=Color.BLUE,
)
metric_read_bytes_logical_replication_launcher = Metric(
    name="read_bytes_logical_replication_launcher",
    title=Title("Read logical_replication_launcher"),
    unit=UNIT_BPS,
    color=Color.DARK_BLUE,
)
metric_read_bytes_logical_replication_worker = Metric(
    name="read_bytes_logical_replication_worker",
    title=Title("Read logical_replication_worker"),
    unit=UNIT_BPS,
    color=Color.LIGHT_CYAN,
)
metric_read_bytes_logical_replication_tablesync_worker = Metric(
    name="read_bytes_logical_replication_tablesync_worker",
    title=Title("Read logical_replication_tablesync_worker"),
    unit=UNIT_BPS,
    color=Color.CYAN,
)
metric_read_bytes_parallel_worker = Metric(
    name="read_bytes_parallel_worker",
    title=Title("Read parallel_worker"),
    unit=UNIT_BPS,
    color=Color.DARK_CYAN,
)
metric_read_bytes_client_backend = Metric(
    name="read_bytes_client_backend",
    title=Title("Read client_backend"),
    unit=UNIT_BPS,
    color=Color.LIGHT_PURPLE,
)

# ---------------------------------------------------------------
# Write metrics (one per PostgreSQL role)
# ---------------------------------------------------------------
metric_write_bytes_postmaster = Metric(
    name="write_bytes_postmaster",
    title=Title("Write postmaster"),
    unit=UNIT_BPS,
    color=Color.LIGHT_RED,
)
metric_write_bytes_checkpointer = Metric(
    name="write_bytes_checkpointer",
    title=Title("Write checkpointer"),
    unit=UNIT_BPS,
    color=Color.RED,
)
metric_write_bytes_bgwriter = Metric(
    name="write_bytes_bgwriter",
    title=Title("Write bgwriter"),
    unit=UNIT_BPS,
    color=Color.DARK_RED,
)
metric_write_bytes_walwriter = Metric(
    name="write_bytes_walwriter",
    title=Title("Write walwriter"),
    unit=UNIT_BPS,
    color=Color.LIGHT_ORANGE,
)
metric_write_bytes_walsender = Metric(
    name="write_bytes_walsender",
    title=Title("Write walsender"),
    unit=UNIT_BPS,
    color=Color.ORANGE,
)
metric_write_bytes_walreceiver = Metric(
    name="write_bytes_walreceiver",
    title=Title("Write walreceiver"),
    unit=UNIT_BPS,
    color=Color.DARK_ORANGE,
)
metric_write_bytes_archiver = Metric(
    name="write_bytes_archiver",
    title=Title("Write archiver"),
    unit=UNIT_BPS,
    color=Color.LIGHT_YELLOW,
)
metric_write_bytes_startup = Metric(
    name="write_bytes_startup",
    title=Title("Write startup"),
    unit=UNIT_BPS,
    color=Color.YELLOW,
)
metric_write_bytes_io_worker_0 = Metric(
    name="write_bytes_io_worker_0",
    title=Title("Write io_worker_0"),
    unit=UNIT_BPS,
    color=Color.DARK_YELLOW,
)
metric_write_bytes_io_worker_1 = Metric(
    name="write_bytes_io_worker_1",
    title=Title("Write io_worker_1"),
    unit=UNIT_BPS,
    color=Color.LIGHT_GREEN,
)
metric_write_bytes_io_worker_2 = Metric(
    name="write_bytes_io_worker_2",
    title=Title("Write io_worker_2"),
    unit=UNIT_BPS,
    color=Color.GREEN,
)
metric_write_bytes_walsummarizer = Metric(
    name="write_bytes_walsummarizer",
    title=Title("Write walsummarizer"),
    unit=UNIT_BPS,
    color=Color.DARK_GREEN,
)
metric_write_bytes_autovacuum_launcher = Metric(
    name="write_bytes_autovacuum_launcher",
    title=Title("Write autovacuum_launcher"),
    unit=UNIT_BPS,
    color=Color.LIGHT_BLUE,
)
metric_write_bytes_autovacuum_worker = Metric(
    name="write_bytes_autovacuum_worker",
    title=Title("Write autovacuum_worker"),
    unit=UNIT_BPS,
    color=Color.BLUE,
)
metric_write_bytes_logical_replication_launcher = Metric(
    name="write_bytes_logical_replication_launcher",
    title=Title("Write logical_replication_launcher"),
    unit=UNIT_BPS,
    color=Color.DARK_BLUE,
)
metric_write_bytes_logical_replication_worker = Metric(
    name="write_bytes_logical_replication_worker",
    title=Title("Write logical_replication_worker"),
    unit=UNIT_BPS,
    color=Color.LIGHT_CYAN,
)
metric_write_bytes_logical_replication_tablesync_worker = Metric(
    name="write_bytes_logical_replication_tablesync_worker",
    title=Title("Write logical_replication_tablesync_worker"),
    unit=UNIT_BPS,
    color=Color.CYAN,
)
metric_write_bytes_parallel_worker = Metric(
    name="write_bytes_parallel_worker",
    title=Title("Write parallel_worker"),
    unit=UNIT_BPS,
    color=Color.DARK_CYAN,
)
metric_write_bytes_client_backend = Metric(
    name="write_bytes_client_backend",
    title=Title("Write client_backend"),
    unit=UNIT_BPS,
    color=Color.LIGHT_PURPLE,
)

# ---------------------------------------------------------------
# Combined graphs
# ---------------------------------------------------------------
graph_pg_process_read_bytes = Graph(
    name="pg_process_read_bytes",
    title=Title("PostgreSQL process read I/O"),
    simple_lines=[
        "read_bytes_archiver",
        "read_bytes_autovacuum_launcher",
        "read_bytes_autovacuum_worker",
        "read_bytes_bgwriter",
        "read_bytes_checkpointer",
        "read_bytes_client_backend",
        "read_bytes_io_worker_0",
        "read_bytes_io_worker_1",
        "read_bytes_io_worker_2",
        "read_bytes_logical_replication_launcher",
        "read_bytes_logical_replication_tablesync_worker",
        "read_bytes_logical_replication_worker",
        "read_bytes_parallel_worker",
        "read_bytes_postmaster",
        "read_bytes_startup",
        "read_bytes_walreceiver",
        "read_bytes_walsender",
        "read_bytes_walsummarizer",
        "read_bytes_walwriter",
    ],
    optional=[
        "read_bytes_archiver",
        "read_bytes_autovacuum_launcher",
        "read_bytes_autovacuum_worker",
        "read_bytes_bgwriter",
        "read_bytes_checkpointer",
        "read_bytes_client_backend",
        "read_bytes_io_worker_0",
        "read_bytes_io_worker_1",
        "read_bytes_io_worker_2",
        "read_bytes_logical_replication_launcher",
        "read_bytes_logical_replication_tablesync_worker",
        "read_bytes_logical_replication_worker",
        "read_bytes_parallel_worker",
        "read_bytes_postmaster",
        "read_bytes_startup",
        "read_bytes_walreceiver",
        "read_bytes_walsender",
        "read_bytes_walsummarizer",
        "read_bytes_walwriter",
    ],
)

graph_pg_process_write_bytes = Graph(
    name="pg_process_write_bytes",
    title=Title("PostgreSQL process write I/O"),
    simple_lines=[
        "write_bytes_archiver",
        "write_bytes_autovacuum_launcher",
        "write_bytes_autovacuum_worker",
        "write_bytes_bgwriter",
        "write_bytes_checkpointer",
        "write_bytes_client_backend",
        "write_bytes_io_worker_0",
        "write_bytes_io_worker_1",
        "write_bytes_io_worker_2",
        "write_bytes_logical_replication_launcher",
        "write_bytes_logical_replication_tablesync_worker",
        "write_bytes_logical_replication_worker",
        "write_bytes_parallel_worker",
        "write_bytes_postmaster",
        "write_bytes_startup",
        "write_bytes_walreceiver",
        "write_bytes_walsender",
        "write_bytes_walsummarizer",
        "write_bytes_walwriter",
    ],
    optional=[
        "write_bytes_archiver",
        "write_bytes_autovacuum_launcher",
        "write_bytes_autovacuum_worker",
        "write_bytes_bgwriter",
        "write_bytes_checkpointer",
        "write_bytes_client_backend",
        "write_bytes_io_worker_0",
        "write_bytes_io_worker_1",
        "write_bytes_io_worker_2",
        "write_bytes_logical_replication_launcher",
        "write_bytes_logical_replication_tablesync_worker",
        "write_bytes_logical_replication_worker",
        "write_bytes_parallel_worker",
        "write_bytes_postmaster",
        "write_bytes_startup",
        "write_bytes_walreceiver",
        "write_bytes_walsender",
        "write_bytes_walsummarizer",
        "write_bytes_walwriter",
    ],
)

PostgreSQL process read I/O

The first graph shows the read throughput of the individual PostgreSQL process types.

This makes it possible to see, for example, whether a sudden increase in database read activity is coming from client backends, autovacuum workers, the checkpointer or another PostgreSQL process.

PostgreSQL process write I/O

The second graph shows the corresponding write throughput.

This is particularly useful when investigating high write activity caused by checkpoints, WAL processing, autovacuum or application workloads.

What you get in Checkmk

The local check creates a Checkmk service called: PostgreSQL process I/O

The service provides performance data for the different PostgreSQL process roles. The graphing plugin then presents the data as two separate graphs:

PostgreSQL process read I/O

and

PostgreSQL process write I/O

Instead of looking at a single aggregated database I/O value, you can see which PostgreSQL process role is responsible for the activity.

Supported PostgreSQL processes

The graphing plugin includes metrics for process types such as:

  • postmaster
  • checkpointer
  • bgwriter
  • walwriter
  • walsender
  • walreceiver
  • archiver
  • startup
  • io_worker_0
  • io_worker_1
  • io_worker_2
  • walsummarizer
  • autovacuum_launcher
  • autovacuum_worker
  • logical_replication_launcher
  • logical_replication_worker
  • tablesync_worker
  • parallel_worker
  • client_backend

This also makes the solution useful across PostgreSQL versions where additional background processes are present.

Conclusion

Monitoring PostgreSQL I/O per process provides another useful level of visibility for database performance analysis. With check_pg_process_io.sh and pg_process_io.py, Checkmk can show read and write throughput for individual PostgreSQL process roles. This makes troubleshooting high I/O activity much easier and helps answer a practical question:

Which PostgreSQL process is currently causing high I/O load?

For PostgreSQL administrators using Checkmk, this is a relatively small addition that can provide valuable insight when investigating database performance and storage activity.

0
Patroni

Deploying a High-Availability PostgreSQL 18 Cluster on RedHat 10 with Patroni

Introduction

PostgreSQL is one of the most powerful open-source relational databases, and PostgreSQL 18 brings even more performance, security, and scalability improvements. But how do you ensure high availability (HA) and automatic failover for your critical applications?

In this guide, we will walk you through setting up a PostgreSQL 18 cluster on three Red Hat Enterprise Linux 10 VMs using Patroni — a popular open-source tool for managing PostgreSQL HA clusters. All data on the leader node will be preserved and replicated to the other 2 nodes. By the end, you will have a fully redundant, self-healing database cluster ready for production workloads.

Why Patroni?

  • Automatic failover: No manual intervention needed if the primary node fails.
  • Synchronous replication: Data consistency across all nodes.
  • REST API: Easy monitoring and management.
  • Integration with etcd/consul: Distributed configuration and leader election.

Who is this for?

  • DevOps engineers
  • Database administrators
  • Sysadmins managing critical PostgreSQL workloads

Architecture

Production / Large-Scale Environment Design
For large-scale production environments managing multiple Patroni PostgreSQL clusters (e.g., up to 10 clusters with 2–4 replicas each), the established best practice is to deploy a dedicated, external etcd cluster. We implement this using a 3‑node etcd ensemble (running exclusively etcd) to serve as the centralized Distributed Configuration Store (DCS) for all database clusters. This decoupled architecture ensures optimal resource isolation, prevents I/O and CPU contention with database workloads, simplifies operational maintenance (e.g., backups, monitoring, and upgrades), and guarantees a robust Raft consensus quorum for stable leader elections across the entire PostgreSQL fleet.

Test / Development Environment
In contrast, our test and development systems deliberately consolidate the stack to reduce infrastructure footprint and simplify bootstrapping. In this environment, we run PostgreSQL, Patroni, and etcd collocated on the same 3 nodes. While this all‑in‑one setup is perfectly sufficient for validation, functional testing, and rapid prototyping, we strictly avoid this configuration in production due to the increased risk of resource starvation and cascading failures when a single node becomes overloaded.


Prerequisites

Before we begin, ensure you have the following:

Hardware/Software Requirements

RequirementDetails
Operating SystemRed Hat Enterprise Linux 10 (RHEL 10) on all 3 nodes (Minimum 4GB RAM, 2 vCPUs, 50GB storage per VM).
NetworkStatic IPs for all nodes, firewall rules allowing traffic on ports 2379 (etcd), 5432 (PostgreSQL), 8008 (Patroni REST API)
Root/Sudo AccessFull administrative privileges on both VMs

Assumptions

  • All three nodes are fresh RHEL 10 installations as described in this post.
  • You are comfortable with Linux command line and basic networking.
  • You have sudo/root access on both VMs.

1. Install PostgreSQL 18

First we need to install PostgreSQL 18 on all 3 nodes as described in this post: 1. Installing PostgreSQL 18 on RHEL 10.


2. Prepare the OS

2.1 Install the required OS packages

The following packages need to be installed on all nodes:

# run as root on all nodes
dnf -y update
dnf install -y https://dl.fedoraproject.org/pub/epel/epel-release-latest-10.noarch.rpm
dnf config-manager --set-enabled codeready-builder-for-rhel-10-x86_64-rpms
dnf config-manager --enable pgdg-rhel10-extras
dnf -y install patroni patroni-etcd etcd

Note: The patroni-etcd package provides the necessary dependencies for Patroni to communicate with etcd.

2.2 (Optional) Configure firewalld

If you have a active firewall (firewalld) on the nodes you need to open specific ports to allow communication:

# run as root on all nodes
firewall-cmd --permanent --add-port={2379,2380}/tcp   # etcd
firewall-cmd --permanent --add-port={5432,5433}/tcp   # PostgreSQL
firewall-cmd --permanent --add-port=8008/tcp          # Patroni API
firewall-cmd --reload

3. Setup and Start etcd

In a Patroni cluster, etcd serves as the distributed consensus store that acts as the cluster’s “control plane.” Its primary job is to manage the leader election lock, ensuring that only one PostgreSQL node holds the Primary role at any given time. It also stores the definitive cluster state—including the current leader, replica positions (LSNs), and configuration—which all Patroni nodes continuously watch to stay synchronized. By providing strong consistency and fault-tolerance, etcd guarantees that Patroni can execute safe, automatic failovers without the risk of “split-brain” scenarios. The following script can be run on any of the three nodes as root. It will ask for the member nodes of the cluster (the first one entered will be the leader node where data will be preserved) and will create command snippets that need to be run on each node to configure and start etcd (The script by itself doesn’t change anything on the system):

#!/bin/bash
# etcd-config-generator

echo "=== etcd cluster configuration generator ==="
read -p "Enter comma separated node names (e.g., lin1,lin2,lin3): " NODES
[ -z "$NODES" ] && echo "No nodes given." && exit 1

read -p "Cluster token [etcd-cluster-01]: " TOKEN
TOKEN="${TOKEN:-etcd-cluster-01}"
read -p "Cluster state [new]: " STATE
STATE="${STATE:-new}"

IFS=',' read -ra NODE_ARRAY <<< "$NODES"

# Reset arrays to avoid duplicate accumulation when script is re-sourced
NAMES=()
IPS=()

for node in "${NODE_ARRAY[@]}"; do
    node="$(echo "$node" | xargs)"          # trim whitespace
    [ -z "$node" ] && continue
    NAMES+=("$node")
    # Resolve IP
    ip="$(getent ahosts "$node" 2>/dev/null | head -n1 | awk '{print $1}')"
    if [ -z "$ip" ]; then
        if [[ "$node" =~ ^[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
            ip="$node"
        else
            echo "ERROR: Cannot resolve '$node' and it's not an IP." >&2
            exit 1
        fi
    fi
    IPS+=("$ip")
done

# Build initial cluster string
INITIAL_CLUSTER=""
for i in "${!NAMES[@]}"; do
    [ $i -gt 0 ] && INITIAL_CLUSTER+=","
    INITIAL_CLUSTER+="${NAMES[$i]}=http://${IPS[$i]}:2380"
done

# Generate snippets – each includes the systemctl start command
for i in "${!NAMES[@]}"; do
    name="${NAMES[$i]}"
    ip="${IPS[$i]}"
    echo "------------------------------------------------------------"
    echo "# On node $name (IP $ip), run the following block:"
    cat <<EOF
mkdir -p /etc/etcd
cat > /etc/etcd/etcd.conf <<'ETCDEOF'
# [Member]
ETCD_NAME="${name}"
ETCD_DATA_DIR="/var/lib/etcd/default.etcd"
ETCD_LISTEN_PEER_URLS="http://${ip}:2380"
ETCD_LISTEN_CLIENT_URLS="http://${ip}:2379,http://127.0.0.1:2379"

# [Clustering]
ETCD_INITIAL_ADVERTISE_PEER_URLS="http://${ip}:2380"
ETCD_ADVERTISE_CLIENT_URLS="http://${ip}:2379"
ETCD_INITIAL_CLUSTER="${INITIAL_CLUSTER}"
ETCD_INITIAL_CLUSTER_TOKEN="${TOKEN}"
ETCD_INITIAL_CLUSTER_STATE="${STATE}"
ETCDEOF
systemctl enable etcd --now
EOF
    echo
done
Sample Script Output (click to expand):
=== etcd cluster configuration generator ===
Enter comma separated node names (e.g., lin1,lin2,lin3): lin6,lin7,lin8
Cluster token [etcd-cluster-01]:
Cluster state [new]:
------------------------------------------------------------
# On node lin6 (IP 11.1.1.186), run the following block:
mkdir -p /etc/etcd
cat > /etc/etcd/etcd.conf <<'ETCDEOF'
# [Member]
ETCD_NAME="lin6"
ETCD_DATA_DIR="/var/lib/etcd/default.etcd"
ETCD_LISTEN_PEER_URLS="http://11.1.1.186:2380"
ETCD_LISTEN_CLIENT_URLS="http://11.1.1.186:2379,http://127.0.0.1:2379"

# [Clustering]
ETCD_INITIAL_ADVERTISE_PEER_URLS="http://11.1.1.186:2380"
ETCD_ADVERTISE_CLIENT_URLS="http://11.1.1.186:2379"
ETCD_INITIAL_CLUSTER="lin6=http://11.1.1.186:2380,lin7=http://11.1.1.195:2380,lin8=http://11.1.1.196:2380"
ETCD_INITIAL_CLUSTER_TOKEN="etcd-cluster-01"
ETCD_INITIAL_CLUSTER_STATE="new"
ETCDEOF
systemctl enable etcd --now

------------------------------------------------------------
# On node lin7 (IP 11.1.1.195), run the following block:
mkdir -p /etc/etcd
cat > /etc/etcd/etcd.conf <<'ETCDEOF'
# [Member]
ETCD_NAME="lin7"
ETCD_DATA_DIR="/var/lib/etcd/default.etcd"
ETCD_LISTEN_PEER_URLS="http://11.1.1.195:2380"
ETCD_LISTEN_CLIENT_URLS="http://11.1.1.195:2379,http://127.0.0.1:2379"

# [Clustering]
ETCD_INITIAL_ADVERTISE_PEER_URLS="http://11.1.1.195:2380"
ETCD_ADVERTISE_CLIENT_URLS="http://11.1.1.195:2379"
ETCD_INITIAL_CLUSTER="lin6=http://11.1.1.186:2380,lin7=http://11.1.1.195:2380,lin8=http://11.1.1.196:2380"
ETCD_INITIAL_CLUSTER_TOKEN="etcd-cluster-01"
ETCD_INITIAL_CLUSTER_STATE="new"
ETCDEOF
systemctl enable etcd --now

------------------------------------------------------------
# On node lin8 (IP 11.1.1.196), run the following block:
mkdir -p /etc/etcd
cat > /etc/etcd/etcd.conf <<'ETCDEOF'
# [Member]
ETCD_NAME="lin8"
ETCD_DATA_DIR="/var/lib/etcd/default.etcd"
ETCD_LISTEN_PEER_URLS="http://11.1.1.196:2380"
ETCD_LISTEN_CLIENT_URLS="http://11.1.1.196:2379,http://127.0.0.1:2379"

# [Clustering]
ETCD_INITIAL_ADVERTISE_PEER_URLS="http://11.1.1.196:2380"
ETCD_ADVERTISE_CLIENT_URLS="http://11.1.1.196:2379"
ETCD_INITIAL_CLUSTER="lin6=http://11.1.1.186:2380,lin7=http://11.1.1.195:2380,lin8=http://11.1.1.196:2380"
ETCD_INITIAL_CLUSTER_TOKEN="etcd-cluster-01"
ETCD_INITIAL_CLUSTER_STATE="new"
ETCDEOF
systemctl enable etcd --now

[root@lin6 ~]#

After the generated commands are run on all 3 nodes etcd should be active. You can verify the state of etcd with:

# run as root
etcdctl member list
# and with
etcdctl endpoint health --cluster

Expected Output:

[root@lin6 ~]# etcdctl member list
bbe914cd14e288f, started, lin7, http://11.1.1.195:2380, http://11.1.1.195:2379, false
2c828c931533228f, started, lin8, http://11.1.1.196:2380, http://11.1.1.196:2379, false
60432468aecdf222, started, lin6, http://11.1.1.186:2380, http://11.1.1.186:2379, false
[root@lin6 ~]# etcdctl endpoint health --cluster
http://11.1.1.186:2379 is healthy: successfully committed proposal: took = 3.529991ms
http://11.1.1.195:2379 is healthy: successfully committed proposal: took = 4.110628ms
http://11.1.1.196:2379 is healthy: successfully committed proposal: took = 12.164748ms
[root@lin6 ~]#

4. Setup and Start Patroni

Patroni is an open‑source “maestro” for PostgreSQL that automates high‑availability and replication management. Its primary job is to monitor the health of all PostgreSQL instances and orchestrate automatic failover—promoting a replica to primary if the current leader fails—without manual intervention. To coordinate this safely, Patroni relies on a distributed consensus store (etcd in our case) that holds the cluster’s state and manages leader election locks, ensuring every node agrees on who the primary is at all times. By combining robust health checks with a consistent control plane, Patroni gives you resilient, self‑healing PostgreSQL clusters that minimise downtime and data loss. The following steps will preserve the data on the leader node (the one entered first in the scripts node list), configure and start Patroni. Two replicas of the leader node will be created.

4.1 Create the PostgreSQL replication user

For the replication to work we need a PostgreSQL database user (rep_user) on the leader node:

# run as root on the leader node
su - postgres -c "psql -c \"create user rep_user with replication encrypted password 'changeme';\""

4.2 Configure and Start Patroni

First we need to stop and disable PostgreSQL 18 on all nodes. Also we disable automatic startup by systemd:

# run as root on all nodes
systemctl stop postgresql-18
systemctl disable postgresql-18

Now as we did for the etcd config we will run a script on one of the nodes that will create commands to run on each node. After that Patroni will be enabled and started:

#!/bin/bash
# patroni-config-generator – no bootstrap (manual user creation)

unset ORDERED_NAMES ORDERED_IPS UNIQUE_IPS

echo "=== Patroni cluster configuration generator ==="
echo "Note: The FIRST node you enter will be the initial leader."
read -p "Enter comma separated node names (e.g., lin1,lin2,lin3): " NODES
[ -z "$NODES" ] && echo "No nodes given." && exit 1

read -p "Cluster scope [pgcluster]: " SCOPE
SCOPE="${SCOPE:-pgcluster}"

read -p "Superuser password [changeme]: " SUPERPW
SUPERPW="${SUPERPW:-changeme}"

read -p "rep_user password [changeme]: " REPPW
REPPW="${REPPW:-changeme}"

read -p "Shared buffers [1GB]: " SHARED_BUFFERS
SHARED_BUFFERS="${SHARED_BUFFERS:-1GB}"

read -p "Max connections [200]: " MAX_CONNS
MAX_CONNS="${MAX_CONNS:-200}"

declare -A UNIQUE_IPS
ORDERED_NAMES=()
ORDERED_IPS=()

IFS=',' read -ra NODE_ARRAY <<< "$NODES"
for node in "${NODE_ARRAY[@]}"; do
    node="$(echo "$node" | xargs)"
    [ -z "$node" ] && continue
    ip="$(getent ahosts "$node" 2>/dev/null | head -n1 | awk '{print $1}')"
    if [ -z "$ip" ]; then
        if [[ "$node" =~ ^[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
            ip="$node"
        else
            echo "ERROR: Cannot resolve '$node' and it's not an IP." >&2
            exit 1
        fi
    fi
    if [ -z "${UNIQUE_IPS[$ip]}" ]; then
        UNIQUE_IPS["$ip"]="$node"
        ORDERED_NAMES+=("$node")
        ORDERED_IPS+=("$ip")
    fi
done

LEADER="${ORDERED_NAMES[0]}"

# Build etcd3 hosts list
ETCD3_HOSTS=""
for ip in "${!UNIQUE_IPS[@]}"; do
    ETCD3_HOSTS+="    - ${ip}:2379\n"
done

# pg_hba: local + replication + general
PG_HBA_LINES="  - local all postgres peer\n"
for ip in "${!UNIQUE_IPS[@]}"; do
    PG_HBA_LINES+="  - host replication rep_user ${ip}/32 md5\n"
done
PG_HBA_LINES+="  - host all all 0.0.0.0/0 md5"

for i in "${!ORDERED_NAMES[@]}"; do
    name="${ORDERED_NAMES[$i]}"
    ip="${ORDERED_IPS[$i]}"
    echo "------------------------------------------------------------"
    echo "# On node $name (IP $ip), run the following block:"

    if [ "$name" == "$LEADER" ]; then
        CLEANUP_CMD=""
    else
        CLEANUP_CMD="rm -rf /var/lib/pgsql/18/data"
    fi

    cat <<EOF
mkdir -p /etc/patroni
cat > /etc/patroni/patroni.yml <<'PATRONIEOF'
scope: ${SCOPE}
name: ${name}

etcd3:
  hosts:
$(echo -e "$ETCD3_HOSTS")

postgresql:
  listen: ${ip}:5432
  connect_address: ${ip}:5432
  data_dir: /var/lib/pgsql/18/data
  bin_dir: /usr/pgsql-18/bin

  replication:
    listen: ${ip}:5433
    connect_address: ${ip}:5433
    username: rep_user
    password: ${REPPW}

  superuser:
    username: postgres
    password: ${SUPERPW}

  parameters:
    shared_buffers: ${SHARED_BUFFERS}
    max_connections: ${MAX_CONNS}

  pg_hba:
$(echo -e "$PG_HBA_LINES")

restapi:
  listen: ${ip}:8008
  connect_address: ${ip}:8008
PATRONIEOF

mkdir -p /etc/systemd/system/patroni.service.d
cat > /etc/systemd/system/patroni.service.d/override.conf <<'OVERRIDEEOF'
[Unit]
After=etcd.service
Wants=etcd.service
OVERRIDEEOF

systemctl daemon-reload
$( [ -n "$CLEANUP_CMD" ] && echo "$CLEANUP_CMD" )
systemctl enable patroni --now
EOF
    echo
done
Sample Output (click to expand)
=== Patroni cluster configuration generator ===
Note: The FIRST node you enter will be the initial leader.
Enter comma separated node names (e.g., lin1,lin2,lin3): lin6,lin7,lin8
Cluster scope [pgcluster]:
Superuser password [changeme]:
rep_user password [changeme]:
Shared buffers [1GB]:
Max connections [200]:
------------------------------------------------------------
# On node lin6 (IP 11.1.1.186), run the following block:
mkdir -p /etc/patroni
cat > /etc/patroni/patroni.yml <<'PATRONIEOF'
scope: pgcluster
name: lin6

etcd3:
  hosts:
    - 11.1.1.186:2379
    - 11.1.1.196:2379
    - 11.1.1.195:2379

postgresql:
  listen: 11.1.1.186:5432
  connect_address: 11.1.1.186:5432
  data_dir: /var/lib/pgsql/18/data
  bin_dir: /usr/pgsql-18/bin

  replication:
    listen: 11.1.1.186:5433
    connect_address: 11.1.1.186:5433
    username: rep_user
    password: changeme

  superuser:
    username: postgres
    password: changeme

  parameters:
    shared_buffers: 1GB
    max_connections: 200

  pg_hba:
  - local all postgres peer
  - host replication rep_user 11.1.1.186/32 md5
  - host replication rep_user 11.1.1.196/32 md5
  - host replication rep_user 11.1.1.195/32 md5
  - host all all 0.0.0.0/0 md5

restapi:
  listen: 11.1.1.186:8008
  connect_address: 11.1.1.186:8008
PATRONIEOF

mkdir -p /etc/systemd/system/patroni.service.d
cat > /etc/systemd/system/patroni.service.d/override.conf <<'OVERRIDEEOF'
[Unit]
After=etcd.service
Wants=etcd.service
OVERRIDEEOF

systemctl daemon-reload

systemctl enable patroni --now

------------------------------------------------------------
# On node lin7 (IP 11.1.1.195), run the following block:
mkdir -p /etc/patroni
cat > /etc/patroni/patroni.yml <<'PATRONIEOF'
scope: pgcluster
name: lin7

etcd3:
  hosts:
    - 11.1.1.186:2379
    - 11.1.1.196:2379
    - 11.1.1.195:2379

postgresql:
  listen: 11.1.1.195:5432
  connect_address: 11.1.1.195:5432
  data_dir: /var/lib/pgsql/18/data
  bin_dir: /usr/pgsql-18/bin

  replication:
    listen: 11.1.1.195:5433
    connect_address: 11.1.1.195:5433
    username: rep_user
    password: changeme

  superuser:
    username: postgres
    password: changeme

  parameters:
    shared_buffers: 1GB
    max_connections: 200

  pg_hba:
  - local all postgres peer
  - host replication rep_user 11.1.1.186/32 md5
  - host replication rep_user 11.1.1.196/32 md5
  - host replication rep_user 11.1.1.195/32 md5
  - host all all 0.0.0.0/0 md5

restapi:
  listen: 11.1.1.195:8008
  connect_address: 11.1.1.195:8008
PATRONIEOF

mkdir -p /etc/systemd/system/patroni.service.d
cat > /etc/systemd/system/patroni.service.d/override.conf <<'OVERRIDEEOF'
[Unit]
After=etcd.service
Wants=etcd.service
OVERRIDEEOF

systemctl daemon-reload
rm -rf /var/lib/pgsql/18/data
systemctl enable patroni --now

------------------------------------------------------------
# On node lin8 (IP 11.1.1.196), run the following block:
mkdir -p /etc/patroni
cat > /etc/patroni/patroni.yml <<'PATRONIEOF'
scope: pgcluster
name: lin8

etcd3:
  hosts:
    - 11.1.1.186:2379
    - 11.1.1.196:2379
    - 11.1.1.195:2379

postgresql:
  listen: 11.1.1.196:5432
  connect_address: 11.1.1.196:5432
  data_dir: /var/lib/pgsql/18/data
  bin_dir: /usr/pgsql-18/bin

  replication:
    listen: 11.1.1.196:5433
    connect_address: 11.1.1.196:5433
    username: rep_user
    password: changeme

  superuser:
    username: postgres
    password: changeme

  parameters:
    shared_buffers: 1GB
    max_connections: 200

  pg_hba:
  - local all postgres peer
  - host replication rep_user 11.1.1.186/32 md5
  - host replication rep_user 11.1.1.196/32 md5
  - host replication rep_user 11.1.1.195/32 md5
  - host all all 0.0.0.0/0 md5

restapi:
  listen: 11.1.1.196:8008
  connect_address: 11.1.1.196:8008
PATRONIEOF

mkdir -p /etc/systemd/system/patroni.service.d
cat > /etc/systemd/system/patroni.service.d/override.conf <<'OVERRIDEEOF'
[Unit]
After=etcd.service
Wants=etcd.service
OVERRIDEEOF

systemctl daemon-reload
rm -rf /var/lib/pgsql/18/data
systemctl enable patroni --now

[root@lin6 ~]#

The status of the Patroni cluster can be verified with the following command:

# run as root
patronictl -c /etc/patroni/patroni.yml list

After the replicas have been build the status should look similar to:

[root@lin6 ~]# patronictl -c /etc/patroni/patroni.yml list
+ Cluster: pgcluster (7672094740335959559) -+----+-------------+-----+------------+-----+
| Member | Host       | Role    | State     | TL | Receive LSN | Lag | Replay LSN | Lag |
+--------+------------+---------+-----------+----+-------------+-----+------------+-----+
| lin6   | 11.1.1.186 | Leader  | running   |  3 |             |     |            |     |
| lin7   | 11.1.1.195 | Replica | streaming |  3 |   0/5000218 |   0 |  0/5000218 |   0 |
| lin8   | 11.1.1.196 | Replica | streaming |  3 |   0/5000218 |   0 |  0/5000218 |   0 |
+--------+------------+---------+-----------+----+-------------+-----+------------+-----+
[root@lin6 ~]#

Congrats! You have a running 3 node Patroni Cluster.

Performing a switchover

The following command can be used on any running cluster node to switchover the leader to another node and setup the current leader as a replica from the new leader node:

# run as root
# show the current status
patronictl -c /etc/patroni/patroni.yml list
# switchover
patronictl -c /etc/patroni/patroni.yml switchover
# show the new status
patronictl -c /etc/patroni/patroni.yml list
Sample Output (click to expand):
[root@lin7 ~]# patronictl -c /etc/patroni/patroni.yml list
+ Cluster: pgcluster (7672094740335959559) -+----+-------------+-----+------------+-----+
| Member | Host       | Role    | State     | TL | Receive LSN | Lag | Replay LSN | Lag |
+--------+------------+---------+-----------+----+-------------+-----+------------+-----+
| lin6   | 11.1.1.186 | Leader  | running   |  3 |             |     |            |     |
| lin7   | 11.1.1.195 | Replica | streaming |  3 |   0/5000218 |   0 |  0/5000218 |   0 |
| lin8   | 11.1.1.196 | Replica | streaming |  3 |   0/5000218 |   0 |  0/5000218 |   0 |
+--------+------------+---------+-----------+----+-------------+-----+------------+-----+
[root@lin7 ~]# patronictl -c /etc/patroni/patroni.yml switchover
Current cluster topology
+ Cluster: pgcluster (7672094740335959559) -+----+-------------+-----+------------+-----+
| Member | Host       | Role    | State     | TL | Receive LSN | Lag | Replay LSN | Lag |
+--------+------------+---------+-----------+----+-------------+-----+------------+-----+
| lin6   | 11.1.1.186 | Leader  | running   |  3 |             |     |            |     |
| lin7   | 11.1.1.195 | Replica | streaming |  3 |   0/5000218 |   0 |  0/5000218 |   0 |
| lin8   | 11.1.1.196 | Replica | streaming |  3 |   0/5000218 |   0 |  0/5000218 |   0 |
+--------+------------+---------+-----------+----+-------------+-----+------------+-----+
Primary [lin6]:
Candidate ['lin7', 'lin8'] []: lin8
When should the switchover take place (e.g. 2026-08-10T11:25 )  [now]:
Are you sure you want to switchover cluster pgcluster, demoting current leader lin6? [y/N]: y
2026-08-10 10:26:03.98239 Successfully switched over to "lin8"
+ Cluster: pgcluster (7672094740335959559) ----+-------------+-----+------------+-----+
| Member | Host       | Role    | State   | TL | Receive LSN | Lag | Replay LSN | Lag |
+--------+------------+---------+---------+----+-------------+-----+------------+-----+
| lin6   | 11.1.1.186 | Replica | stopped |    |     unknown |     |    unknown |     |
| lin7   | 11.1.1.195 | Replica | running |  3 |   0/5000360 |   0 |  0/5000360 |   0 |
| lin8   | 11.1.1.196 | Leader  | running |  3 |             |     |            |     |
+--------+------------+---------+---------+----+-------------+-----+------------+-----+
[root@lin7 ~]# patronictl -c /etc/patroni/patroni.yml list
+ Cluster: pgcluster (7672094740335959559) -+----+-------------+-----+------------+-----+
| Member | Host       | Role    | State     | TL | Receive LSN | Lag | Replay LSN | Lag |
+--------+------------+---------+-----------+----+-------------+-----+------------+-----+
| lin6   | 11.1.1.186 | Replica | streaming |  4 |   0/50004A0 |   0 |  0/50004A0 |   0 |
| lin7   | 11.1.1.195 | Replica | streaming |  4 |   0/50004A0 |   0 |  0/50004A0 |   0 |
| lin8   | 11.1.1.196 | Leader  | running   |  4 |             |     |            |     |
+--------+------------+---------+-----------+----+-------------+-----+------------+-----+
[root@lin7 ~]#

Troubleshooting Common Issues

IssueSolution
Patroni fails to startCheck logs: journalctl -u patroni -f. Ensure etcd is running and reachable.
etcd cluster unhealthyRestart etcd on both nodes: sudo systemctl restart etcd. Verify with etcdctl endpoint health --cluster.
PostgreSQL not startingCheck PostgreSQL logs.
Leader election stuckRestart Patroni on both nodes. Check etcd for conflicts.

Performance Tuning Tips

1. Adjust PostgreSQL Parameters (in patroni.yml):

The file is located here: /etc/patroni/patroni.yml

parameters:
  shared_buffers: 4GB
  effective_cache_size: 12GB
  work_mem: 64MB
  maintenance_work_mem: 2GB
  random_page_cost: 1.1

Ressources

The following links have further information about a Patroni PostgreSQL Cluster:

Conclusion

You have now successfully set up a highly available PostgreSQL 18 cluster on Red Hat 10 using Patroni and etcd. Here is a quick recap:

  • Three-node PostgreSQL 18 cluster with automatic failover.
  • Patroni manages leader election and replication.
  • etcd ensures cluster state consistency.

Next Steps:

  • Deploy a monitoring solution (Prometheus + Grafana).
  • Set up regular backups (WAL archiving, pg_dump).
  • Test failover scenarios in a staging environment.
  • Scale the cluster by adding more nodes.

Final Thoughts:

This setup is production-ready but can be further customized based on your workload. Patronis REST API and etcd integration make it a robust choice for managing PostgreSQL HA clusters.

Happy clustering!

1
Checkmk service monitoring

Checkmk Monitoring Guide: From Hosts to Databases and Custom Services


Learn how to set up comprehensive monitoring with Checkmk, starting with the monitoring of databases like PostgreSQL, Microsoft SQL Server, and IBM DB2, and other services. This step-by-step guide covers everything you need to build a robust monitoring infrastructure.


Why Use Checkmk for Comprehensive Monitoring?

Checkmk is a powerful, open-source monitoring solution that provides:
✅ End-to-end visibility across servers, applications, and databases
✅ Automatic service discovery to reduce manual configuration
✅ Performance metrics and historical data for trend analysis
✅ Flexible alerting with notifications via email, Slack, PagerDuty, and more
✅ Custom checks for monitoring any service or application
✅ Scalability from small environments to enterprise deployments

Whether you’re monitoring a single server or a complex infrastructure with hundreds of services, Checkmk provides the tools you need to stay on top of your systems.


Prerequisites

You should already have a running Checkmk server. The installation steps are described in this post (Step1).

Adding a Monitored Host to Checkmk

1.1 Install the Checkmk Agent on the Target Host

Linux (RHEL/CentOS/OL)

# run as root
# install the checkmk agent
wget lin3.fritz.box/mysite/check_mk/agents/check-mk-agent-2.5.0p10-1.noarch.rpm
dnf -y install ./check-mk-agent-2.5.0p10-1.noarch.rpm

Linux (Ubuntu/Debian)

# run as root
wget lin3.fritz.box/mysite/check_mk/agents/check-mk-agent_2.5.0p10-1_all.deb
apt -y install ./check-mk-agent_2.5.0p10-1_all.deb

Windows

Run the following in a command prompt to allow ICMP (ping) to the host:

netsh advfirewall firewall add rule name="ICMP Allow incoming V4 echo request" protocol=icmpv4:8,any dir=in action=allow

Then do the followoing:

  1. Download the agent from Setup > Agents > Windows in your Checkmk web interface
  2. Run the installer with administrator rights
  3. Configure the agent service to start automatically
  4. Verify the service is running in Services.msc

1.2 Add the host to Checkmk (GUI)

Navigate to the Checkmk GUI and add the new host:

  • Setup => Hosts => Add host (or click here)
  • Enter the Host name and click “Save & run service discovery”
  • Then Click “Accept all” to enable all discovered services
  • Click on Changes => Activate pending changes to perform the configuration changes

For the next step we need a agent registration password. Let’s create one in the GUI:

  • Go to Setup => Users => Edit the agent_registration user
  • Click on Create random secret and copy secret to clipboard and Save.
  • Activate the pending Changes: Changes => Activate pending Changes
  • The one time password is now saved to the clipboard (it is needed in the next step)

1.2 Configure TLS Encryption

Run this command on the monitored host to enable TLS:

On Linux:

# run as root
cmk-agent-ctl register --server lin3.fritz.box --site mysite --hostname lin6.fritz.box --user agent_registration --trust-cert
# enter the password from the previous step
Sample Output (click to expand):
[root@lin6 ~]# cmk-agent-ctl register --server lin3.fritz.box --site mysite --hostname lin6.fritz.box --user agent_registration --trust-cert

Password for Checkmk user 'agent_registration':
>
Registration complete.
[root@lin6 ~]#

On Windows

Run the following command in a command prompt and enter the registration password from the previous step:

C:\ProgramData\checkmk\agent\bin\cmk-agent-ctl.exe register --server lin3.fritz.box --site mysite --hostname win3.fritz.box --user agent_registration --trust-cert
Sample Output (click to expand):
C:\Windows\system32>C:\ProgramData\checkmk\agent\bin\cmk-agent-ctl.exe register --server lin3.fritz.box --site mysite --hostname win3.fritz.box --user agent_registration --trust-cert

Password for Checkmk user 'agent_registration':
>
Registration complete.

C:\Windows\system32>


Monitoring PostgreSQL Databases

The PostgreSQL database has been installed as documented in this post.

Install the PostgreSQL Plugin

On the Target Host (Linux)

# run as root
dnf -y install python3
wget -P /usr/lib/check_mk_agent/plugins lin3.fritz.box/mysite/check_mk/agents/plugins/mk_postgres.py
chmod +x /usr/lib/check_mk_agent/plugins/mk_postgres.py

Discover PostgreSQL Services in Checkmk

Perform the following steps to find the new PostgreSQL Checkmk services:

  • In the Host menu of the monitored host start: Run service discovery then Accept All
  • Activate the pending Changes: Changes => Activate pending Changes

After these steps the PostgreSQL Services are discovered, and after some time they all have been checked:


Monitoring Microsoft SQL Server

The SQL Server has been installed as documented in this post.

Install the SQL Server Plugin

On the monitored host download the Checkmk SQL Server plugin from the Checkmk server to %ProgramData%\checkmk\agent\plugins . Next create the config file with the following content:

# run in PowerShell
$p="$env:ProgramData\checkmk\agent\config"; mkdir $p -Force; @"
---
mssql:
  main:
    authentication:
      username: ''
      type: integrated
"@ | Out-File "$p\mk-sql.yml" -Encoding utf8


Discover SQL Server Services in Checkmk

Perform the following steps to find the new SQL Server Checkmk services:

  • In the Host menu of the monitored host start: Run service discovery then Accept All
  • Activate the pending Changes: Changes => Activate pending Changes

After these steps the SQL Server Services are discovered, and after some time they all have been checked:


Monitoring IBM DB2 databases

The IBM Db2 database server has been installed as documented in this post.

Install the DB2 Plugin

On the Target Host (Linux)

wget -P /usr/lib/check_mk_agent/plugins/ http://lin3.fritz.box/mysite/check_mk/agents/plugins/mk_db2.linux
chmod +x /usr/lib/check_mk_agent/plugins/mk_db2.linux

Discover Db2 Services in Checkmk

Perform the following steps to find the new Db2 Checkmk services:

  • In the Host menu of the monitored host start: Run service discovery then Accept All
  • Activate the pending Changes: Changes => Activate pending Changes

After these steps the Db2 Services are discovered, and after some time they all have been checked:


Monitoring Oracle Databases

We already covered monitoring of Oracle databases with Checkmk in the post: Monitoring Oracle 26ai Database with Checkmk on Ubuntu 26.04. This post also covers the installation of the Checkmk server.


Conclusion

Setting up comprehensive monitoring with Checkmk gives you end-to-end visibility across your entire infrastructure. By following these steps, you can:

✅ Monitor hosts with secure TLS connections
✅ Track database performance for PostgreSQL, SQL Server, and DB2
✅ Get alerts before issues impact your users
✅ Analyze trends with historical data and dashboards

0
tde

Oracle TDE (Transparent Data Encryption): The Complete Guide for Oracle AI Database 26ai

Oracle TDE Transparent Data Encryption Database Security

In today’s data-driven world, protecting sensitive information at rest is not just a best practice—it’s a compliance requirement. Oracle Transparent Data Encryption (TDE) provides a robust solution for encrypting database files, ensuring that even if storage media is stolen, your data remains secure and inaccessible to unauthorized users.

This comprehensive guide walks you through Oracle TDE concepts, implementation, and maintenance specifically for Oracle AI Database 26ai running on a VirtualBox VM, as described in this installation guide. We’ll cover everything from foundational concepts to hands-on configuration and ongoing maintenance.


Table of Contents


What is Oracle Transparent Data Encryption (TDE)?

Oracle Transparent Data Encryption (TDE) is a data-at-rest encryption feature that protects sensitive data stored in database files. Unlike application-level encryption, TDE operates at the database layer, making it transparent to applications—data is automatically encrypted when written to disk and decrypted when accessed by authorized users or applications.

TDE is included with Oracle Advanced Security, which is a licensed option for Oracle Database Enterprise Edition. It addresses the critical security gap where database authentication and authorization mechanisms protect data access but not the physical data files where the data is stored.

Key Benefits of Oracle TDE

  • Compliance Ready: Helps meet regulatory requirements like PCI-DSS, HIPAA, GDPR, and SOX
  • Transparent Operation: No application changes required—encryption/decryption happens automatically
  • Granular Control: Encrypt entire tablespaces, specific tables, or individual columns
  • Performance Optimized: Minimal performance overhead with hardware acceleration support
  • Comprehensive Protection: Secures data files, redo logs, backups, and temporary files
  • Key Management: Flexible key storage options including Oracle Wallet, Hardware Security Modules (HSM), and Oracle Key Vault

How Oracle TDE Works

Oracle TDE uses a hierarchical key management system to efficiently encrypt and decrypt data:

TDE Key Hierarchy

  • Master Encryption Key: The root key stored in an external keystore (Oracle Wallet or HSM). This key encrypts all other keys in the hierarchy.
  • Tablespace Encryption Keys: Unique keys for each encrypted tablespace, encrypted by the master key
  • Table/Column Keys: Keys for specific encrypted columns or tables, also encrypted by the master key
  • Data Encryption: Actual data is encrypted using standard algorithms (AES-128, AES-192, or AES-256)

Important for Oracle AI Database 26ai: Starting with 26ai, AES256 is the new default encryption algorithm for TDE, providing stronger security and aligning with quantum-resistant practices. This means that when you upgrade from previous versions, Oracle will automatically perform rekey operations to upgrade existing encrypted data to AES256.

When a user or application accesses encrypted data, Oracle TDE:

  1. Opens the wallet/keystore containing the master encryption key
  2. Uses the master key to decrypt the appropriate tablespace or column key
  3. Uses the decrypted key to decrypt the actual data
  4. Returns the cleartext data to the authorized user/application

Key TDE Components

1. TDE Wallet (Keystore)

The TDE Wallet is a PKCS#12 container that stores the master encryption key and other encryption keys. It’s essentially a password-protected file that resides on the database server’s filesystem.

Wallet Types:

  • Password-based Wallet (ewallet.p12): The primary wallet file that requires a password to open
  • Auto-login Wallet (cwallet.sso): Allows automatic wallet opening when the database starts (derived from the password wallet)
  • Hardware Security Module (HSM): External hardware device for enhanced security
  • Oracle Key Vault: Centralized key management solution for enterprise environments

⚠️ Critical Note for upgrading to 26ai: If TDE is enabled but WALLET_ROOT is not configured, you will be blocked from upgrading to 26ai. Always ensure proper wallet configuration before upgrading.

2. Master Encryption Key

The TDE Master Encryption Key is the foundation of the TDE key hierarchy. It’s generated when you first set up TDE and is used to encrypt all other encryption keys in your database.

Best Practice: Always create a backup of your master encryption key when you create it, as losing this key means losing access to all encrypted data.

3. Encryption Algorithms

Oracle TDE supports several encryption algorithms:

AlgorithmKey SizeDefault in 26aiNotes
AES128, 192, or 256 bits✅ AES256FIPS 140-2 compliant
3DES168 bits❌ NoLegacy, not recommended

Prerequisites for Our Environment

This guide assumes you have completed the Oracle AI Database 26ai installation on a VirtualBox VM as described in this installation guide. Here’s what you should have:

Environment Setup

  • Operating System: Oracle Linux 9.5
  • Virtualization: VirtualBox VM
  • Database: Oracle AI Database 26ai Enterprise Edition (23.26.0.0.0)
  • Storage: ASM with DATA (50GB x2) and FRA (25GB x3) diskgroups
  • Users: oracle (database owner), grid (ASM owner)
  • Database Home: /u01/app/oracle/product/23.26.0/dbhome_1
  • Grid Home: /u01/app/23.26.0/grid
  • Database Name: orcl (or your chosen SID)

Requirements for TDE

  • Oracle Advanced Security Option: TDE requires this licensed option (included in Enterprise Edition)
  • Database Compatibility: COMPATIBLE parameter must be set to at least 11.1.0.0
  • File System Permissions: Oracle user must have read/write access to the wallet directory
  • Backup Strategy: Ensure you have a backup strategy for both database and wallet files

Note: The installation guide already sets up the necessary infrastructure, including ASM diskgroups and proper user permissions, making it an ideal foundation for implementing TDE.


Step-by-Step TDE Implementation

Now let’s implement TDE on your Oracle AI Database 26ai installation. We’ll follow the official Oracle documentation (Oracle AI Database Transparent Data Encryption Guide) while adapting the steps for our VirtualBox VM environment.


Step 1: Set Initialization Parameters

The first step is to configure the database parameters that tell Oracle where to find the TDE wallet and how to manage encryption.

1.1 Create Wallet Directory

Connect to your VM as the oracle user and create the wallet directory. For our environment, we’ll use /u01/app/oracle/wallet:

# run as the oracle user
# create wallet directory
. ora26.env
mkdir -p /u01/app/oracle/wallet/${ORACLE_SID}
# set proper permissions (critical for security)
chmod -R 700 /u01/app/oracle/wallet
chown -R oracle:oinstall /u01/app/oracle/wallet

⚠️ Security Note: The wallet directory must have 700 permissions (read/write/execute for owner only). Never store wallet files in a location accessible to other users.

1.2 Configure Database Parameters

Set the TDE related parameters in your database. For Oracle AI Database 26ai, the WALLET_ROOT parameter is mandatory:

# Connect to your CDB as SYSDBA (handled by / as sysdba)
. ora26.env
sqlplus -S / as sysdba <<EOF


-- Set WALLET_ROOT to point to your wallet directory
-- This is REQUIRED for Oracle 26ai
ALTER SYSTEM SET WALLET_ROOT='/u01/app/oracle/wallet/${ORACLE_SID}' SCOPE = SPFILE;

-- Enable automatic tablespace encryption
-- This ensures new tablespaces are encrypted by default
ALTER SYSTEM SET TABLESPACE_ENCRYPTION='AUTO_ENABLE' SCOPE=SPFILE;

-- Optional: Set the default encryption algorithm
-- In 26ai, AES256 is the default, but you can explicitly set it
-- ALTER SYSTEM SET "TABLESPACE_ENCRYPTION_DEFAULT_ALGORITHM"='AES256' SCOPE=BOTH SID='*';

-- restart the database
shutdown immediate
startup

-- set the TDE_CONFIGURATION parameter
ALTER SYSTEM SET TDE_CONFIGURATION="KEYSTORE_CONFIGURATION=FILE" SCOPE=BOTH SID = '*';

-- Verify the parameters
show parameter wallet
show parameter encryption
show parameter tde

EXIT;
EOF
Sample Output (click to expand):
[oracle@lin1 ~]$ sqlplus -S / as sysdba <<EOF
>
>
> -- Set WALLET_ROOT to point to your wallet directory
> -- This is REQUIRED for Oracle 26ai
> ALTER SYSTEM SET WALLET_ROOT='/u01/app/oracle/wallet/${ORACLE_SID}' SCOPE = SPFILE;
>
> -- Enable automatic tablespace encryption
> -- This ensures new tablespaces are encrypted by default
> ALTER SYSTEM SET TABLESPACE_ENCRYPTION='AUTO_ENABLE' SCOPE=SPFILE;
>
> -- Optional: Set the default encryption algorithm
> -- In 26ai, AES256 is the default, but you can explicitly set it
> -- ALTER SYSTEM SET "TABLESPACE_ENCRYPTION_DEFAULT_ALGORITHM"='AES256' SCOPE=BOTH SID='*';
>
> -- restart the database
> shutdown immediate
> startup
>
> -- set the TDE_CONFIGURATION parameter
> ALTER SYSTEM SET TDE_CONFIGURATION="KEYSTORE_CONFIGURATION=FILE" SCOPE=BOTH SID = '*';
>
> -- Verify the parameters
> show parameter wallet
> show parameter encryption
> show parameter tde
>
> EXIT;
> EOF

System altered.


System altered.

Database closed.
Database dismounted.
ORACLE instance shut down.
ORACLE instance started.

Total System Global Area 4476610824 bytes
Fixed Size                  5015816 bytes
Variable Size             855638016 bytes
Database Buffers         3607101440 bytes
Redo Buffers                8855552 bytes
Database mounted.
Database opened.

System altered.


NAME                                 TYPE        VALUE
------------------------------------ ----------- ------------------------------
ssl_wallet                           string
wallet_root                          string      /u01/app/oracle/wallet/orcl

NAME                                 TYPE        VALUE
------------------------------------ ----------- ------------------------------
tablespace_encryption                string      AUTO_ENABLE
tablespace_encryption_default_algori string      AES256
thm
tablespace_encryption_default_cipher string      XTS
_mode

NAME                                 TYPE        VALUE
------------------------------------ ----------- ------------------------------
one_step_plugin_for_pdb_with_tde     boolean     FALSE
tde_configuration                    string      KEYSTORE_CONFIGURATION=FILE
tde_key_cache                        boolean     FALSE
[oracle@lin1 ~]$

Important for upgrading to 26ai: The WALLET_ROOT parameter was introduced in Oracle 21c and is required for Oracle 26ai. If this parameter is not set and TDE is enabled, you cannot upgrade to 26ai.

Note for ASM: If you’re using ASM (as configured in the installation guide), the wallet can also be stored in ASM. However, for simplicity and to match common practices, we’re using the filesystem approach here.


Step 2: Create the TDE Wallet (Keystore)

Now we’ll create the actual wallet that will store our encryption keys.

2.1 Create the Wallet

Use the ADMINISTER KEY MANAGEMENT command to create the wallet:

# run as the oracle user on the CDB
sql -S / as sysdba <<EOF
-- Create the wallet with a strong password
-- Replace 'MySecureWalletPass123!' with your own strong password
ADMINISTER KEY MANAGEMENT CREATE KEYSTORE IDENTIFIED BY "MySecureWalletPass123!";

-- Verify the wallet was created
SELECT * FROM V\$ENCRYPTION_WALLET;

EXIT;
EOF
Sample Output (click to expand):
[oracle@lin1 ~]$ sql -S / as sysdba <<EOF
> -- Create the wallet with a strong password
> -- Replace 'MySecureWalletPass123!' with your own strong password
> ADMINISTER KEY MANAGEMENT CREATE KEYSTORE IDENTIFIED BY "MySecureWalletPass123!";
>
> -- Verify the wallet was created
> SELECT * FROM V\$ENCRYPTION_WALLET;
>
> EXIT;
> EOF


Key MANAGEMENT succeeded.


WRL_TYPE WRL_PARAMETER                    STATUS WALLET_TYPE WALLET_ORDER KEYSTORE_MODE FULLY_BACKED_UP CON_ID
________ ________________________________ ______ ___________ ____________ _____________ _______________ ______
FILE     /u01/app/oracle/wallet/orcl/tde/ CLOSED UNKNOWN     SINGLE       NONE          UNDEFINED            1
FILE                                      CLOSED UNKNOWN     SINGLE       UNITED        UNDEFINED            2
FILE                                      CLOSED UNKNOWN     SINGLE       UNITED        UNDEFINED            3

[oracle@lin1 ~]$

💡 Password Requirements:

  • Minimum 8 characters
  • At least 1 uppercase letter
  • At least 1 lowercase letter
  • At least 1 digit
  • At least 1 special character
  • Store this password securely – you’ll need it for wallet operations

2.2 Create Auto-Login Wallet (Optional but Recommended)

For production environments, create an auto-login wallet so the database can open the wallet automatically when it starts:

# run as the oracle user on the CDB
sql -S / as sysdba <<EOF
-- First, open the wallet with the password
ADMINISTER KEY MANAGEMENT SET KEYSTORE OPEN IDENTIFIED BY "MySecureWalletPass123!" CONTAINER=ALL;

-- Create auto-login wallet
ADMINISTER KEY MANAGEMENT CREATE AUTO_LOGIN KEYSTORE FROM KEYSTORE IDENTIFIED BY "MySecureWalletPass123!";

-- Verify both wallets exist
!ls -la /u01/app/oracle/wallet/orcl/tde

EXIT;
EOF
Sample Output (click to expand):
[oracle@lin1 ~]$ # run as the oracle user on the CDB
[oracle@lin1 ~]$ sql -S / as sysdba <<EOF
> -- First, open the wallet with the password
> ADMINISTER KEY MANAGEMENT SET KEYSTORE OPEN IDENTIFIED BY "MySecureWalletPass123!";
>
> -- Create auto-login wallet
> ADMINISTER KEY MANAGEMENT CREATE AUTO_LOGIN KEYSTORE FROM KEYSTORE IDENTIFIED BY "MySecureWalletPass123!";
>
> -- Verify both wallets exist
> !ls -la /u01/app/oracle/wallet/orcl/tde
>
> EXIT;
> EOF


Key MANAGEMENT succeeded.


Key MANAGEMENT succeeded.

total 16
drwxr-x--- 2 oracle asmadmin 4096 Aug  5 16:11 .
drwx------ 3 oracle oinstall 4096 Aug  5 16:10 ..
-rw------- 1 oracle asmadmin 2608 Aug  5 16:11 cwallet.sso
-rw------- 1 oracle asmadmin 2563 Aug  5 16:10 ewallet.p12

[oracle@lin1 ~]$

ewallet.p12 is the Password-based wallet
cwallet.sso is the Auto-login wallet

⚠️ Important Security Considerations:

  • Do NOT delete the password-based wallet (ewallet.p12) – you need it to regenerate or rekey the TDE master encryption key in the future
  • The auto-login wallet (cwallet.sso) is derived from the password wallet and allows automatic opening
  • Both files must be backed up together
  • Store wallet backups in a secure, separate location from the database backups

Step 3: Set the TDE Master Encryption Key

Now we’ll create the master encryption key that will protect all other encryption keys in your database.

3.1 Create the Master Key

Execute the following command to create the master encryption key in the wallet:

# run as the oracle user on the CDB
sql -S / as sysdba <<EOF
-- Ensure the wallet is open
ADMINISTER KEY MANAGEMENT SET KEYSTORE OPEN IDENTIFIED BY "MySecureWalletPass123!" CONTAINER=ALL;

-- Create the master encryption key with backup
-- The WITH BACKUP clause creates a backup of the key
ADMINISTER KEY MANAGEMENT SET KEY IDENTIFIED BY "MySecureWalletPass123!"  
WITH BACKUP USING 'tde_master_key_backup' CONTAINER=ALL;

-- Verify the master key was created
SELECT * FROM V\$ENCRYPTION_WALLET;

EXIT;
EOF
Sample Output (click to expand):
[oracle@lin1 ~]$ # run as the oracle user on the CDB
[oracle@lin1 ~]$ sql -S / as sysdba <<EOF
> -- Ensure the wallet is open
> ADMINISTER KEY MANAGEMENT SET KEYSTORE OPEN IDENTIFIED BY "MySecureWalletPass123!" CONTAINER=ALL;
>
> -- Create the master encryption key with backup
> -- The WITH BACKUP clause creates a backup of the key
> ADMINISTER KEY MANAGEMENT SET KEY IDENTIFIED BY "MySecureWalletPass123!"
> WITH BACKUP USING 'tde_master_key_backup' CONTAINER=ALL;
>
> -- Verify the master key was created
> SELECT * FROM V\$ENCRYPTION_WALLET;
>
> EXIT;
> EOF


Error starting at line : 2 in command -
ADMINISTER KEY MANAGEMENT SET KEYSTORE OPEN IDENTIFIED BY "MySecureWalletPass123!" CONTAINER=ALL
Error report -
ORA-28354: Encryption wallet, auto login wallet, or HSM is already open.
Help: https://docs.oracle.com/error-help/db/ora-28354/

28354. 0000 -  "Encryption wallet, auto login wallet, or HSM is already open."
*Cause:    Either the encryption wallet, auto login wallet, or hardware security module (HSM) keystore was already open.
*Action:   None.

Key MANAGEMENT succeeded.


WRL_TYPE WRL_PARAMETER                    STATUS WALLET_TYPE WALLET_ORDER KEYSTORE_MODE FULLY_BACKED_UP CON_ID
________ ________________________________ ______ ___________ ____________ _____________ _______________ ______
FILE     /u01/app/oracle/wallet/orcl/tde/ OPEN   PASSWORD    SINGLE       NONE          NO                   1
FILE                                      OPEN   PASSWORD    SINGLE       UNITED        NO                   2
FILE                                      OPEN   PASSWORD    SINGLE       UNITED        NO                   3

[oracle@lin1 ~]$

💡 What just happened:
The WITH BACKUP USING clause creates a backup of the master key with the specified label. This backup is stored in the wallet and can be used for recovery if needed.

3.2 Verify Master Key Creation

Check that the master key exists and is properly stored:

# run as the oracle user on the CDB
sql -S / as sysdba <<EOF
SELECT
    b.name AS container_name,
    a.wrl_type,
    a.wrl_parameter,
    a.status,
    a.wallet_type
FROM v\$encryption_wallet a, v\$containers b
WHERE a.con_id = b.con_id
ORDER BY a.con_id;
EXIT;
EOF
Output (click to expand):
[oracle@lin1 ~]$ # run as the oracle user on the CDB
[oracle@lin1 ~]$ sql -S / as sysdba <<EOF
> SELECT
>     b.name AS container_name,
>     a.wrl_type,
>     a.wrl_parameter,
>     a.status,
>     a.wallet_type
> FROM v\$encryption_wallet a, v\$containers b
> WHERE a.con_id = b.con_id
> ORDER BY a.con_id;
> EXIT;
> EOF


CONTAINER_NAME WRL_TYPE WRL_PARAMETER                    STATUS WALLET_TYPE
______________ ________ ________________________________ ______ ___________
CDB$ROOT       FILE     /u01/app/oracle/wallet/orcl/tde/ OPEN   PASSWORD
PDB$SEED       FILE                                      OPEN   PASSWORD
PDB1           FILE                                      OPEN   PASSWORD

[oracle@lin1 ~]$


Step 4: Restart the Database

For the WALLET_ROOT and TABLESPACE_ENCRYPTION parameters to take full effect, restart your database:

# run as the oracle user on the CDB
sql -S / as sysdba <<EOF
-- Shutdown the database
SHUTDOWN IMMEDIATE;

-- Startup the database
STARTUP;

-- Verify parameters are set
SELECT name, value FROM v\$parameter 
WHERE name IN ('wallet_root', 'tablespace_encryption');
EXIT;
EOF
Output (click)
Database closed.
Database dismounted.
ORACLE instance shut down.
ORACLE instance started.

Total System Global Area   4476610824 bytes
Fixed Size                    5015816 bytes
Variable Size               855638016 bytes
Database Buffers           3607101440 bytes
Redo Buffers                  8855552 bytes
Database mounted.
Database opened.

NAME                  VALUE
_____________________ ___________________________
tablespace_encryption AUTO_ENABLE
wallet_root           /u01/app/oracle/wallet/orcl

Important: After restart, the auto-login wallet should open automatically. Verify this with:

SELECT status FROM V$ENCRYPTION_WALLET WHERE wrl_type = 'FILE';

Expected output: OPEN

Output (click):
SQL> SELECT status FROM V$ENCRYPTION_WALLET WHERE wrl_type = 'FILE';

STATUS
------------------------------
OPEN
OPEN
OPEN

SQL>


Step 5: Encrypt Tablespaces

Now that TDE is configured, let’s encrypt some tablespaces. With TABLESPACE_ENCRYPTION=AUTO_ENABLE, new tablespaces will be encrypted automatically, but we need to handle existing ones.

5.1 Create a New Encrypted Tablespace

Create a new tablespace that will be encrypted by default:

# run as the oracle user on PDB1
sql -S / as sysdba <<EOF
-- Create an encrypted tablespace for sensitive data
alter session set container=pdb1;
CREATE TABLESPACE secure_data 
DATAFILE '+DATA' SIZE 40M 
AUTOEXTEND ON 
ENCRYPTION USING 'AES256' ENCRYPT;

-- Verify the tablespace is encrypted
SELECT t.name AS tablespace_name,
       e.ts#,
       e.encryptionalg,
       e.ciphermode,
       e.encryptedts
FROM   v\$encrypted_tablespaces e
JOIN   v\$tablespace t ON e.ts# = t.ts#;

EXIT;
EOF
Sample Output (click to expand):
Session altered.


TABLESPACE SECURE_DATA created.


TABLESPACE_NAME TS# ENCRYPTIONALG CIPHERMODE ENCRYPTEDTS
_______________ ___ _____________ __________ ___________
SECURE_DATA       7 AES256        XTS        YES

Note: Thanks to TABLESPACE_ENCRYPTION=AUTO_ENABLE, you could also create the tablespace without the ENCRYPTION clause, and it would still be encrypted:

-- This will also be encrypted due to AUTO_ENABLE
CREATE TABLESPACE auto_secure_data 
DATAFILE '+DATA' SIZE 20M AUTOEXTEND ON;

5.2 Encrypt Existing Tablespaces (Online Method)

For existing tablespaces, Oracle 26ai introduces online tablespace encryption, which allows you to encrypt tablespaces without taking them offline. This is a significant improvement over previous versions.

# run as the oracle user on PDB1
sql -S / as sysdba <<EOF
alter session set container=pdb1;
-- create unencrypted data in the USERS tablespace
create table t tablespace users as select a2.* from all_objects a1, all_objects a2 where rownum<=1e6 order by a1.object_id;
-- Start online encryption for an existing tablespace
-- This example encrypts the USERS tablespace
ALTER TABLESPACE users 
ENCRYPTION ONLINE USING 'AES256' ENCRYPT;

-- Check the encryption status
SELECT t.name AS tablespace_name,
       e.ts#,
       e.encryptionalg,
       e.ciphermode,
       e.encryptedts
FROM   v\$encrypted_tablespaces e
JOIN   v\$tablespace t ON e.ts# = t.ts#;

-- The status will show 'ENCRYPTING' initially
SELECT t.name AS tablespace_name,
       e.ts#,
       e.encryptionalg,
       e.ciphermode,
       e.encryptedts,
       e.status,
       e.blocks_encrypted, -- number of new blocks that have been encrypted
       e.blocks_decrypted  -- number of encrypted blocks that have been decrypted
FROM   v\$encrypted_tablespaces e
JOIN   v\$tablespace t ON e.ts# = t.ts#;

EXIT;
EOF
Sample Output (click to expand):
[oracle@lin1 ~]$ sql -S / as sysdba <<EOF
> alter session set container=pdb1;
> -- create unencrypted data in the USERS tablespace
> create table t tablespace users as select a2.* from all_objects a1, all_objects a2 where rownum<=1e6 order by a1.object_id;
> -- Start online encryption for an existing tablespace
> -- This example encrypts the USERS tablespace
> ALTER TABLESPACE users
> ENCRYPTION ONLINE USING 'AES256' ENCRYPT;
>
> -- Check the encryption status
> SELECT t.name AS tablespace_name,
>        e.ts#,
>        e.encryptionalg,
>        e.ciphermode,
>        e.encryptedts
> FROM   v\$encrypted_tablespaces e
> JOIN   v\$tablespace t ON e.ts# = t.ts#;
>
> -- The status will show 'ENCRYPTING' initially
> SELECT t.name AS tablespace_name,
>        e.ts#,
>        e.encryptionalg,
>        e.ciphermode,
>        e.encryptedts,
>        e.status,
>        e.blocks_encrypted, -- number of new blocks that have been encrypted
>        e.blocks_decrypted  -- number of encrypted blocks that have been decrypted
> FROM   v\$encrypted_tablespaces e
> JOIN   v\$tablespace t ON e.ts# = t.ts#;
>
> EXIT;
> EOF


Session altered.


Table T created.


TABLESPACE USERS altered.


TABLESPACE_NAME  TS# ENCRYPTIONALG CIPHERMODE ENCRYPTEDTS
________________ ___ _____________ __________ ___________
USERS              6 AES256        XTS        YES
SECURE_DATA        7 AES256        XTS        YES
AUTO_SECURE_DATA   8 AES256        XTS        YES


TABLESPACE_NAME  TS# ENCRYPTIONALG CIPHERMODE ENCRYPTEDTS STATUS BLOCKS_ENCRYPTED BLOCKS_DECRYPTED
________________ ___ _____________ __________ ___________ ______ ________________ ________________
USERS              6 AES256        XTS        YES         NORMAL                0                0
SECURE_DATA        7 AES256        XTS        YES         NORMAL               46                0
AUTO_SECURE_DATA   8 AES256        XTS        YES         NORMAL               46                0

[oracle@lin1 ~]$

Online Encryption Process:

  1. Oracle starts encrypting data in the background
  2. Existing data is encrypted as it’s accessed (lazy encryption)
  3. New data written to the tablespace is encrypted immediately
  4. The tablespace remains fully accessible during the process
  5. Use ALTER TABLESPACE ... ENCRYPTION FINISH; to complete the process if needed

Note for Oracle 26ai: Online tablespace encryption uses tweakable block ciphertext stealing (XTS) instead of the older Cipher Feedback (CFB) mode, providing stronger security.

5.3 Encrypt System Tablespaces (Recommended for Production)

For maximum security, consider encrypting the SYSTEM and SYSAUX tablespaces as well:

# run as the oracle user on PDB1
sql -S / as sysdba <<EOF
alter session set container=pdb1;
-- Encrypt SYSTEM tablespace (requires database in restricted mode)
ALTER SYSTEM ENABLE RESTRICTED SESSION;

-- Disconnect all non-SYS sessions (if needed)
-- ALTER SYSTEM DISCONNECT SESSION 'sid,serial#' POST_TRANSACTION;

-- Encrypt SYSTEM and SYSAUX
ALTER TABLESPACE SYSTEM ENCRYPTION ONLINE USING 'AES256' ENCRYPT;
ALTER TABLESPACE SYSAUX ENCRYPTION ONLINE USING 'AES256' ENCRYPT;

-- Exit restricted mode
ALTER SYSTEM DISABLE RESTRICTED SESSION;

EXIT;
EOF
Sample Output (click to expand):
[oracle@lin1 ~]$ # run as the oracle user on PDB1
[oracle@lin1 ~]$ sql -S / as sysdba <<EOF
> alter session set container=pdb1;
> -- Encrypt SYSTEM tablespace (requires database in restricted mode)
> ALTER SYSTEM ENABLE RESTRICTED SESSION;
>
> -- Disconnect all non-SYS sessions (if needed)
> -- ALTER SYSTEM DISCONNECT SESSION 'sid,serial#' POST_TRANSACTION;
>
> -- Encrypt SYSTEM and SYSAUX
> ALTER TABLESPACE SYSTEM ENCRYPTION ONLINE USING 'AES256' ENCRYPT;
> ALTER TABLESPACE SYSAUX ENCRYPTION ONLINE USING 'AES256' ENCRYPT;
>
> -- Exit restricted mode
> ALTER SYSTEM DISABLE RESTRICTED SESSION;
>
> EXIT;
> EOF


Session altered.


System altered.


TABLESPACE SYSTEM altered.


TABLESPACE SYSAUX altered.


System altered.

[oracle@lin1 ~]$

⚠️ Warning: Encrypting SYSTEM and SYSAUX tablespaces can impact database performance and should be done during a maintenance window. Test this in a non-production environment first.


Step 6: Encrypt Specific Columns

In addition to tablespace-level encryption, TDE supports column-level encryption for more granular control.

6.1 Create a Table with Encrypted Columns

Let’s create a table with specific encrypted columns for sensitive data:

# run as the oracle user on PDB1
sql -S / as sysdba <<EOF
alter session set container=pdb1;
alter session set current_schema=dbsnmp;
-- Create a table in your encrypted tablespace
CREATE TABLE customers (
    customer_id NUMBER PRIMARY KEY,
    first_name VARCHAR2(50),
    last_name VARCHAR2(50),
    email VARCHAR2(100),
    ssn VARCHAR2(11) ENCRYPT,  -- Social Security Number - encrypted
    credit_card VARCHAR2(16) ENCRYPT USING 'AES256',  -- Credit card - encrypted with AES256
    phone VARCHAR2(15)
) TABLESPACE secure_data;

-- Insert some test data
INSERT INTO customers VALUES (
    1, 'John', 'Doe', 'john.doe@example.com', 
    '123-45-6789', '4111111111111111', '555-123-4567'
);

-- Query the data - it will be automatically decrypted for authorized users
SELECT * FROM customers;

EXIT;
EOF
Output (click to expand):
[oracle@lin1 ~]$ sql -S / as sysdba <<EOF
> alter session set container=pdb1;
> alter session set current_schema=dbsnmp;
> -- Create a table in your encrypted tablespace
> CREATE TABLE customers (
>     customer_id NUMBER PRIMARY KEY,
>     first_name VARCHAR2(50),
>     last_name VARCHAR2(50),
>     email VARCHAR2(100),
>     ssn VARCHAR2(11) ENCRYPT,  -- Social Security Number - encrypted
>     credit_card VARCHAR2(16) ENCRYPT USING 'AES256',  -- Credit card - encrypted with AES256
>     phone VARCHAR2(15)
> ) TABLESPACE secure_data;
>
> -- Insert some test data
> INSERT INTO customers VALUES (
>     1, 'John', 'Doe', 'john.doe@example.com',
>     '123-45-6789', '4111111111111111', '555-123-4567'
> );
>
> -- Query the data - it will be automatically decrypted for authorized users
> SELECT * FROM customers;
>
> EXIT;
> EOF


Session altered.


Session altered.


Table CUSTOMERS created.


1 row inserted.


CUSTOMER_ID FIRST_NAME LAST_NAME EMAIL                SSN         CREDIT_CARD      PHONE
___________ __________ _________ ____________________ ___________ ________________ ____________
          1 John       Doe       john.doe@example.com 123-45-6789 4111111111111111 555-123-4567

[oracle@lin1 ~]$

6.2 Encrypt Columns in Existing Tables

For existing tables, you can add encrypted columns or modify existing columns to be encrypted:

# run as the oracle user on PDB1
sql -S / as sysdba <<EOF
alter session set container=pdb1;
alter session set current_schema=dbsnmp;
-- Add an encrypted column to an existing table
ALTER TABLE customers ADD (
    bank_account VARCHAR2(20) ENCRYPT
);

-- For existing columns, you need to:
-- 1. Add a new encrypted column
-- 2. Copy data from old column to new column
-- 3. Drop the old column
-- 4. Rename the new column to the old name

ALTER TABLE customers ADD (
    new_email VARCHAR2(100) ENCRYPT
);

UPDATE customers SET new_email = email;

ALTER TABLE customers DROP COLUMN email;

ALTER TABLE customers RENAME COLUMN new_email TO email;

EXIT;
EOF
Sample Output (click to expand):
[oracle@lin1 ~]$ # run as the oracle user on PDB1
[oracle@lin1 ~]$ sql -S / as sysdba <<EOF
> alter session set container=pdb1;
> alter session set current_schema=dbsnmp;
> -- Add an encrypted column to an existing table
> ALTER TABLE customers ADD (
>     bank_account VARCHAR2(20) ENCRYPT
> );
>
> -- For existing columns, you need to:
> -- 1. Add a new encrypted column
> -- 2. Copy data from old column to new column
> -- 3. Drop the old column
> -- 4. Rename the new column to the old name
>
> ALTER TABLE customers ADD (
>     new_email VARCHAR2(100) ENCRYPT
> );
>
> UPDATE customers SET new_email = email;
>
> ALTER TABLE customers DROP COLUMN email;
>
> ALTER TABLE customers RENAME COLUMN new_email TO email;
>
> EXIT;
> EOF


Session altered.


Session altered.


Table CUSTOMERS altered.


Table CUSTOMERS altered.


1 row updated.


Table CUSTOMERS altered.


Table CUSTOMERS altered.

[oracle@lin1 ~]$

⚠️ Important Limitations for Column Encryption:

  • You cannot encrypt columns with data types that have size restrictions (e.g., LONG, LONG RAW)
  • Encrypted columns cannot be used in certain operations like indexing (unless using virtual columns or using the column NO SALT option)
  • Column encryption has a small storage overhead (approximately 16-32 bytes per encrypted value)
  • Not all SQL functions work with encrypted columns

TDE Maintenance and Best Practices

Implementing TDE is just the beginning. Proper maintenance ensures your encrypted data remains secure and accessible. Here are the essential maintenance tasks for your Oracle AI Database 26ai TDE implementation.


1. Wallet Management

1.1 Wallet Backup and Recovery

The wallet file is the most critical component of TDE. Without the wallet and its password, you cannot access your encrypted data, even with full database backups. Losing the wallet means permanent data loss.

Backup the Wallet

Create regular backups of your wallet files:

# As oracle user
su - oracle

# Create a backup directory
mkdir -p /u01/app/oracle/wallet_backups/${ORACLE_SID}

# Copy wallet files to backup location
cp /u01/app/oracle/wallet/${ORACLE_SID}/tde/*.p12 /u01/app/oracle/wallet_backups/${ORACLE_SID}
cp /u01/app/oracle/wallet/${ORACLE_SID}/tde/*.sso /u01/app/oracle/wallet_backups/${ORACLE_SID}

# Set proper permissions on backup
chmod -R 700 /u01/app/oracle/wallet_backups
chown -R oracle:oinstall /u01/app/oracle/wallet_backups

# Create a tarball for off-site backup
cd /u01/app/oracle/wallet_backups
tar czvf wallet_backup_${ORACLE_SID}_$(date +%Y%m%d).tar.gz ${ORACLE_SID}

# Securely transfer to backup server
scp wallet_backup_${ORACLE_SID}_$(date +%Y%m%d).tar.gz backup_server:/backups/oracle/

Wallet Backup Best Practices:

  • Backup Frequency: Backup the wallet every time you make changes (new keys, rekey operations)
  • Separate Storage: Store wallet backups in a different location than database backups
  • Secure Transfer: Use encrypted channels (SCP, SFTP) for transferring wallet backups
  • Access Control: Restrict access to wallet backups to authorized personnel only
  • Documentation: Document the wallet password storage procedure (use a secure password manager)
  • Test Restores: Regularly test wallet restore procedures
Recover from Wallet Loss

If you lose your wallet, you can restore from backup:

-- First, ensure the wallet directory exists
!mkdir -p /u01/app/oracle/wallet/${ORACLE_SID}/tde

-- Copy backup files to wallet directory
!cp /u01/app/oracle/wallet_backups/${ORACLE_SID}/ewallet.p12 /u01/app/oracle/wallet/${ORACLE_SID}/tde/
!cp /u01/app/oracle/wallet_backups/${ORACLE_SID}/cwallet.sso /u01/app/oracle/wallet/${ORACLE_SID}/tde/

-- Set proper permissions
!chmod 700 /u01/app/oracle/wallet/${ORACLE_SID}/tde/
!chown oracle:oinstall /u01/app/oracle/wallet/${ORACLE_SID}/tde/*

-- Open the wallet (if not using auto-login)
ADMINISTER KEY MANAGEMENT SET KEYSTORE OPEN 
IDENTIFIED BY "MySecureWalletPass123!";

-- Verify wallet status
SELECT * FROM V$ENCRYPTION_WALLET;

⚠️ Critical: If you don’t have a wallet backup and forget the password, your encrypted data is permanently inaccessible. There is no backdoor or recovery mechanism.


2. Key Management

Regular key rotation is a security best practice. Oracle TDE makes this process relatively straightforward.

2.1 Rotate the TDE Master Key

To rotate the master encryption key:

# run as the oracle user on the CDB
sql -S / as sysdba <<EOF
-- Verify the current key
select creator_pdbname, algorithm, creation_time from v\$encryption_keys;

-- next two steps needed to avoid: ORA-28354: Encryption wallet, auto login wallet, or HSM is already open.
-- Close the  auto login keystore
ADMINISTER KEY MANAGEMENT SET KEYSTORE CLOSE CONTAINER = ALL;

-- Open the password-based keystore 
ADMINISTER KEY MANAGEMENT SET KEYSTORE OPEN IDENTIFIED BY "MySecureWalletPass123!" CONTAINER=ALL;

-- Create a new master key (this automatically re-encrypts all dependent keys)
ADMINISTER KEY MANAGEMENT SET KEY IDENTIFIED BY "MySecureWalletPass123!" 
WITH BACKUP USING 'tde_master_key_rotation_2026' CONTAINER=ALL;

-- Verify the new key
select creator_pdbname, algorithm, creation_time from v\$encryption_keys;

EXIT;
EOF
Sample Output (click to expand):
[oracle@lin1 ~]$ sql -S / as sysdba <<EOF
> -- Verify the current key
> select creator_pdbname, algorithm, creation_time from v\$encryption_keys;
>
> -- next two steps needed to avoid: ORA-28354: Encryption wallet, auto login wallet, or HSM is already open.
> -- Close the  auto login keystore
> ADMINISTER KEY MANAGEMENT SET KEYSTORE CLOSE CONTAINER = ALL;
>
> -- Open the password-based keystore
> ADMINISTER KEY MANAGEMENT SET KEYSTORE OPEN IDENTIFIED BY "MySecureWalletPass123!" CONTAINER=ALL;
>
> -- Create a new master key (this automatically re-encrypts all dependent keys)
> ADMINISTER KEY MANAGEMENT SET KEY IDENTIFIED BY "MySecureWalletPass123!"
> WITH BACKUP USING 'tde_master_key_rotation_2026' CONTAINER=ALL;
>
> -- Verify the new key
> select creator_pdbname, algorithm, creation_time from v\$encryption_keys;
>
> EXIT;
> EOF


CREATOR_PDBNAME ALGORITHM CREATION_TIME
_______________ _________ ___________________________________
CDB$ROOT        AES256    05-AUG-26 10.35.17.381149000 AM GMT
PDB1            AES256    05-AUG-26 10.35.17.415059000 AM GMT


Error starting at line : 6 in command -
ADMINISTER KEY MANAGEMENT SET KEYSTORE CLOSE CONTAINER = ALL
Error report -
ORA-28389: Cannot close auto login keystore.
Help: https://docs.oracle.com/error-help/db/ora-28389/

28389. 00000 -  "Cannot close auto login keystore."
*Cause:    Auto login keystore could not be closed because the keystore type
           that is currently open is of password type and not auto-login.
*Action:   Close the keystore with a password.

Error starting at line : 9 in command -
ADMINISTER KEY MANAGEMENT SET KEYSTORE OPEN IDENTIFIED BY "MySecureWalletPass123!" CONTAINER=ALL
Error report -
ORA-28354: Encryption wallet, auto login wallet, or HSM is already open.
Help: https://docs.oracle.com/error-help/db/ora-28354/

28354. 0000 -  "Encryption wallet, auto login wallet, or HSM is already open."
*Cause:    Either the encryption wallet, auto login wallet, or hardware security module (HSM) keystore was already open.
*Action:   None.

Key MANAGEMENT succeeded.


CREATOR_PDBNAME ALGORITHM CREATION_TIME
_______________ _________ ___________________________________
PDB1            AES256    05-AUG-26 11.44.00.331030000 AM GMT
CDB$ROOT        AES256    05-AUG-26 11.44.00.286483000 AM GMT
CDB$ROOT        AES256    05-AUG-26 10.35.17.381149000 AM GMT
PDB1            AES256    05-AUG-26 10.35.17.415059000 AM GMT

[oracle@lin1 ~]$

💡 What happens during key rotation:

  1. Oracle generates a new master encryption key
  2. All existing keys (tablespace keys, column keys) are re-encrypted with the new master key
  3. The old master key is retained until all data is re-encrypted
  4. Applications continue to work without interruption

2.2 Rekey Tablespace Encryption

To change the encryption key for a specific tablespace:

-- Rekey a tablespace (this creates a new tablespace encryption key)
ALTER TABLESPACE secure_data ENCRYPTION USING 'AES256' REKEY;

-- For online rekey (Oracle 26ai feature)
ALTER TABLESPACE secure_data ENCRYPTION ONLINE USING 'AES256' REKEY;

-- Monitor rekey progress
SELECT t.name AS tablespace_name,
        e.ts#,
        e.encryptionalg,
        e.ciphermode,
        e.encryptedts,
        e.status,
        e.blocks_encrypted,
        e.blocks_decrypted
 FROM   v$encrypted_tablespaces e
 JOIN   v$tablespace t ON e.ts# = t.ts#;

Note: In Oracle 26ai, you can perform online rekey operations while the tablespace remains accessible, and Data Guard standby recovery can continue uninterrupted.


3. Backup and Recovery Considerations

TDE has important implications for database backup and recovery strategies.

3.1 Backup Strategy

Golden Rule: A database backup without the corresponding wallet backup is useless for recovering encrypted data.

  • Coordinate Backups: Always backup the wallet at the same time as the database
  • Separate Media: Store wallet backups on separate media from database backups
  • Test Recovery: Regularly test recovery procedures including wallet restore

3.2 Recovery with TDE

When recovering a database with TDE:

  1. Restore the wallet from its separate backup
  2. Open the wallet with the correct password
  3. Restore the database from backup
  4. Recover the database as usual
-- Example recovery process
-- restore wallet from backup
SQL> STARTUP NOMOUNT;
SQL> ADMINISTER KEY MANAGEMENT SET KEYSTORE CLOSE CONTAINER = ALL; -- close the autologin wallet
SQL> ADMINISTER KEY MANAGEMENT SET KEYSTORE OPEN IDENTIFIED BY "MySecureWalletPass123!" CONTAINER=ALL; -- open the password wallet
SQL> alter database mount; -- now the wallet is open and the master key loaded
RMAN> RESTORE DATABASE;
RMAN> RECOVER DATABASE;
RMAN> alter database open;

-- After recovery, ensure wallet is accessible for pdb1
SQL> alter session set container=pdb1;
SQL> ADMINISTER KEY MANAGEMENT SET KEYSTORE OPEN IDENTIFIED BY "MySecureWalletPass123!";
SQL> select * from v$ENCRYPTION_WALLET;

-- Verify encrypted data is accessible
SELECT COUNT(*) FROM dbsnmp.customers;

4. Monitoring TDE

Regular monitoring ensures your TDE implementation is working correctly and helps identify potential issues.

4.1 Key Views for Monitoring

Use these dynamic performance views to monitor TDE:

-- Wallet status
SELECT * FROM V$ENCRYPTION_WALLET;

-- Encrypted tablespaces
SELECT c.name AS container_name,
       t.name AS tablespace_name,
       e.ts#,
       e.encryptionalg,
       e.ciphermode,
       e.encryptedts,
       e.status,
       e.blocks_encrypted,  -- Number of new blocks encrypted
       e.blocks_decrypted   -- Number of encrypted blocks decrypted
FROM   v$encrypted_tablespaces e
JOIN   v$tablespace t ON e.ts# = t.ts# AND e.con_id = t.con_id
JOIN   v$containers c ON e.con_id = c.con_id
ORDER BY c.name, t.name;

-- Encryption keys
select creator_pdbname, algorithm, creation_time from v$encryption_keys;


Common Issues and Troubleshooting

Even with proper implementation, you may encounter issues with TDE. Here are the most common problems and their solutions.


1. Wallet Not Opening

Symptom: ORA-28365: wallet is not open

This error occurs when you try to access encrypted data but the wallet is closed.

Solution:

-- Check wallet status
SELECT * FROM V$ENCRYPTION_WALLET;

-- Open the wallet
ADMINISTER KEY MANAGEMENT SET KEYSTORE OPEN IDENTIFIED BY "your_wallet_password" CONTAINER=ALL;

-- Verify if it's open
SELECT * FROM V$ENCRYPTION_WALLET;

Common Causes:

  • Database was restarted and auto-login wallet is not working
  • Wrong wallet password was provided
  • Wallet files are missing or corrupted
  • WALLET_ROOT parameter is not set correctly

2. ORA-28360: master key not yet set in wallet

Symptom: ORA-28360: master key not yet set in wallet

This error indicates that you’re trying to encrypt data but the master encryption key hasn’t been created yet.

Solution:

-- Ensure wallet is open
ADMINISTER KEY MANAGEMENT SET KEYSTORE OPEN IDENTIFIED BY "your_wallet_password" CONTAINER=ALL;

-- Create the master key
ADMINISTER KEY MANAGEMENT SET KEY IDENTIFIED BY "your_wallet_password" WITH BACKUP CONTAINER=ALL;

3. ORA-28354: cannot open wallet

Symptom: ORA-28354: cannot open wallet

This error typically indicates a problem with the wallet files or permissions.

Solution:

  1. Check file permissions:
  ls -la /u01/app/oracle/wallet/${ORACLE_SID}/tde/

The files should be owned by oracle:oinstall with 600 or 700 permissions.

  1. Verify wallet location:
  SELECT value FROM v$parameter WHERE name = 'wallet_root';
  1. Check if wallet files exist:
  ls -la /u01/app/oracle/wallet/${ORACLE_SID}/tde/ewallet.p12
  ls -la /u01/app/oracle/wallet/${ORACLE_SID}/tde/cwallet.sso
  1. Verify password: Ensure you’re using the correct wallet password.
  2. Check for corruption: If the wallet files are corrupted, restore from backup.

4. ORA-28337: the password supplied for the wallet is incorrect

Symptom: ORA-28337: the password supplied for the wallet is incorrect

Self-explanatory – the wallet password you provided doesn’t match.

Solution:

  1. Double-check the password you’re using
  2. If you’ve forgotten the password and don’t have a backup, the encrypted data is permanently inaccessible
  3. Restore the wallet from backup if available

💡 Prevention: Store wallet passwords in a secure password manager and ensure multiple authorized personnel have access.


5. ORA-19908: cannot open wallet for tablespace encryption

Symptom: ORA-19908: cannot open wallet for tablespace encryption

This error occurs when trying to create or encrypt a tablespace but the wallet isn’t accessible.

Solution:

-- Ensure wallet is open
ADMINISTER KEY MANAGEMENT SET KEYSTORE OPEN IDENTIFIED BY "your_wallet_password" CONTAINER=ALL;

-- Ensure master key exists
ADMINISTER KEY MANAGEMENT SET KEY IDENTIFIED BY "your_wallet_password" CONTAINER=ALL;

-- Retry the tablespace encryption
ALTER TABLESPACE your_tablespace ENCRYPTION ONLINE USING 'AES256' ENCRYPT;

6. Performance Issues with TDE

Symptom: Slow performance after enabling TDE

While TDE has minimal overhead, you might notice performance impact in some scenarios.

Solution:

  • Check for missing indexes: Encrypted columns normally cannot use regular indexes. Consider virtual columns or function-based indexes, or create the column with the NO SALT option.
    • This is related to: ORA-28338: Columns cannot be both indexed and encrypted with salt.
  • Monitor CPU usage: TDE operations are CPU-intensive. Ensure you have adequate CPU resources.
  • Use appropriate algorithm: AES256 has more overhead than AES128. Use the strongest algorithm you need.
  • Consider hardware acceleration: Some hardware supports AES acceleration.
  • Review encryption scope: Only encrypt what’s necessary. Tablespace encryption has less overhead than column encryption.

Conclusion

Oracle Transparent Data Encryption (TDE) is a powerful feature that provides robust protection for your data at rest. With Oracle AI Database 26ai, TDE has become even more powerful with features like online tablespace encryption, AES256 as the default algorithm, and improved Data Guard integration.

In this comprehensive guide, we’ve covered:

  • TDE Fundamentals: How TDE works, key hierarchy, and components
  • Implementation: Step-by-step guide to enable TDE on your Oracle AI Database 26ai
  • Maintenance: Wallet management, key rotation, backup strategies, and monitoring
  • Troubleshooting: Common issues and their solutions

By implementing TDE on your Oracle AI Database 26ai installation, you’re taking a crucial step toward securing your sensitive data and meeting compliance requirements.

Remember: The security of your encrypted data depends on the security of your wallet. Always follow best practices for wallet backup, password management, and access control.


Additional Resources

0