Skip to content

[-] fix quoting $databases var in pgbouncer dashboard#1349

Merged
0xgouda merged 5 commits intocybertec-postgresql:masterfrom
slardiere:master
Apr 3, 2026
Merged

[-] fix quoting $databases var in pgbouncer dashboard#1349
0xgouda merged 5 commits intocybertec-postgresql:masterfrom
slardiere:master

Conversation

@slardiere
Copy link
Copy Markdown
Contributor

@slardiere slardiere commented Mar 31, 2026

Description

with the default use of the $databases variable in Grafana, the quoting is wrong when there is only one DB selected by the user.

AI & Automation Policy

  • I am the human author and take full personal responsibility for every change in this PR.
  • No AI or automated generative tool was used in any part of this PR OR I have disclosed all tool(s) below.

AI/automation tools used (leave blank if none):

Sébastien Lardière and others added 2 commits March 31, 2026 16:39
    with the default use of the $databases variable in Grafana, the quoting is wrong when there is only one DB selected by the user.
@slardiere slardiere changed the title Fix quoting databases name Fix quoting databases name in pgbouncer dashboard Apr 1, 2026
@0xgouda
Copy link
Copy Markdown
Collaborator

0xgouda commented Apr 2, 2026

Can you share before and after screenshots?

@0xgouda 0xgouda self-assigned this Apr 2, 2026
@0xgouda 0xgouda added the dashboards Grafana dashboards related label Apr 2, 2026
@slardiere
Copy link
Copy Markdown
Contributor Author

Before this fix, there is just empty panels with an error:

db query error: ERROR: column "dotclear" does not exist (SQLSTATE 42703)

image

The query is just :

select
  floor(extract(epoch from time)/120)*120 AS "time",
  avg((c - c_lag) / extract(epoch from time - time_lag)) as tps
from (
        select 
          (data->>'total_xact_count')::int8 as c, lag((data->>'total_xact_count')::int8) over w as c_lag,
          time, lag(time) over w as time_lag
        from pgbouncer_stats
        where data->>'database' in (dotclear) and dbname = 'pgb_spokane' and time BETWEEN '2026-04-03T07:09:03.82Z' AND '2026-04-03T07:24:03.82Z'
        window w as (order by data->>'database', time)        
) x
where c >= c_lag and time > time_lag
group by 1
order by 1

You can see the value dotclear which should be quoted.

Grafana manage that with a format option : https://grafana.com/docs/grafana/latest/visualizations/dashboards/variables/variable-syntax/

which gives : ${databases:singlequote} which fix this problem.

best regards,
Sébastien

Copy link
Copy Markdown
Collaborator

@0xgouda 0xgouda left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thanks for your contribution!

Note to self (to inspect later):

I am a bit confused why the upper panels give an error because the $databases var does not get quoted properly, but the below ones work, and the var gets quoted:
both used to have data->>'database' in ($databases)

Image

@0xgouda 0xgouda changed the title Fix quoting databases name in pgbouncer dashboard [-] fix quoting $databases var in pgbouncer dashboard Apr 3, 2026
@0xgouda 0xgouda merged commit 6859e01 into cybertec-postgresql:master Apr 3, 2026
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

dashboards Grafana dashboards related

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants