Can't connect to postgres_exporter using Grafana Alloy

I created an account on grafana.com to check out the hosted Grafana.

I have added a connection to a server named “Linux”. Steps I did:

  1. Created a token with the name “test-token”
  2. The command with the token I was given after creating the token, I ran on my server, it installed alloy (I clicked on Test Alloy connection and this worked)
  3. I followed the instructions to add the required snippets to the configuration file (/etc/alloy/config.alloy)
  4. I pressed “Test connection” and this worked, so my server is connected
  5. I installed the dashboard

So far, everything is working as expected, BUT, …

I have a postgresql database running on my server and I want to monitor this. So I added a new connection named “PostgreSQL”. Steps I did:

  1. Grafana alloy was already running on my server so I did not create a new token or ran the jnstall command again
  2. I copied the given snippet to my /etc/alloy/config.alloy-file (NOTE: this already had a snippet for the linux connection)
  3. I created a non-superuser database user named “postgres_exporter” (with password “password”) and granted the necessary permissions (as stated here) (connect to database postgres and pg_monitor)
  4. I edited the snippet I pasted in the configuration-file, especially in the beginning:
prometheus.exporter.postgres "integrations_postgres_exporter" {
    data_source_names = ["postgresql://postgres_exporter:password@localhost:5432/postgres?sslmode=disable"]
}

As you can see, I added the username and password to the snippet.
I have tested the user credentials. Through psql, I can login to the database with these credentials! (psql -U postgres_exporter postgres)

I have restarted alloy: sudo systemctl reload alloy

Now, when clicking “Test connection” on the setup page, I runs for like a minute and then gives me an error that the connection failed. I have set this up yesterday, today I tested it again but still no connection (and no data in my dashboard).

Do I have to open a port on my server for these data? Ports 22, 80, 443 and 9187 are open.

What could possibly be wrong?

Edit: to added, I checked the journald logs. No errors, no warnings, one notice (that alloy is running) and some info logs. When checking the ui (port 12345), I see the postgres_exporter listed and healthy.