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

ERRO[0141] Error opening connection to database connect: connection refused #497

Closed
derekgiri opened this issue Mar 8, 2021 · 4 comments

Comments

@derekgiri
Copy link

derekgiri commented Mar 8, 2021

Hi All,
I am facing a connection issue with version of exporter I have just set up

To test connections wit the exporter I issue

[root@prom pg_exp]# sudo -u postgres  DATA_SOURCE_NAME="postgresql://postgres_exporter:******@192.168.56.99:5432/postgres?sslmode=disable" ./postgres_exporter --web.listen-address=:9188 --log.level=debug

The logging errors throws

INFO[0223] Established new database connection to "192.168.56.99:5432".  source="postgres_exporter.go:983"
ERRO[0224] Error opening connection to database (postgresql://postgres_exporter:PASSWORD_REMOVED@192.168.56.99:5432/postgres?sslmode=disable): dial tcp 192.168.56.99:5432: connect: connection refused  source="postgres_exporter.go:1621"

The set up is pretty straight forward with a single server instance of Grafana + Prometheus and separate standalone PostgreSQL 12. I have used the latest release 0.9.0 / 2021-03-01

My systemd service file is pretty straight forward set up on the prometheus server as

[Unit]
Description=Prometheus exporter for Postgresql
Wants=network-online.target
After=network-online.target

[Service]

#User=postgres
#Group=postgres

WorkingDirectory=/opt/postgres_exporter/postgres_exporter-090
EnvironmentFile=/opt/postgres_exporter/postgres_exporter-090/postgres_exporter.env
ExecStart=/usr/local/bin/postgres_exporter --web.listen-address=:9187 --web.telemetry-path=/metrics
Restart=always

[Install]
WantedBy=multi-user.target

My environment file, pretty straightforward too

DATA_SOURCE_NAME="postgresql://postgres_exporter:********@192.168.56.99:5432/postgres?sslmode=disable"

PostgreSQL Database setup:
User postgres_exporter created as per README and I have allowed all connections over md5 on the PostgreSQL server.

[TEST]

  1. PostgreSQL client on prometheus to check connectivity to postgresql - OK
    psql -U postgres_exporter -d postgres -h 192.168.56.99 -p 5432

NB: Firewall disabled on prometheus and postgres server

Any thoughts and Ideas welcome.

Thanks

@SuperQ
Copy link
Contributor

SuperQ commented Mar 9, 2021

It looks like you're getting at TCP reset from 192.168.56.131. I'm guessing you have a leaking firewall rule on whatever that server is.

@SuperQ
Copy link
Contributor

SuperQ commented Apr 12, 2021

The best solution is to run the postgres_exporter against localhost. This avoids any networking or firewall problems.

For questions/help/support please use our community channels. There are more people available to potentially respond to your request and the whole community can benefit from the answers provided.

@SuperQ SuperQ closed this as completed Apr 12, 2021
@kmantresh
Copy link

Any Solution?

@brunolnetto
Copy link

I am looking for this error solution as well

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

5 participants
@SuperQ @brunolnetto @derekgiri @kmantresh and others