Heroku postgres关系“information_schema.session_state”不存在

时间:2017-12-01 08:49:23

标签: postgresql heroku kotlin heroku-postgres ktor

我正在尝试将Ktor后端移至Heroku postgres db。这里整个应用程序代码:

https://github.com/MarcinMoskala/KotlinAcademyApp/tree/master/backend

要转移到Heroku postgres,我基于这个示例项目:

https://github.com/orangy/ktor-heroku-start

我将数据库配置更改为以下内容:

private val config = application.environment.config.config("database")

private val poolSize = config.property("poolSize").getString().toInt()

private val hikariConfig = HikariConfig().apply {
    val url = System.getenv("JDBC_DATABASE_URL") ?: config.property("connection").getString()
    application.log.info("DB url is $url")
    jdbcUrl = url
    maximumPoolSize = poolSize
    validate()
}

private val dataSource = HikariDataSource(hikariConfig)

private val connection: DatabaseConnection = H2Connection { dataSource.connection }

private val dispatcher = newFixedThreadPoolContext(poolSize, "database-pool")

init {
    connection.transaction {
        databaseSchema().create(listOf(NewsTable, FeedbackTable, TokensTable))
    }
}

我添加了postgressql依赖:

compile "org.postgresql:postgresql:9.4-1201-jdbc4"

在本地它仍在创建SQLite数据库,但当我将它推送到Heroku时,我有以下结果:

DEBUG com.zaxxer.hikari.HikariConfig - jdbc4ConnectionTest.............false
DEBUG com.zaxxer.hikari.HikariConfig - jdbcUrl.........................jdbc:postgresql://ec7-77-77-777-77.compute-1.amazonaws.com:7777/7777777?user=aaaaaaaaaaaa&password=<masked>&sslmode=require
DEBUG com.zaxxer.hikari.HikariConfig - leakDetectionThreshold..........0
DEBUG com.zaxxer.hikari.HikariConfig - maximumPoolSize.................20
DEBUG com.zaxxer.hikari.HikariConfig - maxLifetime.....................1800000
DEBUG com.zaxxer.hikari.HikariConfig - metricRegistry..................none
DEBUG com.zaxxer.hikari.HikariConfig - metricsTrackerFactory...........none
DEBUG com.zaxxer.hikari.HikariConfig - minimumIdle.....................20
DEBUG com.zaxxer.hikari.HikariConfig - password........................<masked>
 [main] DEBUG com.zaxxer.hikari.HikariConfig - poolName........................"HikariPool-1"
