# Elastic fleet for postgresql fails to scrape pg\_stat\_statements

**URL:** <https://discuss.elastic.co/t/elastic-fleet-for-postgresql-fails-to-scrape-pg-stat-statements/356197>\
**Category:** Metrics\
**Tags:** fleet\
**Created:** [March 26, 2024, 3:39pm UTC](https://discuss.elastic.co/t/elastic-fleet-for-postgresql-fails-to-scrape-pg-stat-statements/356197 "2024-03-26T15:39:16Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![dier](https://avatars.discourse-cdn.com/v4/letter/d/3da27b/32.png) [@dier](https://discuss.elastic.co/u/dier)\
**Post date:** [March 26, 2024, 3:39pm UTC](https://discuss.elastic.co/t/elastic-fleet-for-postgresql-fails-to-scrape-pg-stat-statements/356197/1 "2024-03-26T15:39:16Z")

</div>

Hey,

I am currently setting up a elastic cloud installation with fleet agents. Our services are running in k8s as well as our agents. Also our databases are running in kubernetes.

Now I wanted to add the postgresql integration into my policy but I am experiencing issues when checking the dashboards. As far as I saw the agent is not able to scrape from `pg_stat_statements`. Here the exact error I get:

```auto
[elastic_agent.metricbeat][error] Error fetching data for metricset postgresql.statement: QueryStats: failed to query database: pq: relation "pg_stat_statements" does not exist

```

 ![image](https://us1.discourse-cdn.com/elastic/original/3X/0/5/053d0532911351f16d33f065d7ae674d967e714d.png)

This is very weird as I am able to query the table through Datagrip in the postrgres database. Also I added the preloaded library on startup. I am not sure why this is happening as it can't shouldn't be a permissions issue as I used the same user to query manually as well as in the agent and some of the data metric data are in elastic.

Any help is much appreciated.

Thanks!

---

<div class="post-metadata">

**Author:** ![Julia\_Bardi](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/julia_bardi/32/79463_2.png) [@Julia\_Bardi](https://discuss.elastic.co/u/Julia_Bardi)\
**Post date:** [March 26, 2024, 3:50pm UTC](https://discuss.elastic.co/t/elastic-fleet-for-postgresql-fails-to-scrape-pg-stat-statements/356197/2 "2024-03-26T15:50:42Z")

</div>

Hi D.R. welcome to the community!

I think the error doesn't seem like a permission issue on fleet/agent side, more like a problem with the postgresql setup.  
I'm not very knowledgeable on postgresql, but found similar issues reported here:

> <https://github.com/prometheus-community/postgres_exporter/issues/924>
>
> me too
> I have the same problem。
> 
> postgrepsql version: 12.0
> postgreps-exporte…r version: 0.14.0
> 
> i have aleady install pg\_stat\_statements extension;
> 
> 
> logs
> \-------------
> ts=2023-09-28T09:10:37.268Z caller=main.go:86 level=warn msg="Error loading config" err="Error opening config file "postgres\_exporter.yml": open postgres\_exporter.yml: no such file or directory"
> ts=2023-09-28T09:10:37.268Z caller=proc.go:250 msg="Excluded databases" databases=\[\]
> ts=2023-09-28T09:10:37.268Z caller=main.go:99 level=warn msg="The extended queries.yaml config is DEPRECATED" file=queries.yaml
> ts=2023-09-28T09:10:37.269Z caller=tls\_config.go:274 level=info msg="Listening on" address=\[::\]:9187
> ts=2023-09-28T09:10:37.269Z caller=tls\_config.go:277 level=info msg="TLS is disabled." http2=false address=\[::\]:9187
> ts=2023-09-28T09:10:43.986Z caller=server.go:74 level=info msg="Established new database connection" fingerprint=10.16.65.12:5432
> ts=2023-09-28T09:10:43.988Z caller=postgres\_exporter.go:613 level=info msg="Semantic version changed" server=10.16.65.12:5432 from=0.0.0 to=12.0.0
> ts=2023-09-28T09:10:44.026Z caller=namespace.go:236 level=info err="Error running query on database "192.168.2.11:5432": pg\_stat\_statements pq: relation "pg\_stat\_statements" does not exist"
> ts=2023-09-28T09:10:44.027Z caller=postgres\_exporter.go:682 level=error err="queryNamespaceMappings returned 1 errors"
> ts=2023-09-28T09:10:51.891Z caller=namespace.go:236 level=info err="Error running query on database "192.168.2.11:5432": pg\_stat\_statements pq: relation "pg\_stat\_statements" does not exist"
> ts=2023-09-28T09:10:51.911Z caller=postgres\_exporter.go:682 level=error err="queryNamespaceMappings returned 1 errors"

> <https://stackoverflow.com/questions/31021174/pg-stat-statements-enabled-but-the-table-does-not-exist>

---

<div class="post-metadata">

**Author:** ![dier](https://avatars.discourse-cdn.com/v4/letter/d/3da27b/32.png) [@dier](https://discuss.elastic.co/u/dier)\
**Post date:** [March 27, 2024, 8:54am UTC](https://discuss.elastic.co/t/elastic-fleet-for-postgresql-fails-to-scrape-pg-stat-statements/356197/3 "2024-03-27T08:54:44Z")

</div>

Thanks @Julia_Bardi , there was indeed an issue. I didn't create the postgresql extension in the correct database.

Thank you for your help!

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [April 24, 2024, 8:55am UTC](https://discuss.elastic.co/t/elastic-fleet-for-postgresql-fails-to-scrape-pg-stat-statements/356197/4 "2024-04-24T08:55:22Z")

</div>

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.
