timescale / tobs

tobs - The Observability Stack for Kubernetes. Easy install of a full observability stack into a k8s cluster with Helm charts.
Apache License 2.0
561 stars 61 forks source link

postgres_exporter takes >5mins to generate metrics on large database #652

Closed arajkumar closed 1 year ago

arajkumar commented 1 year ago

What happened?

$title

Did you expect to see something different?

postgres_exporter /metrics page must return data quickly in few seconds.

How to reproduce it (as minimally and precisely as possible):

Run against large postgres with quite bit of child tables/hyper tables.

Environment

I've been running postgres/timescale for 2 weeks with >5000 hyper tables and quite a bit of data(1.2TiB).

insert tobs logs relevant to the issue here

Anything else we need to know?:

arajkumar commented 1 year ago

I will move this to upstream postgres_exporter once I find the root cause.

arajkumar commented 1 year ago

The query which lists database along with it's size takes the time.

SELECT pg_database.datname
        ,pg_database_size(pg_database.datname)
        FROM pg_database;
arajkumar commented 1 year ago

Looks like the large database is the culprit.

SELECT pg_database.datname
                ,pg_database_size(pg_database.datname)
                FROM pg_database;
  datname  | pg_database_size
-----------+------------------
 postgres  |    1284355875619
 template1 |         10265091
 template0 |          8602115

SELECT pg_database_size('postgres') takes a lot of time(~5mins) to complete. Probably we should have an option to disable db size population from the exporter?

arajkumar commented 1 year ago

I see that there is an option collector.database to disable it, but that doesn't seem to work!

arajkumar commented 1 year ago

--no-collector.database should fix the problem

arajkumar commented 1 year ago

@paulfantom May be we should consider bringing the change to cloud as well. CC: @cevian