DEBUG com.zaxxer.hikari.HikariConfig - registerMbeans..................false
DEBUG com.zaxxer.hikari.HikariConfig - readOnly........................false
DEBUG com.zaxxer.hikari.HikariConfig - scheduledExecutor...............none
DEBUG com.zaxxer.hikari.HikariConfig - scheduledExecutorService........internal
DEBUG com.zaxxer.hikari.HikariConfig - schema..........................none
DEBUG com.zaxxer.hikari.HikariConfig - threadFactory...................internal
DEBUG com.zaxxer.hikari.HikariConfig - transactionIsolation............default
DEBUG com.zaxxer.hikari.HikariConfig - username........................none
DEBUG com.zaxxer.hikari.HikariConfig - validationTimeout...............5000
DEBUG com.zaxxer.hikari.HikariConfig - allowPoolSuspension.............false
DEBUG com.zaxxer.hikari.HikariConfig - autoCommit......................true
DEBUG com.zaxxer.hikari.HikariConfig - HikariPool-1 - configuration:
DEBUG com.zaxxer.hikari.HikariConfig - connectionInitSql...............none
DEBUG com.zaxxer.hikari.HikariConfig - catalog.........................none
DEBUG com.zaxxer.hikari.HikariConfig - connectionTestQuery.............none
DEBUG com.zaxxer.hikari.HikariConfig - connectionTimeout...............30000
DEBUG com.zaxxer.hikari.HikariConfig - dataSource......................none
DEBUG com.zaxxer.hikari.HikariConfig - dataSourceClassName.............none
DEBUG com.zaxxer.hikari.HikariConfig - dataSourceJNDI..................none
DEBUG com.zaxxer.hikari.HikariConfig - dataSourceProperties............{password=<masked>}
DEBUG com.zaxxer.hikari.HikariConfig - driverClassName.................none
DEBUG com.zaxxer.hikari.HikariConfig - healthCheckProperties...........{}
DEBUG com.zaxxer.hikari.HikariConfig - healthCheckRegistry.............none
DEBUG com.zaxxer.hikari.HikariConfig - idleTimeout.....................600000
DEBUG com.zaxxer.hikari.HikariConfig - initializationFailFast..........true
DEBUG com.zaxxer.hikari.HikariConfig - initializationFailTimeout.......1
DEBUG com.zaxxer.hikari.HikariConfig - isolateInternalQueries..........false
DEBUG com.zaxxer.hikari.HikariConfig - jdbc4ConnectionTest.............false
DEBUG com.zaxxer.hikari.HikariConfig - jdbcUrl.........................jdbc:postgresql://ec2-23-21-155-53.compute-1.amazonaws.com:5432/d1bj65rb5gi9qt?user=ufwvhxlvfjopkm&password=<masked>&sslmode=require
DEBUG com.zaxxer.hikari.HikariConfig - maxLifetime.....................1800000
DEBUG com.zaxxer.hikari.HikariConfig - leakDetectionThreshold..........0
DEBUG com.zaxxer.hikari.HikariConfig - maximumPoolSize.................20
DEBUG com.zaxxer.hikari.HikariConfig - metricRegistry..................none
DEBUG com.zaxxer.hikari.HikariConfig - metricsTrackerFactory...........none
DEBUG com.zaxxer.hikari.HikariConfig - minimumIdle.....................20
DEBUG com.zaxxer.hikari.HikariConfig - password........................<masked>
DEBUG com.zaxxer.hikari.HikariConfig - poolName........................"HikariPool-1"
DEBUG com.zaxxer.hikari.HikariConfig - readOnly........................false
DEBUG com.zaxxer.hikari.HikariConfig - registerMbeans..................false
DEBUG com.zaxxer.hikari.HikariConfig - scheduledExecutorService........internal
DEBUG com.zaxxer.hikari.HikariConfig - scheduledExecutor...............none
DEBUG com.zaxxer.hikari.HikariConfig - schema..........................none
DEBUG com.zaxxer.hikari.HikariConfig - threadFactory...................internal
DEBUG com.zaxxer.hikari.HikariConfig - transactionIsolation............default
DEBUG com.zaxxer.hikari.HikariConfig - username........................none
DEBUG com.zaxxer.hikari.HikariConfig - validationTimeout...............5000
INFO  com.zaxxer.hikari.HikariDataSource - HikariPool-1 - Starting...
Process exited with status 1
2017-12-01 08:38:27.783 [main] INFO  com.zaxxer.hikari.pool.PoolBase - HikariPool-1 - Driver does not support get/set network timeout for connections. (Method org.postgresql.jdbc4.Jdbc4Connection.getNetworkTimeout() is not yet implemented.)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
2017-12-01 08:38:27.832 [main] DEBUG com.zaxxer.hikari.pool.HikariPool - HikariPool-1 - Added connection org.postgresql.jdbc4.Jdbc4Connection@49c66ade
2017-12-01 08:38:27.834 [main] INFO  com.zaxxer.hikari.HikariDataSource - HikariPool-1 - Start completed.
Exception in thread "main" java.lang.reflect.InvocationTargetException
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at kotlin.reflect.jvm.internal.KCallableImpl.call(KCallableImpl.kt:107)
    at kotlin.reflect.jvm.internal.FunctionCaller$Method.callMethod(FunctionCaller.kt:98)
    at kotlin.reflect.jvm.internal.FunctionCaller$StaticMethod.call(FunctionCaller.kt:108)
    at kotlin.reflect.jvm.internal.KCallableImpl.callDefaultMethod(KCallableImpl.kt:149)
    at kotlin.reflect.jvm.internal.KCallableImpl.callBy(KCallableImpl.kt:111)
    at io.ktor.server.engine.ApplicationEngineEnvironmentReloading.executeModuleFunction(ApplicationEngineEnvironmentReloading.kt:270)
    at io.ktor.server.engine.ApplicationEngineEnvironmentReloading.instantiateAndConfigureApplication(ApplicationEngineEnvironmentReloading.kt:247)
    at io.ktor.server.engine.ApplicationEngineEnvironmentReloading.callFunctionWithInjection(ApplicationEngineEnvironmentReloading.kt:314)
    at io.ktor.server.engine.ApplicationEngineEnvironmentReloading.createApplication(ApplicationEngineEnvironmentReloading.kt:118)
    at io.ktor.server.engine.ApplicationEngineEnvironmentReloading.start(ApplicationEngineEnvironmentReloading.kt:227)
    at io.ktor.server.netty.NettyApplicationEngine.start(NettyApplicationEngine.kt:43)
    at com.marcinmoskala.kotlinacademy.backend.ServerKt.main(Server.kt:8)
    at io.ktor.server.netty.NettyApplicationEngine.start(NettyApplicationEngine.kt:15)
    at io.ktor.server.engine.ApplicationEngine$DefaultImpls.start$default(ApplicationEngine.kt:29)
