Skip to content

postgres_exporter left more and more conntions in database and not released or reuse them #727

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

Closed
sheenzxx opened this issue Dec 1, 2022 · 8 comments · Fixed by #734
Closed

Comments

@sheenzxx
Copy link

sheenzxx commented Dec 1, 2022

when use postgres_exporter to monitor pg database,

postgres_exporter left more and more connections in database and not released or reuse them

1669889809(1)

then on other windows to request metrics

curl "http://localhost:9187/probe?auth_module=foo1&target=192.168.74.94:5433/pcauto"

query
select datid,pid,usename,query_start from pg_stat_activity where usename='exporter_monitor' order by query_start

can see that when request 1 time .1 more connection add and not released or reuse
1669889957(1)

@sheenzxx
Copy link
Author

sheenzxx commented Dec 2, 2022

I reslove this problem wiht add db.SetConnMaxLifetime(60 * time.Second)

@sheenzxx
Copy link
Author

sheenzxx commented Dec 2, 2022

if there any Perfect solution?

@hajdukda
Copy link

ok this one is super important to fix.

@kjbass
Copy link
Contributor

kjbass commented Dec 14, 2022

Yeah, another +1 for this being an important one to fix. Running the exporter caused number of connections to go up endlessly. @sheenzxx's solution seems like a valid one, but another option would be actually closing the connection after a probe finishes. Currently, cannot really use this in prod.

@kjbass
Copy link
Contributor

kjbass commented Dec 14, 2022

Tried my hand at writing a fix here: #734

@kazauwa
Copy link

kazauwa commented Feb 1, 2023

This bug can easily bring the production database down. This is what we saw yesterday after enabling postgres_exporter. We definitely need https://github.com/prometheus-community/postgres_exporter/pull/734 merged.
Screenshot 2023-02-01 at 12 22 38

@MichaelDBA
Copy link

MichaelDBA commented Feb 2, 2023

Doesn't the error message indicate its a configuration problem? --> error = empty dsn

So perhaps the connection is made nonetheless but unawares to the postgres_exporter so that's the reason its never closed or assumed to be active in the first place.

@kjbass
Copy link
Contributor

kjbass commented Feb 3, 2023

Doesn't the error message indicate its a configuration problem? --> error = empty dsn

So perhaps the connection is made nonetheless but unawares to the postgres_exporter so that's the reason its never closed or assumed to be active in the first place.

I'm pretty sure that's a separate issue. The error = empty dsn shows up regardless when you're using the multi-target exporter, but it's a bit of noise that does not affect things. When using the multi target exporter you do not set a DSN, since you are targeting multiple instances with the probes.

I think in general the multi target exporting could use some more love, but triaging the runaway connections is a good first step.

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 a pull request may close this issue.

5 participants