Skip to content

Commit

Permalink
feat(compute): Set default application_name for pgbouncer connections (
Browse files Browse the repository at this point in the history
…#9973)

## Problem

When client specifies `application_name`, pgbouncer propagates it to the
Postgres. Yet, if client doesn't do it, we have hard time figuring out
who opens a lot of Postgres connections (including the `cloud_admin`
ones).

See this investigation as an example:
https://neondb.slack.com/archives/C0836R0RZ0D

## Summary of changes

I haven't found this documented, but it looks like pgbouncer accepts
standard Postgres connstring parameters in the connstring in the
`[databases]` section, so put the default `application_name=pgbouncer`
there. That way, we will always see who opens Postgres connections. I
did tests, and if client specifies a `application_name`, pgbouncer
overrides this default, so it only works if it's not specified or set to
blank `&application_name=` in the connection string.

This is the last place we could potentially open some Postgres
connections without `application_name`. Everything else should be either
of two:
1. Direct client connections without `application_name`, but these
should be strictly non-`cloud_admin` ones
2. Some ad-hoc internal connections, so if we see spikes of unidentified
`cloud_admin` connections, we will need to investigate it again.

Fixes neondatabase/cloud#20948
  • Loading branch information
ololobus authored Dec 4, 2024
1 parent bd52822 commit 9a4157d
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion compute/etc/pgbouncer.ini
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
[databases]
*=host=localhost port=5432 auth_user=cloud_admin
;; pgbouncer propagates application_name (if it's specified) to the server, but some
;; clients don't set it. We set default application_name=pgbouncer to make it
;; easier to identify pgbouncer connections in Postgres. If client sets
;; application_name, it will be used instead.
*=host=localhost port=5432 auth_user=cloud_admin application_name=pgbouncer
[pgbouncer]
listen_port=6432
listen_addr=0.0.0.0
Expand Down

1 comment on commit 9a4157d

@github-actions
Copy link

Choose a reason for hiding this comment

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

7166 tests run: 6848 passed, 0 failed, 318 skipped (full report)


Flaky tests (2)

Postgres 15

Code coverage* (full report)

  • functions: 30.8% (8258 of 26823 functions)
  • lines: 47.8% (65141 of 136319 lines)

* collected from Rust tests only


The comment gets automatically updated with the latest test results
9a4157d at 2024-12-04T15:32:13.825Z :recycle:

Please sign in to comment.