aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSteve Klabnik <steve@steveklabnik.com>2012-05-24 14:36:14 -0400
committerSteve Klabnik <steve@steveklabnik.com>2012-05-24 14:36:14 -0400
commit4dacac3baa271597e6bcf3527c557182d64a6a95 (patch)
tree74cb0aecfedacca0f2ad9455dc6027c52cc90785
parentabccf82c8b1010736c72058948d42acb7127f82a (diff)
downloadrails-4dacac3baa271597e6bcf3527c557182d64a6a95.tar.gz
rails-4dacac3baa271597e6bcf3527c557182d64a6a95.tar.bz2
rails-4dacac3baa271597e6bcf3527c557182d64a6a95.zip
Properly discover a connection is closed in postgresql_adapter
PQstatus doesn't properly test if future operations will succeed. A PQping function is added to libpq in PostgreSQL 9.1, but if we rely on it, everyone on earlier versions of Postgres is out of luck, and the pg gem wouldn't have the 'fix' until the next release. Thanks to @cbrecabarren and @ged for handling all the dirty details. Closes #3392.
-rw-r--r--activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb3
1 files changed, 2 insertions, 1 deletions
diff --git a/activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb b/activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb
index d62cf529a4..0bd7403c32 100644
--- a/activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb
+++ b/activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb
@@ -457,7 +457,8 @@ module ActiveRecord
# Is this connection alive and ready for queries?
def active?
- @connection.status == PGconn::CONNECTION_OK
+ @connection.query 'SELECT 1'
+ true
rescue PGError
false
end