@cryptotaxi247 / netdata-1 / commits / 39f0415fa

Reuse existing connection.

Facetoe committed Oct 23, 2016 at 17:57 UTC 39f0415fa556a793af6ff903d86be6e6f63f34e1
1 file changed +4 -6
python.d/postgres.chart.py
+4 -6
@@ -246,15 +246,15 @@ class Service(SimpleService):
246 host='localhost',
247 port=5432)
248 params.update(self.configuration)
249 - self.connection = psycopg2.connect(**params)
250 - self.connection.set_isolation_level(extensions.ISOLATION_LEVEL_AUTOCOMMIT)
251 - self.connection.set_session(readonly=True)
249 + if not self.connection:
250 + self.connection = psycopg2.connect(**params)
251 + self.connection.set_isolation_level(extensions.ISOLATION_LEVEL_AUTOCOMMIT)
252 + self.connection.set_session(readonly=True)
253
254 def check(self):
255 try:
256 self.connect()
257 self.discover_databases()
257 - self.connection.close()
258 self._create_definitions()
259 return True
260 except Exception as e:
@@ -330,8 +330,6 @@ class Service(SimpleService):
330 self.add_stats(cursor)
331
332 cursor.close()
333 - self.connection.close()
334 -
333 return self.data
334
335 def add_stats(self, cursor):