Kubernetes
Migrate CloudNativePG to the Barman Cloud plugin
For the DBA whose CloudNativePG clusters still archive through barmanObjectStore, and who has to move them before the operator stops supporting it.
CloudNativePG 1.32 removes in-tree Barman Cloud. How to move WAL archiving to the plugin, and the silent breakages to check before you trust it.
Reference page, revised in place. Last updated .
Our advice: start on your next planned operator upgrade, to 1.30.2 or later, switch archiving to the Barman Cloud plugin in a separate window soon after, and judge the move by the archive rather than by the manifest. The YAML change is small. The failures either page nobody or page for the wrong reason: backup alerts that start lying, backups that fail on a default nobody changed, and restore runbooks that bring up clusters which never archive.
What is changing, and when
CloudNativePG deprecated its built-in Barman Cloud support, the .spec.backup.barmanObjectStore section, in 1.26. The 1.30 documentation says it is removed starting from 1.32.0, and that 1.31 is the last minor release to ship it. The removal has slipped four times, from 1.28 to 1.32. We would plan to the release the documentation now names rather than to a fifth slip.
The replacement is the Barman Cloud plugin. It runs as a sidecar container next to every PostgreSQL instance and works through CNPG-I, the operator’s plugin interface. Version 0.16.0 requires CloudNativePG 1.30 or newer, installs in the operator’s own namespace, and needs cert-manager for its stock install, or certificates of your own. Whatever plugin version you run, the operator upgrade comes first for a different reason, below. That makes the migration three changes: an operator upgrade, cert-manager if you do not run it already, and the archiving switch itself.
There are two reasons to do it early. The first is separation: the operator upgrade and cert-manager go in on their own schedule, and the archiving switch follows on a quiet day rather than in the same window. The second matters more. While both paths exist, a cluster on which the plugin misbehaves can be switched back to barmanObjectStore, which is another rolling update the documentation does not describe, so rehearse it on one cluster first. On 1.32 there is nothing to switch back to.
Use 1.30.2 or later, not just 1.30, because 1.30.2 fixes this exact change: pods created before a sidecar plugin was enabled had no sidecar until they were recreated, a switchover could wait forever, and when the plugin was the WAL archiver the former primary crash looped until its pod was deleted. The operator now recreates it. An earlier fix in the same series covered a switchover deadlock for the same reason.
The mapping below comes from the plugin’s migration guide and usage pages.
| In-tree today | Under the plugin |
|---|---|
Cluster.spec.backup.barmanObjectStore |
An ObjectStore resource; the same fields under .spec.configuration, with the same secret references |
barmanObjectStore.serverName, if you set one |
Cluster.spec.plugins[].parameters.serverName; the ObjectStore’s own serverName stays empty |
Cluster.spec.backup.retentionPolicy |
ObjectStore.spec.retentionPolicy |
| WAL archiving, implied by the backup section | Cluster.spec.plugins with isWALArchiver: true |
ScheduledBackup with the default method |
method: plugin and pluginConfiguration.name |
externalClusters[].barmanObjectStore |
A plugin block with barmanObjectName and serverName |
kubectl cnpg backup --method=barmanObjectStore |
--method=plugin --plugin-name=barman-cloud.cloudnative-pg.io |
cnpg_collector_last_available_backup_timestamp |
barman_cloud_cloudnative_pg_io_last_available_backup_timestamp |
cnpg_collector_last_failed_backup_timestamp |
barman_cloud_cloudnative_pg_io_last_failed_backup_timestamp |
cnpg_collector_first_recoverability_point |
barman_cloud_cloudnative_pg_io_first_recoverability_point |
Check the archive before you change how it is written
Do not migrate a cluster whose archiving is already behind. The change rolls every pod, and for this change the primary is restarted or recreated in place whichever primaryUpdateMethod you use: restart is the default, and the 1.30 releases recreate the primary in place even under switchover, because a clean demotion needs the archiver sidecar that is not there yet. While it shuts down, CloudNativePG gives it what remains of stopDelay, 1800 seconds in all by default, to finish archiving and streaming. A long backlog makes that window long and sits on the WAL volume the whole time.
The cumulative counters in pg_stat_archiver are the first thing to read, and backup verification and restore testing covers what they do and do not prove. On a CloudNativePG primary, also count the backlog itself. Every segment PostgreSQL has finished but not yet archived leaves a .ready file in pg_wal/archive_status.
SELECT count(*) FILTER (WHERE name LIKE '%.ready') AS files_waiting
FROM pg_ls_archive_statusdir();
The function is restricted to superusers and monitoring roles by default; kubectl cnpg psql connects as a superuser. The count includes timeline history and backup label files as well as segments. CloudNativePG sets archive_timeout to five minutes, which closes a segment at least that often while anything is being written. How long a closed segment then waits depends on how fast the archiver ships, so watch whether the count grows rather than holding files to a fixed age. A count that keeps climbing is WAL accumulating on the volume. PostgreSQL’s documentation says pg_wal keeps filling until archiving succeeds, and that a full file system means a PANIC shutdown. Each instance’s exporter publishes the same count as cnpg_collector_pg_wal_archive_status{value="ready"}, which is not among the metrics the migration renames.
If the WAL disk does fill, CloudNativePG deliberately avoids a failover, which its documentation says could complicate recovery, and the documented fix is to expand the volume and then raise the size in the Cluster resource to match.
The change itself
Install the plugin first, in the operator’s namespace, and check it is running before touching a cluster. Its deployment uses the Recreate strategy, so a later plugin upgrade leaves it briefly unavailable; plan those like operator upgrades.
Then create an ObjectStore in the cluster’s namespace. The configuration is the old barmanObjectStore content as it was, with retentionPolicy moved in from the Cluster:
apiVersion: barmancloud.cnpg.io/v1
kind: ObjectStore
metadata:
name: pg-eu-store
spec:
retentionPolicy: "30d"
configuration:
destinationPath: s3://backups/
s3Credentials:
accessKeyId:
name: backup-creds
key: ACCESS_KEY_ID
secretAccessKey:
name: backup-creds
key: ACCESS_SECRET_KEY
wal:
compression: gzip
# keep endpointURL, region and any other keys exactly as they were in-tree
Keep destinationPath as it was, as the migration guide’s own example does; the plugin’s documentation says backups taken the in-tree way are compatible with it.
The Cluster edit is one change, applied at once: remove barmanObjectStore and retentionPolicy from spec.backup, remove spec.backup entirely if that empties it, and add the plugin.
spec:
plugins:
- name: barman-cloud.cloudnative-pg.io
isWALArchiver: true
parameters:
barmanObjectName: pg-eu-store
# serverName: pg-eu # only if barmanObjectStore.serverName was set
If the in-tree section set serverName, carry it over. Dropping it moves WAL to the cluster’s own name: either a fresh prefix that your existing base backups cannot replay into, or one another cluster already writes to. If it was never set, the default was already the cluster name and nothing moves.
Applying the change starts a rolling update, which is how the sidecar gets into each pod. The sidecar’s own settings live in the ObjectStore under instanceSidecarConfiguration, and changing them later can roll the cluster again. Afterwards, change every ScheduledBackup to method: plugin with pluginConfiguration.name: barman-cloud.cloudnative-pg.io, and convert any externalClusters entry used for recovery or a replica cluster to the plugin form.
Three things the rollout will not tell you about
Backup alerts start lying. The plugin reports backups under the new metric names, but on 1.30 the old cnpg_collector_* backup gauges do not disappear. The exporter still registers them and fills them from the cluster’s status. The monitoring page says they keep working with the in-tree path and volume snapshots, and we read the 1.30 source to see what that leaves out: a successful plugin backup does not update the status fields behind cnpg_collector_last_available_backup_timestamp and cnpg_collector_first_recoverability_point. Those two stop at your last in-tree backup, so a backup-age rule on them pages you once its threshold passes, about backups that are fine, while an absence rule on the old names never fires because the series is still there. Rewrite the rules on the new names in the same change, add an absence alert on the new series, and delete the old rules.
A backup you did not convert fails on a default. The default backup method is still the in-tree one. A Backup or ScheduledBackup without method: plugin, or a kubectl cnpg backup run from someone’s shell history, fails with “cannot proceed with the backup as the cluster has no backup section” once spec.backup is gone, or with “no barmanObjectStore section defined on the target cluster” if the section survives for something else, such as volume snapshots. From 1.30.2 the admission webhook warns when such a resource is created or updated; objects already in the cluster stay silent, so list Backup and ScheduledBackup resources whose method is empty or the in-tree one, and search the repositories, runbooks and cron jobs too.
Converted restore runbooks bring up clusters that never archive. Bootstrapping from the plugin, for a restore or a clone, does not turn on WAL archiving for the new cluster. The plugin’s usage page shows a restore without spec.plugins and warns, in a callout after it, that this configuration does not enable WAL archiving; a runbook converted from that example inherits the gap. Add spec.plugins with isWALArchiver: true and point it at the new cluster’s own object store, which the plugin documentation strongly recommends.
Proving it worked
The test that matters is a segment you can name arriving in the bucket. On the current primary, which after the rollout may not be the pod you started with, make a small write and then force a segment switch:
SELECT pg_walfile_name(pg_switch_wal()) AS segment_just_closed;
The write matters, and what goes wrong without it depends on the version. We ran the query on idle PostgreSQL 14, 17 and 18 servers. With nothing written since the last switch, pg_switch_wal closes nothing and returns the boundary of the current file. On 14, pg_walfile_name names the previous segment, which was archived long ago, so the check passes and proves nothing. On 17 and 18 it names the segment still being written, which will not reach the bucket until it fills or a write lets archive_timeout close it, so the check waits for a file that is not coming.
A minute later, the archiver should report that segment and no failure since:
SELECT last_archived_wal,
last_archived_time,
last_failed_wal,
last_failed_time
FROM pg_stat_archiver;
These counters belong to the instance, so read them on the primary you have now. PostgreSQL’s documentation also warns that archive order is not guaranteed around a promotion, so last_archived_wal alone does not prove everything older made it; the backlog query above should come back to zero as well. Then find that segment in the bucket under the server name’s wals/ prefix, with a .gz suffix if WAL is compressed, and, if the timeline is above 1, its .history file. Take one on-demand backup with the plugin method and restore it to a scratch cluster. Until that restore has run, the migration has changed configuration and proved nothing about recovery.
This is where our advice is weakest. The plugin is at 0.x. It shares the pod’s CPU and memory with PostgreSQL, and its troubleshooting page notes that restarting the sidecar means restarting the whole pod. Moving early means living with those properties for longer, and anyone who moved on a release before 1.30.2 was exposed to the crash loop it fixed. For a team with no operator upgrade planned before 1.31, waiting is a defensible choice. What waiting does not change is the work: the same edits and the same three failures, found with less time to spare and no way back.