Grafana version : 11.4.0
I use the variable “vBDD” of type Query in a dashboard:
SELECT datname FROM pg_database where datname not in (‘template1’,‘template0’, ‘pghd’,‘postgres’,‘repmgr’,‘r3d3agt’);
When I reference this variable in the dashboard:
Example:
SELECT date_id AS “time”,
count(pid) AS “nbr active sessions”
FROM histo_pg_stat_activity
WHERE pid <> pg_backend_pid()
AND datid in (select oid from pg_database where datname in (${vBDD}) )
AND state in (‘active’)
AND $__timeFilter(date_id)
GROUP BY date_id
ORDER BY date_id asc
With Grafana 10: It works fine
With Grafana 11: It doesn’t work
The error message is:
db query error : pq: column “dummy” does not exist , db query
error : pq: column “dummy” does not exist
Here is what I found in the postgresql.log file 221932 2025-01-15 08:18:37 CET : ,[1571329], [11]: [0] ,usr=[grafanareader], db=[pghd], cli=[pc2b0445.pcy.edf.fr], app=[[unknown]], sid=[67876109.17fa01],qid=[0] >
221933 count(pid) AS “nbr sessions inactives”
221934 FROM histo_pg_stat_activity
221935 WHERE pid <> pg_backend_pid()
221936 AND datid in (select oid from pg_database where datname in (bddseisme) )
221937 AND state not in (‘active’)
221938 AND date_id BETWEEN ‘2025-01-08T07:13:00.623Z’ AND ‘2025-01-15T07:12:00.624Z’
221939 GROUP BY date_id
221940 ORDER BY date_id asc
The database name is written without quotes and It is considered as a column name.
When I change my query
SELECT date_id AS “time”,
count(pid) AS “nbr sessions actives”
FROM histo_pg_stat_activity
WHERE pid <> pg_backend_pid()
AND datid in (select oid from pg_database where datname in (‘${vBDD}’) )
AND state in (‘active’)
AND $__timeFilter(date_id)
GROUP BY date_id
ORDER BY date_id asc
I have added a quote around the database name. it is OK