使用pg_basebackup命令的是直接报错了!!!
[postgres@pg01 tools]$ pg_basebackup -h 10.0.0.101 -U postgres -F p -P -X stream -R -D $PGDATA -l postgresbackup20260616 2026-06-16 10:17:31.017 CST [1577] FATAL: no pg_hba.conf entry for replication connection from host "10.0.0.101", user "postgres" pg_basebackup: error: could not connect to server: FATAL: no pg_hba.conf entry for replication connection from host "10.0.0.101", user "postgres"
pg_hba.conf里面我明明填写了,为什么还会出现这个问题呢?
host all all 0.0.0.0/0 trust
原因:pg_basebackup备份的过程中走的replication库,而replication又不是真实的库,只是一个虚拟库。所以在备份的过程中,需要主机能允许replication库的规则才能避开报错信息。
host replication all 0.0.0.0/0 trust
然后pg_ctl restart
[postgres@pg01 backup]$ pg_basebackup -h 10.0.0.101 -U postgres -F p -P -X stream -R -D $PGDATA/backup -l postgresbackup20260616
65502/65502 kB (100%), 1/1 tablespace
总结:pg_hba.conf 中确实至少需要两条规则:
host all all 0.0.0.0/0 trust
host replication all 0.0.0.0/0 trust
第一条:允许普通数据库连接(所有数据库、所有用户、任意IP,使用trust认证)
- 第二条:允许复制连接(特殊的
replication虚拟数据库、所有用户、任意IP,trust认证)
