# Metricbeat SQL Module : Unable to extract data from a custom query

**URL:** https://discuss.elastic.co/t/metricbeat-sql-module-unable-to-extract-data-from-a-custom-query/279360
**Category:** Beats
**Created:** [July 22, 2021, 9:03am UTC](https://discuss.elastic.co/t/metricbeat-sql-module-unable-to-extract-data-from-a-custom-query/279360 "2021-07-22T09:03:20Z")
**Posts on this page:** 8
**Page:** 1

<div class="post-metadata">

### Author: ![VinodKumarPotta](https://avatars.discourse-cdn.com/v4/letter/v/bbce88/32.png) [@VinodKumarPotta](https://discuss.elastic.co/u/VinodKumarPotta)
#### Post date: [July 22, 2021, 9:03am UTC](https://discuss.elastic.co/t/metricbeat-sql-module-unable-to-extract-data-from-a-custom-query/279360/1 "2021-07-22T09:03:20Z")

</div>

Hi Team,

Seek your expert advise on this.

I have recently enabled Metricbeat sql module to extract data from a custom query.  
I have followed the instructions given in sql.yml file ([SQL module | Metricbeat Reference [7.9] | Elastic](https://www.elastic.co/guide/en/beats/metricbeat/7.9/metricbeat-module-sql.html)) and hit below error.

Can you please kindly help on this asap?

````auto
Jul 21 16:56:56 <hostname> metricbeat[120547]: 2021-07-21T16:56:56.712+0800 INFO module/wrapper.go:266 Error fetching data for metricset sql.query: error opening connection: testing connection: pq: password authentication failed for user <db_user>```
````

---

<div class="post-metadata">

### Author: ![VinodKumarPotta](https://avatars.discourse-cdn.com/v4/letter/v/bbce88/32.png) [@VinodKumarPotta](https://discuss.elastic.co/u/VinodKumarPotta)
#### Post date: [July 23, 2021, 5:40am UTC](https://discuss.elastic.co/t/metricbeat-sql-module-unable-to-extract-data-from-a-custom-query/279360/2 "2021-07-23T05:40:41Z")

</div>

Hi Team, Please help to check and advise on the above reported issue asap? Thank you!

---

<div class="post-metadata">

### Author: ![stephenb](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/stephenb/32/40856_2.png) [@stephenb](https://discuss.elastic.co/u/stephenb)
#### Post date: [July 23, 2021, 5:59am UTC](https://discuss.elastic.co/t/metricbeat-sql-module-unable-to-extract-data-from-a-custom-query/279360/3 "2021-07-23T05:59:45Z")

</div>

Looks like a bad connection string / password  
What does your connection string look like?  
What kind of Database?  
Are you using 7.9?  
Why not a newer version?

---

<div class="post-metadata">

### Author: ![VinodKumarPotta](https://avatars.discourse-cdn.com/v4/letter/v/bbce88/32.png) [@VinodKumarPotta](https://discuss.elastic.co/u/VinodKumarPotta)
#### Post date: [July 23, 2021, 10:35am UTC](https://discuss.elastic.co/t/metricbeat-sql-module-unable-to-extract-data-from-a-custom-query/279360/4 "2021-07-23T10:35:22Z")

</div>

What kind of Database? Postgres  
Are you using 7.9? Yes  
Why not a newer version? I am sorry. This is organizational direction.  
Below are the list of strings I tried and all giving same error.

```auto
hosts: ["user=<<Username>> password=<<Password>> dbname='<<Hostname>>:<<Port>>/<<DBName>>' sslmode=disable"]

hosts: ["<<Username>>:<<Password>>@tcp(<<Hostname>>:<<Port>>)/<<DBName>>?sslmode=disable"]

hosts: ["postgres://<<Hostname>>:<<Port>>/<<DBName>>?sslmode=disable&user=<<Username>>&password=<<Password>>"]

hosts: ["user=<<Username>> password=<<Password>> dbname=postgres://<<Hostname>>:<<Port>>/<<DBName>> sslmode=disable"]

hosts: ["postgres://<<Username>>:<<Password>>@<<Hostname>>:<<Port>>/<<DBName>>?sslmode=disable"]

```

---

<div class="post-metadata">

### Author: ![stephenb](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/stephenb/32/40856_2.png) [@stephenb](https://discuss.elastic.co/u/stephenb)
#### Post date: [July 23, 2021, 3:34pm UTC](https://discuss.elastic.co/t/metricbeat-sql-module-unable-to-extract-data-from-a-custom-query/279360/5 "2021-07-23T15:34:48Z")

</div>

This worked for me

```auto
- module: sql
  metricsets:
    - query
  period: 10s
  hosts: ["postgres://myuser:mypassword@192.168.2.205:5432/mydb?sslmode=disable"]

  driver: "postgres"
  sql_query: "select now()"
  sql_response_format: table

```

I tried with 7.9.3

If your password has special characters perhaps that could be causing escape issues....

 ![Screen Shot 2021-07-23 at 8.34.02 AM](https://us1.discourse-cdn.com/elastic/original/3X/6/c/6cdd9f88b133b123606c95e303258bc64d6dedb9.jpeg)

---

<div class="post-metadata">

### Author: ![VinodKumarPotta](https://avatars.discourse-cdn.com/v4/letter/v/bbce88/32.png) [@VinodKumarPotta](https://discuss.elastic.co/u/VinodKumarPotta)
#### Post date: [July 26, 2021, 1:48am UTC](https://discuss.elastic.co/t/metricbeat-sql-module-unable-to-extract-data-from-a-custom-query/279360/6 "2021-07-26T01:48:00Z")

</div>

Hi Stephen,  
Noted with thanks.  
Yes. My password is combination of

1. One capital letter followed by three or more small letters
2. One special character
3. Four or more digits

Ex: **Abcd#2021**

How to use this kind of passwords in the string? Kindly advice.

---

<div class="post-metadata">

### Author: ![stephenb](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/stephenb/32/40856_2.png) [@stephenb](https://discuss.elastic.co/u/stephenb)
#### Post date: [July 26, 2021, 2:35am UTC](https://discuss.elastic.co/t/metricbeat-sql-module-unable-to-extract-data-from-a-custom-query/279360/7 "2021-07-26T02:35:45Z")

</div>

I am not saying that **is** the issue just **maybe** the issue... Maybe try a user with a simple password to see if you can connect.

If you can then that would help diagnose.

---

<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: [August 23, 2021, 2:35am UTC](https://discuss.elastic.co/t/metricbeat-sql-module-unable-to-extract-data-from-a-custom-query/279360/8 "2021-08-23T02:35:51Z")

</div>

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