]> arthur.barton.de Git - netdata.git/commitdiff
Use only one query.
authorFacetoe <facetoe@facetoe.com.au>
Tue, 4 Oct 2016 14:36:59 +0000 (22:36 +0800)
committerFacetoe <facetoe@facetoe.com.au>
Tue, 4 Oct 2016 14:38:09 +0000 (22:38 +0800)
python.d/postgres.chart.py

index 88ca1e95c607b59bb03f6c2f8757de6cf3e7dbc2..9e3b481c2db687b6c69ac2a60907b6c0ce6b5600 100644 (file)
@@ -79,6 +79,7 @@ class Service(SimpleService):
         params.update(self.configuration)
         if self.connection is None:
             self.connection = psycopg2.connect(**params)
+            self.connection.set_session(readonly=True)
 
     def check(self):
         try:
@@ -90,23 +91,17 @@ class Service(SimpleService):
 
     def _get_data(self):
         cursor = self.connection.cursor(cursor_factory=DictCursor)
-        cursor.execute("""
-            SELECT *
-            FROM pg_stat_database
-            WHERE datname = %(database)s
-        """, self.configuration)
-        graph_data = dict(cursor.fetchone())
-
-        # Pull in BGWriter info
         cursor.execute("""
             SELECT
+              pg_stat_database.*,
               pg_stat_get_bgwriter_timed_checkpoints()     AS bg_checkpoint_time,
               pg_stat_get_bgwriter_requested_checkpoints() AS bg_checkpoint_requested,
               pg_stat_get_buf_written_backend()            AS buffers_written,
               pg_stat_get_buf_alloc()                      AS buffers_allocated
-        """)
-        graph_data.update(dict(cursor.fetchone()))
-
+            FROM pg_stat_database
+            WHERE datname = %(database)s
+        """, self.configuration)
+        graph_data = dict(cursor.fetchone())
         self.connection.commit()
         cursor.close()
         return graph_data