# Postgresql query + Graph

**URL:** <https://community.grafana.com/t/postgresql-query-graph/3709>\
**Category:** Time Series Panel\
**Tags:** postgres\
**Created:** [November 10, 2017, 10:25am UTC](https://community.grafana.com/t/postgresql-query-graph/3709 "2017-11-10T10:25:28Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![santosr](https://avatars.discourse-cdn.com/v4/letter/s/f475e1/32.png) [@santosr](https://community.grafana.com/u/santosr)\
**Post date:** [November 10, 2017, 10:25am UTC](https://community.grafana.com/t/postgresql-query-graph/3709/1 "2017-11-10T10:25:28Z")

</div>

Hello,

I don’t know if I’m using correctly the datasource of postgresql but:

- I’ve ad a graph with a a query, for example " select count(\*) from my\_table" .

This returns the correct value, wich changes trought time… But grafana is not keep track of the changes so it cannot produce the graph.

When i choose to show the values min max avg current and total, they are always the same trough time.

Thank you

---

<div class="post-metadata">

**Author:** ![torkel](https://sea2.discourse-cdn.com/grafana/user_avatar/community.grafana.com/torkel/32/20_2.png) [@torkel](https://community.grafana.com/u/torkel)\
**Post date:** [November 10, 2017, 11:20am UTC](https://community.grafana.com/t/postgresql-query-graph/3709/2 "2017-11-10T11:20:42Z")

</div>

That query does not return a time column

---

<div class="post-metadata">

**Author:** ![santosr](https://avatars.discourse-cdn.com/v4/letter/s/f475e1/32.png) [@santosr](https://community.grafana.com/u/santosr)\
**Post date:** [November 10, 2017, 3:44pm UTC](https://community.grafana.com/t/postgresql-query-graph/3709/3 "2017-11-10T15:44:39Z")

</div>

hello, thank you for the reply

I added (NOW() ) in my actual query:

SELECT NOW () as time,  
round( (blks\_hit :: NUMERIC / (blks\_hit + blks\_read) :: NUMERIC) \* 100,2) AS read\_hit\_percentage  
FROM  
pg\_stat\_database  
WHERE  
blks\_hit + blks\_read \> 0 AND datname=‘mydatabase’

it does not give me any error, but still does not produce the graphic. What Am Im missing here?

screenshot:

 ![graph](https://us1.discourse-cdn.com/grafana/original/2X/8/8723c3db448cc740a1e217d17fb414c2cc3be189.PNG)

NOTE: if I add a panel (Table) it only produces 1 row every refresh.

thank you

---

<div class="post-metadata">

**Author:** ![svenklemm](https://avatars.discourse-cdn.com/v4/letter/s/e56c9b/32.png) [@svenklemm](https://community.grafana.com/u/svenklemm)\
**Post date:** [November 10, 2017, 7:23pm UTC](https://community.grafana.com/t/postgresql-query-graph/3709/4 "2017-11-10T19:23:27Z")

</div>

Grafana does not collect metrics or remember metrics. Grafana only does visualization you need some other software (for example collectd or telegraf) to do the collecting.

---

<div class="post-metadata">

**Author:** ![santosr](https://avatars.discourse-cdn.com/v4/letter/s/f475e1/32.png) [@santosr](https://community.grafana.com/u/santosr)\
**Post date:** [November 13, 2017, 10:23am UTC](https://community.grafana.com/t/postgresql-query-graph/3709/5 "2017-11-13T10:23:04Z")

</div>

Hello, thank you for the reply.

I already use zabbix integrated with grafana, but when I saw this postgresql datasource directly integrated with grafana, making it possible to do whatever query I wanted, it’s a all new level, in terms of flexibility.

So this makes me wonder what’s the point of having this datasource if we still need an intermediate to do metrics?

With zabbix, using “userParameters” in the agent side I can perform any kind of Query.

I thought by using directly the postgresql datasource in grafana iI could directly access the same data (wich I can) but it is only usefull to “print” current values. To build a simple graph over time ( for example like an hour) it can’t because it does not store the past values.

I think this datasource as the potential to be great by allowing the flexibility to query any postgres DB we want for monitoring… But it could collect values, this could be store e grafana DB no?

Thank you
