You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

添加新节点后PostgreSQL Citus分片重平衡失败:远程连接无密码错误

问题概述

在将PostgreSQL表通过Citus分布式部署并添加新节点(192.168.1.101)后,执行分片重平衡时反复报错:

connection to the remote node localhost:5432 failed with the following error: fe_sendauth: no password supplied

已尝试相关问题的解决方案但无效,环境与操作信息如下:

环境信息

  • 操作系统:Ubuntu 20.04.4 LTS
  • Citus版本:11.0-2
  • PostgreSQL版本:14.4 (Ubuntu 14.4-1.pgdg20.04+1)
  • 协调器节点:192.168.1.100
  • 新增扩容节点:192.168.1.101

操作步骤

  1. 设置协调器节点:
SELECT citus_set_coordinator_host('192.168.1.100', 5432);
  1. 分布式部署目标表:
select create_distributed_table('public."Table"','distributedField');
  1. 添加新节点:
SELECT * from citus_add_node('192.168.1.101', 5432);
  1. 执行分片重平衡:
Select * from rebalance_table_shards('public."Table"');

当前pg_hba.conf配置

local   all             postgres                                peer

local   all             all                                     peer

host    all             all             127.0.0.1/32            scram-sha-256

host    all             all             ::1/128                 scram-sha-256

local   replication     all                                     peer
host    replication     all             127.0.0.1/32            scram-sha-256
host    replication     all             ::1/128                 scram-sha-256
host    all             all             192.0.0.0/8             trust

host    all             all             127.0.0.1/32            trust
host    all             all             ::1/128                 trust
host    all             all             192.168.1.101/32        trust

排查与解决方向

1. 调整本地连接的身份验证规则

Citus重平衡过程中,节点间可能通过localhost本地连接通信,当前local all all peer规则要求系统用户与PostgreSQL用户完全匹配,若重平衡进程的运行用户不满足此条件,会触发验证失败。

修改本地连接规则为trust(临时测试用,生产环境建议配置密码文件):

local   all             all                                     trust

修改后重新加载PostgreSQL配置:

sudo systemctl reload postgresql

2. 修正pg_hba.conf规则顺序

PostgreSQL按从上到下的顺序匹配验证规则,现有配置中127.0.0.1/32的scram-sha-256规则在trust规则之前,导致本地TCP连接优先使用密码验证。将trust规则移到前面:

host    all             all             127.0.0.1/32            trust
host    all             all             ::1/128                 trust
host    all             all             192.0.0.0/8             trust

host    all             all             127.0.0.1/32            scram-sha-256
host    all             all             ::1/128                 scram-sha-256

重新加载配置生效:

sudo systemctl reload postgresql

3. 检查Citus节点元数据正确性

确认Citus节点列表中没有错误的localhost节点,执行以下命令查看:

SELECT * FROM pg_dist_node;

若存在localhost节点,删除后重新添加正确的IP节点:

SELECT citus_remove_node('localhost', 5432);
SELECT citus_add_node('192.168.1.101', 5432);

4. 配置全局密码文件.pgpass

在协调器和新增节点的PostgreSQL用户主目录(通常为/var/lib/postgresql)下创建.pgpass文件,统一配置节点间连接凭证:

localhost:5432:*:postgres:your_password
192.168.1.100:5432:*:postgres:your_password
192.168.1.101:5432:*:postgres:your_password

设置文件权限(必须严格为600):

chmod 600 /var/lib/postgresql/.pgpass
chown postgres:postgres /var/lib/postgresql/.pgpass

5. 确认PostgreSQL监听地址

检查协调器节点的postgresql.conf,确保监听所有地址(包含localhost):

listen_addresses = '*'

修改后重启PostgreSQL:

sudo systemctl restart postgresql

内容的提问来源于stack exchange,提问作者Uncle Bent

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.24 22:15:41