Ubuntu 22.04 安装 Barman 3.20.1 指南
在 Ubuntu 22.04 LTS 从零安装 Barman 3.20.1:PGDG apt 与 pip+Python3.12 两条路线完整实测(含 psycopg2 构建失败排障)、数据库服务器复制账号与 pg_hba 放行、cron/check/首次全量备份验证与 WAITING_FOR_WALS 处理、常见问题与卸载清理。
Ubuntu 22.04 安装 Barman 3.20.1 指南
目标:在 Ubuntu 22.04 LTS 服务器上从零安装 Barman 3.20.1 备份服务器,并与一台 PostgreSQL 17.11 数据库服务器完成对接,跑通首次全量备份与状态验证。已在两台 Ubuntu 22.04 服务器(barman01 备份服务器、pg01 数据库服务器)实测通过,含 PGDG apt 与 pip 两条安装路线的完整命令与回显。
一、环境信息
本篇部署拓扑为「一台备份服务器 + 一台数据库服务器」的最小可用环境,命令均按真实服务器视角给出,读者替换主机名与网段即可复用。
- 操作系统:Ubuntu 22.04.5 LTS(jammy),x86_64
- 数据库服务器:主机名
pg01,IP10.0.0.31(示意网段),安装 PostgreSQL 17.11(PGDG 源,包名postgresql-17,版本 17.11-1.pgdg22.04+2) - 备份服务器:主机名
barman01,IP10.0.0.32(示意网段),安装 Barman 3.20.1(PGDG 源,包名barman,版本 3.20.1-1.pgdg22.04+1) - Barman 版本实查:官网 https://www.pgbarman.org/ 首页版本横幅显示「Version 3.20.1(29 Sep 2026)」,为官方最新稳定版(查询日期 2026-10-20)
- 网络互通:两台服务器同内网可互访,
/etc/hosts已配置主机名映射(10.0.0.31 pg01、10.0.0.32 barman01),后续命令统一用主机名互访 - Barman 数据目录:
/var/lib/barman/;全局配置:/etc/barman.conf;服务器配置节目录:/etc/barman.d/ - 示例口令:数据库专用账号
barman/barman_streaming密码均为q1w2e3r4(演示环境专用,生产环境请改用强口令并优先使用.pgpass文件)
💡 说明:Barman 的角色模型是「备份服务器远程管理数据库服务器」。备份软件全部安装在 barman01 上;pg01 只需要 PostgreSQL 本体、复制账号与 pg_hba 放行,不安装任何 Barman 组件。
二、版本选型说明
安装前先明确「装哪个版本、依赖什么」,避免装到与操作系统不兼容的版本。
2.1 Barman 版本与兼容性
- 最新稳定版:3.20.1(2026-09-29 发布,含 CVE-2026-93853 修复,来源:官网版本横幅与 GitHub Releases,查询日期 2026-10-20)。
- Python 门槛:Barman 3.20.0 起上游要求 Python ≥ 3.12(来源:官方 RELNOTES 3.20.0「Barman now requires Python 3.12 or later」)。Ubuntu 22.04 系统自带 Python 3.10.12——这是 pip 路线的关键约束,PGDG 发行版包已处理好该依赖(见 2.2)。
- PostgreSQL 兼容:Barman 3.x 支持当前主流 PostgreSQL 大版本的物理备份与流归档;本篇实测对接 PostgreSQL 17.11,
barman check全项 OK。
2.2 Ubuntu 22.04 可获得的版本对照
| 安装方案 | 来源 | 实测可获得版本 | Python 要求 | 适用 |
|---|---|---|---|---|
| 方案 A:PGDG apt 源 | apt.postgresql.org(jammy-pgdg) | 3.20.1-1.pgdg22.04+1(与官方最新一致) | 包依赖已内置(python3-barman) | 推荐,绝大多数场景 |
| 方案 B:pip(系统 Python 3.10) | PyPI | 最多解析到 3.19.1 且 sdist 构建 wheel 失败,不可用 | 3.10 不满足 3.20+ | 不推荐 |
| 方案 B':pip(deadsnakes Python 3.12) | PyPI | 3.20.1 | 3.12.15 实测通过 | 需要隔离环境/多实例并存时 |
关键差异解读:PGDG 源为 jammy 打包了 barman 3.20.1 并自带 python3-barman 依赖,一条
apt install即得到官方最新稳定版,还附带 systemd 单元与 cron 文件(第四章实测);pip 路线在 22.04 上必须先用 deadsnakes PPA 装 Python 3.12,且要补齐 psycopg2 编译依赖,步骤多但环境隔离干净(第五章实测)。
三、前置条件
3.1 数据库服务器侧(pg01):安装 PostgreSQL 17
Barman 做物理备份,pg01 只需要装好 PostgreSQL 本体。以下命令在 pg01 上执行(root):
# 安装证书与 GPG 工具
apt-get update
apt-get install -y curl ca-certificates gnupg
# 导入 PGDG 签名密钥并配置软件源
install -d /usr/share/postgresql-common/pgdg
curl -o /usr/share/postgresql-common/pgdg/apt.postgresql.org.asc \
https://www.postgresql.org/media/keys/ACCC4CF8.asc
echo "deb [signed-by=/usr/share/postgresql-common/pgdg/apt.postgresql.org.asc] http://apt.postgresql.org/pub/repos/apt jammy-pgdg main" \
> /etc/apt/sources.list.d/pgdg.list
# 刷新源并安装 PostgreSQL 17
apt-get update
apt-get install -y postgresql-17
安装完成后确认集群已就绪(实测回显):
pg_lsclusters
Ver Cluster Port Status Owner Data directory Log file
17 main 5432 online postgres /var/lib/postgresql/17/main /var/log/postgresql/postgresql-17-main.log
💡 说明:apt 安装即自动 initdb 并启动集群(真实服务器由 systemd 托管,
systemctl status postgresql@17-main可查)。Ubuntu 布局把配置文件放在/etc/postgresql/17/main/、数据放在/var/lib/postgresql/17/main/——这一「配置在数据目录之外」的布局与 Barman 备份行为的交互见 7.3 的 WARNING 说明。
3.2 数据库服务器侧:创建 Barman 专用账号并放行访问
按官方 Pre-requisites 建议(来源:docs.pgbarman.org 3.20.1 user_guide/pre_requisites.html,查询日期 2026-10-20),在 pg01 上创建两个专用角色:
# 创建备份管理账号(超级用户,实验/内网可用)
su - postgres -c "createuser -s -P barman"
# 按提示输入密码两次:q1w2e3r4
# 创建流复制账号(REPLICATION 权限)
su - postgres -c "psql -c \"CREATE ROLE barman_streaming WITH LOGIN REPLICATION PASSWORD 'q1w2e3r4';\""
实测回显:
CREATE ROLE
最小权限替代方案(不想给超级用户时):createuser -P barman 后在 psql 里授予
GRANT EXECUTE ON FUNCTION pg_backup_start(text, boolean) TO barman;
GRANT EXECUTE ON FUNCTION pg_backup_stop(boolean) TO barman;
并给 barman 授予相关库表的读权限(GRANT pg_read_all_data TO barman;)。本篇为聚焦安装主线采用超级用户方案。
接着让 pg01 对外监听并放行 barman01 的访问。打开监听地址:
su - postgres -c "psql -c \"ALTER SYSTEM SET listen_addresses = '*';\""
ALTER SYSTEM
在 /etc/postgresql/17/main/pg_hba.conf 末尾追加两行(按示意网段,读者按实际内网网段替换):
# Barman 管理连接
host all barman 10.0.0.0/24 scram-sha-256
# Barman 流复制连接(WAL 接收)
host replication barman_streaming 10.0.0.0/24 scram-sha-256
重启生效并复核:
pg_ctlcluster 17 main restart
pg_lsclusters
Ver Cluster Port Status Owner Data directory Log file
17 main 5432 online postgres /var/lib/postgresql/17/main /var/log/postgresql/postgresql-17-main.log
⚠️ 注意:PostgreSQL 17 的
wal_level默认即为replica,已满足流备份要求;若生产环境显式改过,需保证wal_level至少为replica,且max_wal_senders(默认 10)与max_replication_slots(默认 10)未耗尽——Barman 的流备份与流归档各占用一个 WAL 发送进程和一个复制槽。
四、在线安装方案 A:PGDG apt 官方仓库(推荐)
本方案从 PGDG(apt.postgresql.org)安装 barman 发行版包,一步到位获得官方最新稳定版,并附带 systemd 托管与 cron 文件。
4.1 方案说明
- 适用:可联网(或配代理)的 Ubuntu 22.04 服务器;
- 来源:PGDG 的
jammy-pgdg仓库,与 PostgreSQL 官方构建同源,版本随上游 release 更新; - 产物:
barman主包 + 依赖python3-barman,附带/lib/systemd/system/barman.service、barman-receive-wal@.service、barman.timer与/etc/cron.d/barman。
4.2 配置 PGDG 软件源
在 barman01 上执行(root):
apt-get update
apt-get install -y curl ca-certificates gnupg
install -d /usr/share/postgresql-common/pgdg
curl -o /usr/share/postgresql-common/pgdg/apt.postgresql.org.asc \
https://www.postgresql.org/media/keys/ACCC4CF8.asc
echo "deb [signed-by=/usr/share/postgresql-common/pgdg/apt.postgresql.org.asc] http://apt.postgresql.org/pub/repos/apt jammy-pgdg main" \
> /etc/apt/sources.list.d/pgdg.list
apt-get update
刷新源后先确认可获得的 barman 版本:
apt-cache policy barman
实测回显:
barman:
Installed: (none)
Candidate: 3.20.1-1.pgdg22.04+1
Version table:
3.20.1-1.pgdg22.04+1 500
500 http://apt.postgresql.org/pub/repos/apt jammy-pgdg/main amd64 Packages
3.20.0-2.pgdg22.04+1 500
500 http://apt.postgresql.org/pub/repos/apt jammy-pgdg/main amd64 Packages
3.20.0-1.pgdg22.04+1 500
500 http://apt.postgresql.org/pub/repos/apt jammy-pgdg/main amd64 Packages
💡 说明:Candidate 即 3.20.1,与官网最新稳定版一致,无需锁版本,直接安装即可。
4.3 安装 barman
apt-get install -y barman
安装会自动创建系统用户 barman 并落好目录(安装输出关键行节选):
Setting up python3-barman (3.20.1-1.pgdg22.04+1) ...
Setting up barman (3.20.1-1.pgdg22.04+1) ...
复核版本与运行身份:
barman --version
id barman
3.20.1 Barman by EnterpriseDB (www.enterprisedb.com)
uid=105(barman) gid=107(barman) groups=107(barman)
4.4 安装内容与托管方式说明
发行版包落盘的关键文件(dpkg -L barman 节选):
/etc/barman.conf
/etc/cron.d/barman
/lib/systemd/system/barman.service
/lib/systemd/system/barman-receive-wal@.service
/lib/systemd/system/barman.timer
/usr/bin/barman
3.20.1 包的托管设计(读取上述单元与 cron 文件内容整理,实测):
- systemd 主机:
barman.timer每分钟触发barman.service(Type=oneshot)执行barman -q cron;每个流归档服务器的 WAL 接收进程由模板单元barman-receive-wal@<server>.service独立托管(barman cron按需启停实例,单元注释明确说明该模板不随机启用); - 无 systemd 主机:
/etc/cron.d/barman以 barman 用户每分钟兜底执行barman -q cron,且其内建了test -d /run/systemd/system判断,避免与 timer 双跑; - 因此装完无需手工 enable 任何服务——首个服务器配置节就绪后,timer/cron 会自动接管维护任务。
包依赖关系(apt-cache show barman 节选,实测):
Depends: python3-barman (= 3.20.1-1.pgdg22.04+1), adduser, file, rsync, python3:any
Recommends: openssh-server, openssh-client, postgresql-client, python3-argcomplete, policykit-1
Suggests: barman-cli, repmgr
💡 说明:主包强依赖 rsync(rsync 备份方法与恢复都需要);
barman-cli/barman-cli-cloud是独立可选包,提供barman-wal-restore/barman-wal-archive辅助脚本与 S3/Azure/GCS 云备份工具族(barman-cloud-backup等),对象存储场景需另装。
4.5 验证安装
barman list-server
实测回显(此时还没有配置任何服务器,输出为空属于正常):
(空输出)
方案 A 安装到此完成,服务器配置节对接见第七章。
五、在线安装方案 B:pip + Python 3.12(deadsnakes PPA)
本方案用 pip 在独立 venv 中安装 Barman,适合需要与发行版包并存、或想精确控制版本的场景。核心前提是 Python ≥ 3.12——Ubuntu 22.04 自带 3.10,先用 deadsnakes PPA 补装。
5.1 安装 Python 3.12
apt-get install -y software-properties-common
add-apt-repository -y ppa:deadsnakes/ppa
apt-get update
apt-get install -y python3.12 python3.12-venv
python3.12 --version
实测回显:
Python 3.12.15
5.2 创建 venv 并安装 barman
python3.12 -m venv /opt/barman-venv312
/opt/barman-venv312/bin/pip install --upgrade pip
/opt/barman-venv312/bin/pip install barman
首次执行第三条命令时会遇到编译依赖缺失,报错尾部节选(实测):
ERROR: Failed to build 'psycopg2' when getting requirements to build wheel
note: This error originates from a subprocess, and is likely not a problem with pip.
⚠️ 排障:psycopg2 无预编译 wheel 可用,源码构建需要
libpq-dev与对应 Python 版本的头文件。补装后重试即可:
apt-get install -y libpq-dev python3.12-dev
/opt/barman-venv312/bin/pip install barman
/opt/barman-venv312/bin/barman --version
实测回显:
3.20.1 Barman by EnterpriseDB (www.enterprisedb.com)
5.3 关于系统 Python 3.10 的结论(实测)
若跳过 5.1 直接用系统 Python 3.10 建 venv:
python3 -m venv /opt/barman-venv310
/opt/barman-venv310/bin/pip install barman
pip 会把版本解析到 3.19.1(PyPI 上 3.20.x 因 requires-python >= 3.12 被 3.10 解释器过滤,pip index versions barman 输出首行即为 barman (3.19.1)),并且源码构建 wheel 失败(实测报错 Getting requirements to build wheel did not run successfully)。结论:22.04 上 pip 路线必须配合 Python 3.12,这也与官方 RELNOTES 3.20.0 的版本要求一致。
5.4 venv 路线的托管与使用差异
- venv 安装不产生 systemd/cron 文件,需要手工托管:可参照 4.4 的单元文件,把
ExecStart指向/opt/barman-venv312/bin/barman; - 以 barman 系统用户运行时,注意 venv 目录与
barman_home的属主都要是barman; - 运行时建议显式指定配置:
/opt/barman-venv312/bin/barman -c /etc/barman.conf <命令>,避免读取路径歧义。
六、方案对比与选择建议
| 维度 | 方案 A:PGDG apt | 方案 B:pip + Python 3.12 |
|---|---|---|
| 版本 | 3.20.1(与上游同步) | 3.20.1(随 PyPI 发布) |
| 安装命令数 | 1 条 apt install | PPA + venv + 依赖排障,约 5 步 |
| Python 依赖 | 包内置(python3-barman) | 需 3.12(deadsnakes)+ libpq-dev/python3.12-dev |
| systemd/cron 托管 | 自动附带三单元 + cron 文件 | 无,需手工配置 |
| 升级方式 | apt upgrade 跟随 PGDG | pip install -U barman |
| 多版本并存 | 困难(系统级单份) | 天然隔离(每 venv 一份) |
| 适用 | 生产服务器标准部署 | 需隔离环境/并存多版本/无 root 定制 |
选择建议:常规生产用方案 A——版本与官方同步、托管文件齐全、升级可预期;只有「同机多 Barman 实例」「需要 pip 生态集成」或「无 apt 管理权限的定制环境」才选方案 B。
七、配置说明:备份服务器对接数据库服务器
两条安装方案的后继配置完全一致。本章给出最小可用的对接配置并验证到首次备份成功。
7.1 全局配置(/etc/barman.conf)
apt 安装后 /etc/barman.conf 已带合理默认值(关键项节选,实测文件内容):
[barman]
; System user
barman_user = barman
; Directory of configuration files. Place your sections in separate files with .conf extension
; For example place the 'main' server section in /etc/barman.d/main.conf
configuration_files_directory = /etc/barman.d
; Main directory
barman_home = /var/lib/barman
; Log location
log_file = /var/log/barman/barman.log
; Log level
log_level = INFO
💡 说明:
configuration_files_directory指向/etc/barman.d/,官方推荐每台被管数据库一个独立.conf配置节(而非全塞进主配置),便于批量管理。参数逐项详解见本专栏《Barman 3.20.1 配置参数详解》(文末参考链接)。
7.2 服务器配置节(/etc/barman.d/pg01.conf)
在 barman01 上为 pg01 建配置节(root 创建,属主交回 barman):
cat > /etc/barman.d/pg01.conf << 'EOF'
[pg01]
description = "pg01 PostgreSQL 17 primary server"
conninfo = host=pg01 port=5432 user=barman dbname=postgres password=q1w2e3r4
streaming_conninfo = host=pg01 port=5432 user=barman_streaming dbname=postgres password=q1w2e3r4
backup_method = postgres
streaming_archiver = on
slot_name = barman
create_slot = auto
minimum_redundancy = 1
retention_policy = RECOVERY WINDOW OF 7 DAYS
EOF
chown barman:barman /etc/barman.d/pg01.conf
关键项说明:
conninfo:管理连接(备份协调、目录采集),用 3.2 节创建的barman账号;streaming_conninfo:流复制连接(pg_basebackup 传输与 pg_receivewal 接收 WAL),用barman_streaming账号;backup_method = postgres:走 pg_basebackup 流式备份,不需要 SSH 免密(这是 2.x 后推荐的现代方式;rsync方法才需要 SSH);streaming_archiver = on+slot_name = barman+create_slot = auto:流归档 WAL,槽不存在时自动创建,保证 WAL 不在备份间隙丢失;minimum_redundancy = 1:至少保留 1 份可用全量;retention_policy:保留可恢复到最近 7 天内任意时刻的备份链。
💡 技术拓展:
backup_method不止postgres一种。可选值对比——
方法 传输方式 是否需 SSH 特点 postgrespg_basebackup 流复制 否 部署最简,3.11+ 支持块级增量,现代默认 rsyncrsync over SSH 是 老版 PG 兼容、支持文件级增量与表空间精细限速 local-to-cloudbarman-cloud-* 直推对象存储 否 备份不落本地盘,S3/Azure/GCS 场景 本文采用
postgres:纯 TCP 依赖、无需 SSH 互信,与流归档共用一套复制账号,运维面最小。
7.3 初始化、体检与首次备份
以下均以 barman 用户在 barman01 上执行(su - barman)。
第一步,运行维护任务初始化复制槽并拉起 WAL 接收进程:
barman cron
Starting WAL archiving for server pg01
Starting streaming archiver for server pg01
第二步,配置体检。首跑会有几项 FAILED,这是正常的「尚未初始化完成」状态(实测首次输出):
barman check pg01
Server pg01:
WAL archive: FAILED (please make sure WAL shipping is setup)
PostgreSQL: OK
superuser or standard user with backup privileges: OK
PostgreSQL streaming: OK
wal_level: OK
replication slot: FAILED (replication slot 'barman' doesn't exist. Please execute 'barman receive-wal --create-slot pg01')
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: FAILED (have 0 non-incremental backups, expected at least 1)
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: FAILED (See the Barman log file for more details)
archiver errors: OK
三个 FAILED 的含义与解法:复制槽未创建(create_slot = auto 配合 barman cron 会自动建,或按提示手工 barman receive-wal --create-slot pg01);WAL 归档未开始(receive-wal 刚拉起,等第一批 WAL 到位);冗余度为 0(还没有任何备份,跑完首次备份即消除)。再跑一次 check 确认就绪(实测,节选):
Server pg01:
PostgreSQL: OK
superuser or standard user with backup privileges: OK
PostgreSQL streaming: OK
wal_level: OK
replication slot: OK
directories: OK
...
第三步,执行首次全量备份:
barman backup pg01
实测回显(节选,真实耗时随库大小与带宽变化):
Starting backup using postgres method for server pg01 in /var/lib/barman/pg01/base/20261019T163122
Backup start at LSN: 0/342C2E0 (000000010000000000000003, 0042C2E0)
Starting backup copy via pg_basebackup for 20261019T163122
WARNING: pg_basebackup does not copy the PostgreSQL configuration files that reside outside PGDATA. Please manually backup the following files:
/etc/postgresql/17/main/postgresql.conf
/etc/postgresql/17/main/pg_hba.conf
/etc/postgresql/17/main/pg_ident.conf
Copy done (time: 1 minute, 38 seconds)
Finalising the backup.
This is the first backup for server pg01
WAL segments preceding the current backup have been found:
000000010000000000000002 from server pg01 has been removed
Backup size: 29.5 MiB
Backup end at LSN: 0/5000000 (000000010000000000000004, 00000000)
Backup completed (start time: 2026-10-19 16:31:22.234473, elapsed time: 1 minute, 38 seconds)
Processing xlog segments from streaming for pg01 (batch size: 1)
000000010000000000000003
WARNING: IMPORTANT: this backup is classified as WAITING_FOR_WALS, meaning that Barman has not received yet all the required WAL files for the backup consistency.
This is a common behaviour in concurrent backup scenarios, and Barman automatically set the backup as DONE once all the required WAL files have been archived.
Hint: execute the backup command with '--wait'
两处实测要点:
- WARNING(配置文件未备份):Ubuntu 布局把
postgresql.conf等放在 PGDATA 之外,pg_basebackup 不会复制它们——需把/etc/postgresql/17/main/纳入配置管理(或另行备份),恢复时回放到目标机同位置; - WAITING_FOR_WALS:备份完成时必需的 WAL 尚未全部归档到位,Barman 会在 WAL 齐备后自动转 DONE;下次备份可直接带
--wait让命令内等待(实测带--wait的第二次备份回显尾部直接进入等待并完成,无该 WARNING):
Backup completed (start time: 2026-10-19 16:47:42.239971, elapsed time: less than one second)
Waiting for the WAL file 000000010000000000000007 from server 'pg01'
Processing xlog segments from streaming for pg01 (batch size: 1)
000000010000000000000006
第四步,查看备份清单确认 DONE:
barman list-backup pg01
pg01 20261019T163122 - F - Mon Oct 19 16:33:00 2026 - Size: 45.5 MiB - WAL Size: 16.0 MiB
💡 说明:
F表示全量(Full);WAL 等待状态消除后 Size 汇总为「基础备份 + 已归档 WAL」。备份的增删改查、PITR 恢复等日常操作详见本专栏《Barman 3.20.1 常用 CLI 命令与工具详解》(文末参考链接)。
八、常见问题(FAQ)
Q1:barman check 报 WAL archive: FAILED (please make sure WAL shipping is setup) 怎么处理?
先跑 barman cron(会拉起 receive-wal 与复制槽),等一分钟再 check;若仍 FAILED,查三处:pg01 的 pg_hba.conf 是否放行 barman_streaming 的 replication 连接、streaming_conninfo 账号是否确有 REPLICATION 权限、barman.log(/var/log/barman/barman.log)里的具体连接错误。
Q2:barman backup 报连接认证失败(password authentication failed)?
确认 conninfo 密码与 pg01 实际账号一致、pg_hba 认证方式与密码加密兼容(PG 17 默认 scram-sha-256,账号创建时的口令即为 scram 存储,配置写 scram-sha-256 认证行即可)。生产建议把口令放进 barman 用户家目录的 .pgpass(chmod 600),conninfo 里省略 password。
Q3:pip 安装报 Failed to build 'psycopg2'?
缺编译环境:apt-get install -y libpq-dev python3.12-dev 后重试(5.2 节实测)。若连版本都解析不到 3.20.x,说明解释器低于 3.12,回到 5.1 换 Python 3.12。
Q4:apt 装完 barman 命令找不到?
apt 包把入口装在 /usr/bin/barman,root 直接可用;以 barman 用户跑时用 su - barman(登录 shell 会加载正常 PATH)。若用了非标准 PATH 的受管账号,显式 /usr/bin/barman 即可。
Q5:首次备份提示 WAITING_FOR_WALS 一直是这个状态?
确认 receive-wal 在跑(barman list-processes pg01 应有 receive-wal 进程)、pg01 有事务活动或手工触发 WAL 切换(在 psql 执行 SELECT pg_switch_wal();),barman cron 周期任务会把 WAL 批量归档入位,状态自动转 DONE。
Q6:barman cron 提示 lock directory 相关错误?
Barman 的锁文件在 barman_home 下;若上次备份异常中断可能残留 .lock 文件,用 barman lock-directory-cleanup 清理后再操作(Barman 3.20 起该命令默认开启自动清理,一般无需干预)。
九、卸载与清理
apt 方案(barman01,root):
# 卸载主包(保留配置与备份数据,便于重装)
apt-get remove -y barman python3-barman
# 彻底清除包与配置文件
apt-get purge -y barman python3-barman
# 视需要删除备份数据目录(不可逆,操作前确认备份不再需要)
rm -rf /var/lib/barman /var/log/barman
pip 方案(barman01):
rm -rf /opt/barman-venv312
apt-get remove -y python3.12 python3.12-venv # 如不再需要 3.12
数据库侧清理(pg01,可选):删除专用账号与复制槽
su - postgres -c "psql -c \"SELECT pg_drop_replication_slot('barman');\""
su - postgres -c "drop role barman;"
su - postgres -c "drop role barman_streaming;"
十、参考链接
- 官网与版本:https://www.pgbarman.org/ (3.20.1,2026-09-29;查询日期 2026-10-20)
- 官方安装文档:https://docs.pgbarman.org/release/3.20.1/user_guide/installation.html
- 官方前置条件:https://docs.pgbarman.org/release/3.20.1/user_guide/pre_requisites.html (barman/barman_streaming 账号与权限)
- 官方发布说明:https://github.com/EnterpriseDB/barman/blob/release/3.20.1/RELNOTES.md (Python 3.12 要求等)
- PGDG 软件源说明:https://apt.postgresql.org/ (jammy-pgdg 源配置)
- 站内延伸阅读:《Barman 3.20.1 介绍与选型指南》(认知与选型)、《Ubuntu 22.04 安装 PostgreSQL 18 指南》(数据库侧同类安装流程参考)