【问题标题】:Flyway cannot connect to db after Heroku Postgres upgradeHeroku Postgres 升级后 Flyway 无法连接到数据库
【发布时间】:2017-02-24 23:11:45
【问题描述】:

我正在将我的 heroku 数据库从业余开发者升级到标准 0(使用官方说明 https://devcenter.heroku.com/articles/upgrading-heroku-postgres-databases#upgrade-with-pg-copy-default)。

一切顺利,直到我推广新数据库并重新启动应用程序。然后我收到以下错误:

o.s.boot.SpringApplication               : Application startup failed
...
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'flywayInitializer' defined in class path resource [org/springframework/boot/autoconfigure/flyway/FlywayAutoConfiguration$FlywayConfiguration.class]: Invocation of init method failed; nested exception is org.flywaydb.core.api.FlywayException: Unable to obtain Jdbc connection from DataSource
...
Caused by: org.flywaydb.core.api.FlywayException: Unable to obtain Jdbc connection from DataSource
...
Caused by: org.postgresql.util.PSQLException: FATAL: no pg_hba.conf entry for host "54.xxx.xx.xxx", user "u94bf9vxxxxxx", database "d2mqk0b6xxxxxx", SSL off
...

如果我再次切换回旧数据库,一切都会恢复正常。我唯一要更改的是提升的数据库。

连接到我需要注意的爱好和标准数据库之间有什么区别吗?

我的 application.yml 的相关部分如下所示:

spring:
    datasource:
        driverClassName: org.postgresql.Driver
        url: ${JDBC_DATABASE_URL} 
        username: ${JDBC_DATABASE_USERNAME}
        password: ${JDBC_DATABASE_PASSWORD}
flyway:
    enabled: true
    locations: classpath:db/migrations

任何关于如何调试它的建议也非常受欢迎。

【问题讨论】:

  • 不能说我最近用过 Heroku,但你可以访问 pg_hba.conf 吗?如果是这样,请提供肯定有助于隔离问题的内容。
  • 很遗憾没有,这是隐藏的,不可编辑。

标签: postgresql heroku spring-boot flyway


【解决方案1】:

看起来您没有使用安装 Heroku PostgreSQL 所需的 SSL 连接。

请参阅 Herokus documentation on SSL for PostgreSQL。

另请参阅有关 JDBC 连接的 Herokus documentation for enabling SSL。

您需要将 &ssl=true&sslfactory=org.postgresql.ssl.NonValidatingFactory 之类的内容添加到您的 JDBC URL。

【讨论】:

  • 谢谢 - 准确。附言我也得到了 Heroku 支持的回复。他们提出了同样的建议。但也建议将我的 postgres JDBC 驱动程序升级到 9.4.x(我使用的是 9.0.x)。这样做也修复了它(似乎较新的驱动程序默认执行上述行为)。
猜你喜欢
  • 1970-01-01
  • 2017-01-10
  • 2016-01-14
  • 1970-01-01
  • 2014-12-14
  • 2016-06-02
  • 2013-03-08
  • 2013-04-21
  • 2021-07-10
相关资源
最近更新 更多