Getting db query error while running table query using postgres datasource: pq: password authentication failed for user {{username}}

Grafana version: v8.2.2
OS: ubuntu 18.04

Hi,
I am trying to provide tabular reports for my micro service by fetching data from postgres database. I have configured the datasource using default.yaml file as shown below:
//////////////////////////////////////////////
apiVersion: 1
datasources:

  • name: {{Service Name}}
    type: postgres
    url: {{db_hostname}}:5432
    password: {{db_password}}
    user: {{db_username}}
    database: {{db_name}}
    jsonData:
    sslmode: “disable”
    postgresVersion: 13
    ///////////////////////////////////////////////////
    Grafana is working perfectly in my machine. But it is not working as expected when I deploy it to my server.

In Server, the datasource test was giving success result as “Database Connection OK”
But I am not able to add table queries for the table panel. It is giving an error as “db query error: pq: password authentication failed for user {{db_username}}”. Getting same error while running queries from the explore option next to datasource test.

Searched online for some solution, but didn’t get any. Since I was new to grafana and postgres not able to identify the root cause also. Any help to arrive at a solution will be greatly appreciated.

Thanks a bunch in advance.

Are you able to access Postgres successfully from the server where Grafana is running? It’s very hard to diagnose without further info on your setup, but it makes sense to start with a sanity check with respect to access outside of Grafana. Based on what you’ve shared, my guess would be that the issue you’re experiencing isn’t related to Grafana itself.

1 Like

Thanks for the response @svetb . The problem was solved after reconfiguring the data source as mentioned below.

apiVersion: 1
deleteDatasources:
 - name: {{Datasource Name}}

datasources:
 - name: {{Datasource Name}}
   type: postgres
   url: {{db_hostname}}:5432
   database: {{db_name}}
   user: {{db_username}}
   secureJsonData:
     password: {{db_password}}

   jsonData:
     sslmode: 'disable'
     postgresVersion: 13