Search code examples
postgresqlgrailsjdbc

Configuring Grails 3 for Postgresql


I've been trying to get grails 3 to connect to postgres and cannot get a connection.

This is in my build file: runtime "org.postgresql:postgresql:42.2.5"

and the application.yml datasource:

dataSource:
    pooled: true
    jmxExport: true
    driverClassName: 'org.Postgresql.Driver'
    dialect: 'org.hibernate.dialect.PostgreSQLDialect'
    username: 'okcomputer'
    password: ''

environments:
    development:
        dataSource:
            dbCreate: create-drop
            url: jdbc:postgresql://localhost:5432/test
    test:
        dataSource:
            dbCreate: update
            url: jdbc:postgresql://localhost:5432/test
    production:
        dataSource:
            dbCreate: none
            url: jdbc:postgresql://localhost:5432/test
            properties:
                jmxEnabled: true
                initialSize: 5
                maxActive: 50
                minIdle: 5
                maxIdle: 25
                maxWait: 10000
                maxAge: 600000
                timeBetweenEvictionRunsMillis: 5000
                minEvictableIdleTimeMillis: 60000
                validationQuery: SELECT 1
                validationQueryTimeout: 3
                validationInterval: 15000
                testOnBorrow: true
                testWhileIdle: true
                testOnReturn: false
                jdbcInterceptors: ConnectionState
                defaultTransactionIsolation: 2 # TRANSACTION_READ_COMMITTED

What am I doing wrong here? I'm sure the database exists and the user/pass is correct, but am not sure what to do in order to troubleshoot. A full stack trace is available here: https://pastebin.com/THrALVaE

(I'm using java 1.8 and grails 3.3.8)

Theres a surprisingly small amount of information regarding grails and postgres, so thanks to everyone in advance!


Solution

  • The driver name should probably be org.postgresql.Driver instead of org.Postgresql.Driver. Class names and package names are case sensitive on the JVM.

    dataSource:
        pooled: true
        jmxExport: true
        driverClassName: 'org.postgresql.Driver'
        dialect: 'org.hibernate.dialect.PostgreSQLDialect'
        username: 'okcomputer'
        password: ''