]> arthur.barton.de Git - netdata.git/blobdiff - python.d/postgres.chart.py
Reuse existing connection.
[netdata.git] / python.d / postgres.chart.py
index 9c0e608a849396b761435c7172cd27dab81e5c29..9008b2682fe5837e0e9c8dc635850a94850676f5 100644 (file)
@@ -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):