@cryptotaxi247 / netdata-1 / commits / 689cadac5

Use only one query.

Facetoe committed Oct 4, 2016 at 22:36 UTC 689cadac513160e1e6bad86cc098003936bb8eaf
1 file changed +6 -11
python.d/postgres.chart.py
+6 -11
@@ -79,6 +79,7 @@ class Service(SimpleService):
79 params.update(self.configuration)
80 if self.connection is None:
81 self.connection = psycopg2.connect(**params)
82 + self.connection.set_session(readonly=True)
83
84 def check(self):
85 try:
@@ -90,23 +91,17 @@ class Service(SimpleService):
91
92 def _get_data(self):
93 cursor = self.connection.cursor(cursor_factory=DictCursor)
93 - cursor.execute("""
94 - SELECT *
95 - FROM pg_stat_database
96 - WHERE datname = %(database)s
97 - """, self.configuration)
98 - graph_data = dict(cursor.fetchone())
99 -
100 - # Pull in BGWriter info
94 cursor.execute("""
95 SELECT
96 + pg_stat_database.*,
97 pg_stat_get_bgwriter_timed_checkpoints() AS bg_checkpoint_time,
98 pg_stat_get_bgwriter_requested_checkpoints() AS bg_checkpoint_requested,
99 pg_stat_get_buf_written_backend() AS buffers_written,
100 pg_stat_get_buf_alloc() AS buffers_allocated
107 - """)
108 - graph_data.update(dict(cursor.fetchone()))
109 -
101 + FROM pg_stat_database
102 + WHERE datname = %(database)s
103 + """, self.configuration)
104 + graph_data = dict(cursor.fetchone())
105 self.connection.commit()
106 cursor.close()
107 return graph_data