From 689cadac513160e1e6bad86cc098003936bb8eaf Mon Sep 17 00:00:00 2001 From: Facetoe Date: Tue, 4 Oct 2016 22:36:59 +0800 Subject: [PATCH] Use only one query. --- python.d/postgres.chart.py | 17 ++++++----------- 1 file changed, 6 insertions(+), 11 deletions(-) diff --git a/python.d/postgres.chart.py b/python.d/postgres.chart.py index 88ca1e95..9e3b481c 100644 --- a/python.d/postgres.chart.py +++ b/python.d/postgres.chart.py @@ -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 -- 2.39.2