Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to correctly specify the connection string #75

Open
vetalfw opened this issue May 10, 2022 · 7 comments
Open

How to correctly specify the connection string #75

vetalfw opened this issue May 10, 2022 · 7 comments

Comments

@vetalfw
Copy link

vetalfw commented May 10, 2022

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

@anwareset
Copy link

I got similar issue

@vuducmanh11
Copy link

+1 same error, looks like code is outdated

@RezaImany
Copy link

RezaImany commented Jan 17, 2023

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

@originell
Copy link

originell commented Nov 9, 2023

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
Copy link

vvitad commented Nov 30, 2023

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

@originell
Copy link

@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
Copy link

vvitad commented Dec 1, 2023

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

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

No branches or pull requests

6 participants