0

I have rails and pgBouncer, and I have reconnect: true in the database.yml but I keep getting this in the console:

ActiveRecord::StatementInvalid: PG::ConnectionBad: PQconsumeInput() server closed the connection unexpectedly

The same error happens in sidekiq but not in web, shouldn't rails reconnect after having this error?

MaicolBen
  • 840
  • 1
  • 6
  • 20

2 Answers2

1

It was a timeout configured in the server (that I wasn't aware of). So it doesn't have anything to do with rails/pgbouncer, in fact reconnect flag in the database.yml isn't used anymore in rails.

MaicolBen
  • 840
  • 1
  • 6
  • 20
0

Maybe it is a solution to set the below configuration parameters of Postgresql.

tcp_keepalives_idle (integer)

Specifies the number of seconds of inactivity after which TCP should send a keepalive message to the client. A value of 0 uses the system default. This parameter is supported only on systems that support TCP_KEEPIDLE or an equivalent socket option, and on Windows; on other systems, it must be zero. In sessions connected via a Unix-domain socket, this parameter is ignored and always reads as zero.

tcp_keepalives_interval (integer)

Specifies the number of seconds after which a TCP keepalive message that is not acknowledged by the client should be retransmitted. A value of 0 uses the system default. This parameter is supported only on systems that support TCP_KEEPINTVL or an equivalent socket option, and on Windows; on other systems, it must be zero. In sessions connected via a Unix-domain socket, this parameter is ignored and always reads as zero.

tcp_keepalives_count (integer)

Specifies the number of TCP keepalives that can be lost before the server's connection to the client is considered dead. A value of 0 uses the system default. This parameter is supported only on systems that support TCP_KEEPCNT or an equivalent socket option; on other systems, it must be zero. In sessions connected via a Unix-domain socket, this parameter is ignored and always reads as zero.

fcce
  • 1,034
  • 1
  • 12
  • 24