From 87d306c1950b0c62500fd3aaed1530f146dea287 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thomas=20Herv=C3=A9?= Date: Mon, 30 Dec 2019 09:47:13 +0100 Subject: [PATCH] Handle connection closed Reset the connection object to give the opportunity to the check to retry to connect, for example when the database is restarted. --- postgres/datadog_checks/postgres/postgres.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/postgres/datadog_checks/postgres/postgres.py b/postgres/datadog_checks/postgres/postgres.py index d3b0895c2af1c..aef859b615c79 100644 --- a/postgres/datadog_checks/postgres/postgres.py +++ b/postgres/datadog_checks/postgres/postgres.py @@ -512,6 +512,10 @@ def _get_service_check_tags(cls, host, tags): def _connect(self, host, port, user, password, dbname, ssl, tags): """Get and memoize connections to instances""" + if self.db and self.db.closed: + # Reset the connection object to retry to connect + self.db = None + if self.db: if self.db.status != psycopg2.extensions.STATUS_READY: # Some transaction went wrong and the connection is in an unhealthy state. Let's fix that