prometheus-community/pgbouncer_exporter

How to correctly specify the connection string

vetalfw opened this issue · 7 comments

Could you tell me how to correctly specify the connection string if there is a dash in the name of my database. Connection string example:

- --pgBouncer.connectionString=postgres://$(DB_USER):$(DB_PASSWORD)@127.0.0.1:5432/tmp-test-db?sslmode=disable&connect_timeout=10

The error I am getting:

{"caller":"collector.go:129","err":"error pinging pgbouncer: \"pq: unrecognized configuration parameter \\\"stats\\\"\"","level":"error","msg":"error setting up DB connection","ts":"2022-05-10T19:56:15.348Z"}

Or I can't use the current database and I need to create a new one? Could you please helm me? Thanks

I got similar issue

+1 same error, looks like code is outdated

your database name specified wrong!
you must define a user for admin user and set
admin_users = someuser
in your pgbouncer.ini file
its obvious this user must be defined in your auth_file!
and this user can read metrics data on pgbonucer database
so your connection string goes like this (with correct flag):
--pgBouncer.connectionString="postgres://$YOUR_USERNAME:$YOUR_PASS@$HOST:$PORT/pgbouncer?sslmode=disable"

you must keep pgbouncer as database name

Maybe the following will be helpful for other people stumbling over this:

  • Make sure that you url-encode ("Percent encoding") the username and the password in the connection string. (e.g. if your password would be "foo bar" it would become "foo%20bar")
  • In the issue description above the user is connecting to /tmp-test-db. This is not correct. You should be connecting to /pgbouncer. pgbouncer exposes a special database, called pgbouncer, which one has to connect to for pgbouncer statistics.
  • Make sure that a valid database user is specified in the pgbouncer.ini under stats_users. Otherwise you won't be able to connect as the specified user to the special pgbouncer database.
vvitad commented

Hello, everyone! Does anyone know how to

  • correctly describe a systemd unit (mine is failing with connection refused error, but the ExecStart works outside of the unit correctly)
  • change timezone

@vvitad just guessing here, but did you…

  • check that you url encoded your password?

    e.g. let's say you have a connection string like this:
    postgres://coolusername:amazing special%password@localhost:6432/pgbouncer?sslmode=disable

    the pw would become amazing%20special%25password.

    The end result:
    postgres://coolusername:amazing%20special%25password@localhost:6432/pgbouncer?sslmode=disable.

    However, note the next step as well ->

  • when you are url encoding, you also need to make sure that you replace % with %%.

    systemd files support special syntax that uses %. If you want to actually use the percentage sign, then you have to write %%.

    Continuing the example above and replacing % with %%:
    postgres://coolusername:amazing%%20special%%25password@localhost:6432/pgbouncer?sslmode=disable

vvitad commented

hi, @originell! thanks for the reply
password contains _, yesterday I've created environment variable for the whole connection string and it worked

Environment="DATA_SOURCE_NAME=pgBouncer.connectionString=postgresql://pgbouncer:pgbouncer_password@host:port/pgbouncer?sslmode=disable"
ExecStart=....--${DATA_SOURCE_NAME} 

still struggling with changing timezone though. ts (timestamp) in logs is incorrect