# PostgresSQL Metricbeat module, possible issue with database connections

**URL:** <https://discuss.elastic.co/t/postgressql-metricbeat-module-possible-issue-with-database-connections/223794>\
**Category:** Beats\
**Tags:** metricbeat\
**Created:** [March 16, 2020, 4:50pm UTC](https://discuss.elastic.co/t/postgressql-metricbeat-module-possible-issue-with-database-connections/223794 "2020-03-16T16:50:40Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![mxp7064](https://avatars.discourse-cdn.com/v4/letter/m/919ad9/32.png) [@mxp7064](https://discuss.elastic.co/u/mxp7064)\
**Post date:** [March 16, 2020, 4:50pm UTC](https://discuss.elastic.co/t/postgressql-metricbeat-module-possible-issue-with-database-connections/223794/1 "2020-03-16T16:50:40Z")

</div>

Hi, I started using PostgresSQL Metricbeat module on Kubernetes.  
I installed the latest version of Metricbeat via helm (elastic/metricbeat chart).  
It runs 3 metricbeat pods which show no errors and I can see the metrics in the generated kibana  
dashboard.  
I am running my postgres database as a service using a third party tool called KubeDB.  
This is my metricbeat configuration:

```
output.elasticsearch:
  hosts: ["elasticsearch-master:9200"]
setup.kibana.host: "kibana-kibana:5601"
setup.dashboards.enabled: true
setup.template.enabled: true
metricbeat.autodiscover:
  providers:
    - type: kubernetes
      templates:
        - condition:
            equals:
              kubernetes.service.name: "postgres"
        - condition:
            equals:
              kubernetes.namespace: dev
          config:
            - module: postgresql
              enabled: true
              metricsets:
                - activity
                - bgwriter
                - database
                - statement
              period: 30s
              hosts: ["postgres://postgres:5432?sslmode=disable"]
              username: xxxx
              password: xxxx

```

After metricbeat installs, when i perform 'SELECT \* FROM pg\_stat\_activity' query, I can see that there are about a 60-70 database connections from metricbeat in idle state. The number of connections also varies, sometimes it goes down but sometimes it has a propensity to increase until the database starts throwing 'FATAL: sorry, too many clients already' error. I tried to increase max\_connections to 700 in postgres.conf and after some time metricbeat creates enough connections to again cause the error.

This is the shortened list of connections (they repeat like this):

 ![Screenshot from 2020-03-16 17-39-09](https://us1.discourse-cdn.com/elastic/original/3X/e/8/e8e4621fe0519c0d8384790e73c52fa654e85527.png)

I was just wondering is this normal behavior or I am doing something wrong?  
If it is normal, can someone please explain the rationale behind the design. I would assume that it's better to reuse or at least timely close database connections.

Thank you in advance

---

<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 13, 2020, 4:50pm UTC](https://discuss.elastic.co/t/postgressql-metricbeat-module-possible-issue-with-database-connections/223794/2 "2020-04-13T16:50:40Z")

</div>

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