rails/rails — Issue #3392: PostgreSQL adapter: reconnection problem
Author: cbrecabarren
Created: 2011-10-21 17:52:35+00:00
State: open

It seems that `PostgreSQLAdapter#active?` fails to recognize a disconnection
from the database server (e.g., when the daemon is restarted).

The problem is that the connection status (as informed by
`@connection.status`) is not updated in this situation, leading the
verification routine (`#verify!`) to incorrectly assume that the
database connection is still valid, preventing an automatic
reconnection, and failing in the next query.

A possible solution would be to adopt a previous mechanism for connection
verification, used before the availability of version 0.11.0 of the
`pg` gem (see commit 0eea560b485b6aac0e13119b7a6b925c24051f00).

```ruby
def active?
@connection.query 'SELECT 1'
true
rescue PGError
false
end
```