Search code examples
javapostgresqlmavenherokuheroku-postgres

How to deploy on Heroku with Postgresql Database?


I have a simple rest app on spring. For deploy I've been created 2 profiles - dev & heroku. With dev profile it is all ok. But I can't deploy to Heroku:

[ERROR] Failed to execute goal org.liquibase:liquibase-maven-plugin:3.5.3:update (default) on project myProject: Error setting up or running Liquibase: liquibase.exception.DatabaseException: liquibase.exception.DatabaseException: Connection could not be created to jdbc:postgres://aa2-22-222-222-222.aaaaaa-1.amazonaws.com:5432/aaaaaaaaa with driver org.postgresql.Driver. Possibly the wrong driver for the given database URL -> [Help 1]

I thought that the problem was in my old driver (locally I am using PG 9.4 but on Heroku is 9.6)

 <dependency>
        <groupId>org.postgresql</groupId>
        <artifactId>postgresql</artifactId>
        <version>42.1.1</version>
    </dependency>

After update the issue was not resolved. I tried to use connection strings directly and from System.env but the result was same.

How can I fix this?


Solution

  • Your database URL starts with jdbc:postgres:// but should be jdbc:postgresql://.

    I recommend using the provided JDBC_DATABASE_URL environment variable instead of parsing the DATABASE_URL yourself:

    https://devcenter.heroku.com/articles/connecting-to-relational-databases-on-heroku-with-java#using-the-jdbc_database_url