Skip to content

feat: expose usage counters for prepared statements#1192

Merged
JelteF merged 6 commits into
pgbouncer:masterfrom
sboschman:task-ps-stats
Nov 2, 2024
Merged

feat: expose usage counters for prepared statements#1192
JelteF merged 6 commits into
pgbouncer:masterfrom
sboschman:task-ps-stats

Conversation

@sboschman
Copy link
Copy Markdown
Contributor

With prepared statements tracking enabled in PgBouncer we internally track the following counters:

  • ps_client_parse_count
  • ps_server_parse_count
  • ps_bind_count

But we only expose them in log/systemd messages, but not in any SHOW command, which are used by external monitoring tools like pgbouncer_exporter. These counters are imo important to gain insight in how well 'prepared statement caching' in PgBouncer is working for your workload and your configuration. I think of them as a sort of 'cache hit ratio'.

Signed-off-by: Sverre Boschman <1142569+sboschman@users.noreply.github.com>
@sboschman
Copy link
Copy Markdown
Contributor Author

@JelteF hopefully you have time to take a look at this addition to the prepared statement implementation

@JelteF
Copy link
Copy Markdown
Member

JelteF commented Oct 28, 2024

LGTM, but needs some manual testing on my or someone else's side.

@JelteF
Copy link
Copy Markdown
Member

JelteF commented Oct 28, 2024

If you could add some tests for this that would be great btw.

@sboschman
Copy link
Copy Markdown
Contributor Author

If you could add some tests for this that would be great btw.

What kind of tests are you thinking about? The existing test_admin tests already check the SHOW commands. So f.e. a mismatch between header columns and data columns is detected.

@JelteF
Copy link
Copy Markdown
Member

JelteF commented Oct 29, 2024

Basically a modification to test_show_stats() to show that the returned counts make sense:

def test_show_stats(bouncer):

@sboschman
Copy link
Copy Markdown
Contributor Author

A small test case has been added to the prepared statement test suite: test_prepared.py

Anything else I can do to help out on this issue @JelteF ?

@JelteF JelteF merged commit ee2811a into pgbouncer:master Nov 2, 2024
@sboschman sboschman deleted the task-ps-stats branch November 4, 2024 15:39
rajaryanece pushed a commit to rajaryanece/pgbouncer that referenced this pull request Jan 16, 2025
With prepared statements tracking enabled in PgBouncer we internally
track the following counters:
- ps_client_parse_count
- ps_server_parse_count
- ps_bind_count

But we only exposed them in log/systemd messages, but not in any `SHOW`
command, which are used by external monitoring tools like
pgbouncer_exporter. This starts exporting them in `SHOW` commands.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants