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

首次使用SpringBoot遇HikariPool初始化异常,PostgreSQL数据库不存在

问题排查与解决方案

核心错误分析

错误日志明确提示:org.postgresql.util.PSQLException: 致命错误:数据库"db_name"不存在,说明SpringBoot尝试连接的PostgreSQL数据库db_name并未在你的数据库服务中创建。同时你的配置文件里还有两处需要修正的细节问题。

分步解决步骤

1. 创建缺失的目标数据库

登录PostgreSQL控制台(可通过psql命令),执行以下SQL语句创建数据库:

CREATE DATABASE db_name;

如果需要指定UTF-8编码(推荐生产环境使用):

CREATE DATABASE db_name WITH ENCODING 'UTF8';

2. 修正端口冲突问题

你的application.properties中设置了server.port=5432,这是PostgreSQL的默认端口,会导致SpringBoot启动时占用该端口,进而干扰PostgreSQL服务的正常访问。建议将SpringBoot的端口改为其他常用值,比如:

server.port=8080

3. 修正Hibernate方言拼写错误

配置里的spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.PostgresSQLDialect存在拼写错误,正确的PostgreSQL方言类名是PostgreSQLDialect,修正后:

spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.PostgreSQLDialect

4. 验证PostgreSQL服务可用性

确保你的PostgreSQL服务已经启动,可通过以下命令测试连接:

psql -h localhost -p 5432 -U postgres

输入密码后能进入控制台,说明数据库服务运行正常。

修正后的完整application.properties示例

server.port=8080
spring.datasource.url=jdbc:postgresql://localhost:5432/db_name
spring.datasource.username=postgres
spring.datasource.password=password

spring.jpa.hibernate.ddl-auto=create-drop
spring.jpa.show-sql=true
spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.PostgreSQLDialect
spring.jpa.properties.hibernate.format_sql=true

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.17 07:05:22