Caused by: org.postgresql.util.PSQLException: ERROR: relation "information_schema.session_state" does not exist
  Position: 15
    at org.postgresql.jdbc2.AbstractJdbc2Statement.executeWithFlags(AbstractJdbc2Statement.java:420)
    at org.postgresql.core.v3.QueryExecutorImpl.receiveErrorResponse(QueryExecutorImpl.java:2270)
    at org.postgresql.jdbc2.AbstractJdbc2Statement.executeQuery(AbstractJdbc2Statement.java:305)
    at com.zaxxer.hikari.pool.ProxyPreparedStatement.executeQuery(ProxyPreparedStatement.java:52)
    at org.postgresql.core.v3.QueryExecutorImpl.processResults(QueryExecutorImpl.java:1998)
    at org.postgresql.core.v3.QueryExecutorImpl.execute(QueryExecutorImpl.java:255)
    at org.postgresql.jdbc2.AbstractJdbc2Statement.execute(AbstractJdbc2Statement.java:570)
    at com.zaxxer.hikari.pool.HikariProxyPreparedStatement.executeQuery(HikariProxyPreparedStatement.java)
    at org.jetbrains.squash.schema.DatabaseSchemaBase.createStatements(DatabaseSchemaBase.kt:23)
    at org.jetbrains.squash.dialects.h2.H2DatabaseSchema.currentSchema(H2DatabaseSchema.kt:8)
    at org.jetbrains.squash.drivers.JDBCDatabaseSchema.tables(JDBCDatabaseSchema.kt:12)
    at com.marcinmoskala.kotlinacademy.backend.db.Database$1.invoke(Database.kt:25)
    at com.marcinmoskala.kotlinacademy.backend.db.Database.<init>(Database.kt:46)
    at org.jetbrains.squash.schema.DatabaseSchemaBase.create(DatabaseSchemaBase.kt:10)
    at com.marcinmoskala.kotlinacademy.backend.MainKt.main(Main.kt:39)
    at com.marcinmoskala.kotlinacademy.backend.db.Database$1.invoke(Database.kt:47)
    at org.jetbrains.squash.connection.DatabaseConnectionKt.transaction(DatabaseConnection.kt:25)
    ... 18 more
State changed from starting to crashed

1 个答案:

答案 0 :(得分:2)

你不能将H2Connection与Postgress一起使用。将compile "org.jetbrains.squash:squash-postgres:$squash_version"添加到您的Gradle文件中,并将H2Connection替换为PgConnection