diff --git a/ckan/config/environment.py b/ckan/config/environment.py index 6eaf499193d..16c5842afcf 100644 --- a/ckan/config/environment.py +++ b/ckan/config/environment.py @@ -293,6 +293,10 @@ def update_config(): # CONFIGURATION OPTIONS HERE (note: all config options will override # any Pylons config options) + # Enable pessimistic disconnect handling (added in SQLAlchemy 1.2) + # to eliminate database errors due to stale pooled connections + config.setdefault('pool_pre_ping', True) + # Initialize SQLAlchemy engine = sqlalchemy.engine_from_config(config) model.init_model(engine) diff --git a/ckanext/datastore/backend/postgres.py b/ckanext/datastore/backend/postgres.py index 987b079e973..b3ea070b3bf 100644 --- a/ckanext/datastore/backend/postgres.py +++ b/ckanext/datastore/backend/postgres.py @@ -115,6 +115,7 @@ def _get_engine_from_url(connection_url): engine = _engines.get(connection_url) if not engine: extras = {'url': connection_url} + config.setdefault('pool_pre_ping', True) engine = sqlalchemy.engine_from_config(config, 'ckan.datastore.sqlalchemy.', **extras)