Debian PostgreSQL网络配置需修改配置文件并调整防火墙,以下是关键步骤:
/etc/postgresql/<版本>/main/postgresql.conf,将 listen_addresses 设为 '*' 以允许所有IP连接(生产环境建议指定具体IP)。/etc/postgresql/<版本>/main/pg_hba.conf,添加规则如 host all all 0.0.0.0/0 md5(允许所有IP通过密码认证,不推荐生产环境使用)。sudo systemctl restart postgresql 使配置生效。sudo ufw allow 5432/tcp 开放默认端口。psql -h <服务器IP> -U <用户名> -d <数据库名> 测试远程连接。安全建议:
listen_addresses 为特定IP,避免使用 '*'。