From 39f0415fa556a793af6ff903d86be6e6f63f34e1 Mon Sep 17 00:00:00 2001 From: Facetoe Date: Sun, 23 Oct 2016 17:57:28 +0800 Subject: [PATCH] Reuse existing connection. --- python.d/postgres.chart.py | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/python.d/postgres.chart.py b/python.d/postgres.chart.py index 9c0e608a..9008b268 100644 --- a/python.d/postgres.chart.py +++ b/python.d/postgres.chart.py @@ -246,15 +246,15 @@ class Service(SimpleService): host='localhost', port=5432) params.update(self.configuration) - self.connection = psycopg2.connect(**params) - self.connection.set_isolation_level(extensions.ISOLATION_LEVEL_AUTOCOMMIT) - self.connection.set_session(readonly=True) + if not self.connection: + self.connection = psycopg2.connect(**params) + self.connection.set_isolation_level(extensions.ISOLATION_LEVEL_AUTOCOMMIT) + self.connection.set_session(readonly=True) def check(self): try: self.connect() self.discover_databases() - self.connection.close() self._create_definitions() return True except Exception as e: @@ -330,8 +330,6 @@ class Service(SimpleService): self.add_stats(cursor) cursor.close() - self.connection.close() - return self.data def add_stats(self, cursor): -- 2.39.2