Spring Boot连接PostgreSQL报错HikariPool初始化异常求助
以下是针对你遇到的org.postgresql.util.PSQLException: The connection attempt failed(根源为java.io.EOFException)的具体排查方案:
确认PostgreSQL服务是否监听5433端口
执行对应系统的命令检查端口状态:# Linux/macOS netstat -tulpn | grep 5433 # Windows netstat -ano | findstr :5433若无输出,说明PostgreSQL未在5433端口启动。需修改
postgresql.conf中的port参数为5433,之后重启PostgreSQL服务。检查数据库连接配置的准确性
确保application.properties或application.yml的配置无拼写错误:# 示例application.properties配置 spring.datasource.url=jdbc:postgresql://localhost:5433/your_db_name spring.datasource.username=your_username spring.datasource.password=your_password spring.datasource.driver-class-name=org.postgresql.Driver重点核对:端口号是否为5433、数据库名称是否存在、用户名密码是否正确,避免
localhost与127.0.0.1的解析差异导致的问题。验证PostgreSQL的连接权限配置
修改pg_hba.conf,添加允许本地连接5433端口的规则:host all all 127.0.0.1/32 scram-sha-256注意规则的加密方式需与
postgresql.conf中password_encryption的配置匹配,修改后重启PostgreSQL。排查防火墙或安全软件的拦截
本地防火墙、杀毒软件可能会拦截5433端口的连接请求,可临时关闭防火墙测试,或手动添加5433端口的入站/出站允许规则。核对PostgreSQL驱动与Spring Boot的兼容性
确保依赖中的驱动版本适配Spring Boot版本:<!-- Maven示例,适配Spring Boot 2.x/3.x --> <dependency> <groupId>org.postgresql</groupId> <artifactId>postgresql</artifactId> <scope>runtime</scope> </dependency>避免使用过低版本的驱动(如低于42.2.0)引发协议兼容问题。
内容的提问来源于stack exchange,提问作者iboukou blessing ogoudele

