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

SonarQube 6.7.1 WEB服务无法与JDBC 42.1.4连接求助

解决SonarQube 6.7.1连接PostgreSQL 9.5失败的问题

先梳理下你的环境信息:

  • OS:Ubuntu 16.04 64位LTS
  • SonarQube:6.7.1
  • PostgreSQL:9.5
  • Java:1.8.0_144
  • SonarQube自带JDBC驱动版本:42.1.4

你遇到的错误日志如下:

ERROR web[][o.postgresql.Driver] 连接错误:org.postgresql.util.PSQLException: 连接尝试失败。
at org.postgresql.core.v3.ConnectionFactoryImpl.openConnectionImpl(ConnectionFactoryImpl.java:275)
at org.postgresql.core.ConnectionFactory.openConnection(ConnectionFactory.java:49)
at org.postgresql.jdbc.PgConnection.<init>(PgConnection.java:194)
at org.postgresql.Driver.makeConnection(Driver.java:450)
at org.postgresql.Driver.connect(Driver.java:252)
at org.apache.commons.dbcp.DriverConnectionFactory.createConnection(DriverConnectionFactory.java:38)
at org.apache.commons.dbcp.PoolableConnectionFactory.makeObject(PoolableCo...

可能的排查方向和解决方案

1. 优先排查JDBC驱动兼容性问题

SonarQube 6.7.1自带的JDBC驱动42.1.4和PostgreSQL 9.5之间存在兼容性冲突——42.1.x版本的驱动对较老的PostgreSQL版本(比如9.5)支持不太友好。你可以按下面步骤替换驱动:

  • 找到SonarQube安装目录下的extensions/jdbc-driver/postgresql文件夹
  • 删除里面的postgresql-42.1.4.jar文件
  • 下载适配PostgreSQL 9.5的驱动版本(推荐postgresql-42.0.0.jar)放到这个目录里
  • 重启SonarQube服务,再看连接是否正常

2. 检查SonarQube的数据库配置是否正确

打开SonarQube配置文件conf/sonar.properties,核对以下关键配置:

sonar.jdbc.url=jdbc:postgresql://localhost:5432/sonarqube?currentSchema=public
sonar.jdbc.username=你的数据库用户名
sonar.jdbc.password=你的数据库密码
  • 确认数据库地址、端口、库名完全正确,如果SonarQube和PostgreSQL不在同一台服务器,要把localhost换成PostgreSQL服务器的IP
  • 确保这个数据库用户有访问sonarqube库的权限,可以在PostgreSQL里执行GRANT ALL PRIVILEGES ON DATABASE sonarqube TO 你的用户名;来赋权

3. 调整PostgreSQL的远程连接设置(如果跨服务器部署)

如果SonarQube和PostgreSQL不在同一机器,需要让PostgreSQL允许外部连接:

  • 编辑PostgreSQL配置文件/etc/postgresql/9.5/main/postgresql.conf,把listen_addresses改成*(或者指定SonarQube服务器的IP)
  • 编辑/etc/postgresql/9.5/main/pg_hba.conf,添加一条访问规则:
    host    sonarqube     你的数据库用户名     SonarQube服务器IP/32     md5
    
  • 重启PostgreSQL服务:sudo systemctl restart postgresql

4. 检查防火墙是否拦截了连接

Ubuntu的防火墙可能会阻止5432端口的访问,执行以下命令开放端口:

sudo ufw allow 5432/tcp
sudo ufw reload

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.05.19 03:13:35