Reconnect dropped connections

Issue #129 duplicate
Peter Abrahamsen
created an issue

I would like to be able to detect when the server connection has gone away, and reconnect. Ideally, we would have an "auto-reconnect" option like that of the mysql library. At a minimum, ruby-pg should raise a unique Ruby exception that can be rescued. Currently, it appears to raise a generic PGError.

Comments (6)

  1. Anonymous

    Raising a unique exception would be best. Autoreconnection causes problems unless you can guarantee to return a connection with the exact same state as the connection that was disconnected. PostgreSQL has many options that can be set on a per connection basis via SET, unless you can reapply those settings after reconnection, autoreconnection isn't safe. Even if you can reset all of the settings, autoreconnection would only work properly outside of a transaction. If autoreconnection is added, it should at least be disabled by default.

  2. Michael Granger repo owner
    • changed status to open

    Since libpq itself doesn't provide any sort of reconnect, and as the anonymous poster pointed out, reconnecting is something that belongs in the application domain, I'm inclined to merge this with #5. Is that okay with you @Peter Abrahamsen? I'll look at adding the exception class hierarchy in 0.15.0.

  3. Log in to comment