prometheus-community / prometheus-community/postgres_exporter

No pg_hba for postgres_exporter user (solved in the end).

Open
#696 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Go
Stars
3.6k
Forks
835
Avg merge
2d 4h
Merged PRs (30d)
10

Description

What did you do?
Hi, I tried to install postgres_exporter for PostgreSQL versions >= 10

CREATE ROLE postgres_exporter;
GRANT pg_monitor to postgres_exporter;

I got my Postgresql metrics and it works just fine.

But when I checked /var/log/postgresql/postgresql-14-main.log I got FATAL: no pg_hba.conf entry for host "127.0.0.1", user "postgres_exporter" error

What did you expect to see?
To get my metrics without error on my postgresql logs.

Environment
my postgres_exporter.env file

DATA_SOURCE_NAME="postgresql://postgres_exporter@localhost:5432/?sslmode=disable"
  • System information:
uname info: Linux 5.15.0-46-generic x86_64
OS: GNU/Linux Ubuntu 22.04
  • postgres_exporter version:

postgres_exporter, version 0.11.1 (branch: HEAD, revision: b5fd2465646a09bb1c8dbd5c9c00b852da93927a)
build user: root@a2c981f603ff
build date: 20220818-20:58:17
go version: go1.18.5
platform: linux/amd64

  • postgres_exporter flags:

I use it with no flag but here is my systemd service for postgres_exporter

[Unit]
Description=postgres Exporter Version 0.11.1
After=network-online.target

[Service]
Type=simple
User=postgres_exporter
Group=postgres_exporter
WorkingDirectory=/opt/postgres_exporter
EnvironmentFile=/opt/postgres_exporter/postgres_exporter.env
ExecStart=/usr/local/bin/postgres_exporter

[Install]
WantedBy=multi-user.target
  • PostgreSQL version:

Postgresql: 14

  • Logs:
2022-10-02 13:57:08.329 UTC [3396623] postgres_exporter@postgres_exporter FATAL:  no pg_hba.conf entry for host "127.0.0.1", user "postgres_exporter", database "postgres_exporter", no encryption
2022-10-02 13:57:08.336 UTC [3396624] postgres_exporter@postgres_exporter FATAL:  no pg_hba.conf entry for host "127.0.0.1", user "postgres_exporter", database "postgres_exporter", no encryption

What did you see instead? Under which circumstances?
At the end I created a role with login access and it's own database and pg_hba, I had no error sense then. I think you could add it to your documentation.
or if this approach is wrong please tell me what should I do, thanks in advanced :)

sudo su - postgres
psql
GRANT pg_monitor to postgres_exporter;
CREATE ROLE postgres_exporter CREATEDB LOGIN;
create database postgres_exporter;
grant ALL privileges on database postgres_exporter to postgres_exporter;

edit sudo vim /etc/postgresql/14/main/pg_hba.conf and trust the postgres_exporter user on localhost:

host    postgres_exporter          postgres_exporter            127.0.0.1/32       trust

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Review the exporter setup guidance alongside the mentioned postgres_exporter.env and PostgreSQL /etc/postgresql/14/main/pg_hba.conf configuration. Verify which login, database, and localhost pg_hba settings are required, then document the correct setup and how to confirm that PostgreSQL logs no longer report the authentication error.

Written by the indexing model from the issue text.

Assessment

Tech stack
postgresql
Domain
databases, documentation
Issue type
Documentation
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.