Search code examples
javapostgresqlhibernatejdbcheroku-postgres

How to deal with: SQL Error: 0, SQLState: 08006 and 08003?


I have application on heroku with PostgreSQL db. And parser, which running on my PC, it save and read data from heroku's db every 10 minutes and uses hibernate to interact. Here is config:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-configuration PUBLIC
        "-//Hibernate/Hibernate Configuration DTD 3.0//EN"
        "http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
    <session-factory>
        <property name="hibernate.connection.driver_class">org.postgresql.Driver</property>
        <property name="hibernate.connection.url">jdbc:postgresql:url</property>
        <property name="hibernate.connection.username">user</property>
        <property name="hibernate.connection.password">pass</property>
        <property name="hibernate.dialect">org.hibernate.dialect.PostgreSQL94Dialect</property>
        <property name="show_sql">true</property>

        <property name="hibernate.c3p0.idle_test_period">14400</property><property name="hibernate.c3p0.timeout">25200</property>
        <property name="hibernate.c3p0.max_size">15</property>
        <property name="hibernate.c3p0.min_size">3</property>
        <property name="hibernate.c3p0.max_statements">0</property>
        <property name="hibernate.c3p0.preferredTestQuery">select 1;</property>

    </session-factory>
</hibernate-configuration>

But after some time pass my parser stopping and I get this:

окт 25, 2019 12:44:59 AM org.hibernate.engine.jdbc.spi.SqlExceptionHelper logExceptions
WARN: SQL Error: 0, SQLState: 08006
окт 25, 2019 12:44:59 AM org.hibernate.engine.jdbc.spi.SqlExceptionHelper logExceptions
ERROR: Ошибка ввода/ввывода при отправке бэкенду
окт 25, 2019 12:44:59 AM org.hibernate.engine.jdbc.spi.SqlExceptionHelper logExceptions
WARN: SQL Error: 0, SQLState: 08003
окт 25, 2019 12:44:59 AM org.hibernate.engine.jdbc.spi.SqlExceptionHelper logExceptions
ERROR: Соединение уже было закрыто

What ways there is to solve this problem?


Solution

  • Your database connection is getting closed, and you're testing their validity only every 3 hours. The idle testing is apparently not a good idea anyway.

    Unless you're working in a legacy environment, you should set hibernate.c3p0.testconnectiononcheckout=true, that way you'll always get a valid connection.

    The preferredTestQuery is unnecessary too, if you're working with a JDBC4 driver (and hopefully you are).