docs/sources/datasources/postgres/troubleshooting/index.md
This document provides troubleshooting information for common errors you may encounter when using the PostgreSQL data source in Grafana.
The following errors occur when Grafana cannot establish or maintain a connection to PostgreSQL.
Error message: failed to connect to ... : connect: connection refused or dial tcp: connect: connection refused
Cause: Grafana cannot establish a network connection to the PostgreSQL server.
Solution:
5432).pg_hba.conf.Error message: "context deadline exceeded" or "i/o timeout"
Cause: The connection to PostgreSQL timed out before receiving a response.
Solution:
Error message: failed to connect to ... : hostname resolving error or lookup hostname: no such host
Cause: The hostname specified in the data source configuration cannot be resolved.
Solution:
The following errors occur when there are issues with authentication credentials or permissions.
Error message: failed to connect to ... : server error: FATAL: password authentication failed for user "username" (SQLSTATE 28P01)
Cause: The username or password is incorrect.
Solution:
Error message: ERROR: permission denied for table table_name (SQLSTATE 42501) or ERROR: permission denied for schema schema_name (SQLSTATE 42501)
Cause: The database user does not have permission to access the requested table or schema.
Solution:
Verify the user has SELECT permissions on the required tables.
Grant the necessary permissions:
GRANT USAGE ON SCHEMA schema_name TO grafanareader;
GRANT SELECT ON schema_name.table_name TO grafanareader;
Check that the user has access to the correct database.
Verify the search path includes the schema containing your tables.
Error message: failed to connect to ... : server error: FATAL: no pg_hba.conf entry for host "ip_address", user "username", database "database_name" (SQLSTATE 28000)
Cause: PostgreSQL is not configured to accept connections from the Grafana server.
Solution:
Edit the pg_hba.conf file on the PostgreSQL server.
Add an entry to allow connections from the Grafana server:
host database_name username grafana_ip/32 md5
Reload PostgreSQL configuration: SELECT pg_reload_conf();
If using SSL, ensure the correct authentication method is specified (for example, hostssl instead of host).
The following errors occur when there are issues with TLS configuration.
Error message: "x509: certificate signed by unknown authority" or "certificate verify failed"
Cause: Grafana cannot verify the TLS certificate presented by PostgreSQL.
Solution:
require, verify-ca, or verify-full).disable (not recommended for production).Error message: failed to connect to ... : server refused TLS connection or server does not support SSL
Cause: The PostgreSQL server is not configured for SSL connections, but the data source requires SSL.
Solution:
disable if SSL is not required.ssl = on in postgresql.conf.Error message: "TLS: failed to find any PEM data in certificate input" or "could not load client certificate"
Cause: The client certificate or key is invalid or incorrectly formatted.
Solution:
The following errors occur when there are issues with the database configuration.
Error message: failed to connect to ... : server error: FATAL: database "database_name" does not exist (SQLSTATE 3D000)
Cause: The specified database name is incorrect or the database doesn't exist.
Solution:
\l in psql or SELECT datname FROM pg_database;Error message: ERROR: relation "table_name" does not exist (SQLSTATE 42P01)
Cause: The specified table or view does not exist, or the user cannot access it.
Solution:
schema_name.table_name.SELECT permission on the table.SHOW search_path;The following errors occur when there are issues with SQL syntax or query execution.
Error message: ERROR: syntax error at or near "keyword" (SQLSTATE 42601)
Cause: The SQL query contains invalid syntax.
Solution:
"column_name".Error message: ERROR: column "column_name" does not exist (SQLSTATE 42703)
Cause: The specified column name is incorrect or doesn't exist in the table.
Solution:
"Column_Name" for case-sensitive names.\d table_name in psql.Error message: "no time column found" or time series visualization shows no data
Cause: The query result does not include a properly formatted time column.
Solution:
time that returns a timestamp or epoch value.SELECT created_at AS time.timestamp, timestamptz, or a numeric epoch value.ORDER BY time ASC.Error message: "macro '$__timeFilter' not found" or incorrect query results with macros
Cause: Grafana macros are not being properly expanded.
Solution:
$__timeFilter(time_column).The following issues relate to slow query execution or resource constraints.
Error message: "canceling statement due to statement timeout" or "query timeout"
Cause: The query took longer than the configured timeout.
Solution:
$__timeFilter macro to limit data to the dashboard time range.Error message: failed to connect to ... : server error: FATAL: too many connections for role "username" (SQLSTATE 53300) or connection pool exhausted
Cause: The maximum number of connections to PostgreSQL has been reached.
Solution:
max_connections in PostgreSQL's postgresql.conf if you have admin access.Cause: Queries take a long time to execute.
Solution:
$__timeFilter macro to limit the data scanned.EXPLAIN ANALYZE in PostgreSQL to identify query bottlenecks.The following errors occur when provisioning the data source via YAML.
Error message: "metric request error" or data source test fails after provisioning
Cause: The provisioning YAML file contains incorrect configuration.
Solution:
hostname:port.Example correct configuration:
datasources:
- name: Postgres
type: postgres
url: localhost:5432
user: grafana
secureJsonData:
password: 'Password!'
jsonData:
database: grafana
sslmode: 'disable'
The following issues don't produce specific error messages but are commonly encountered.
Cause: The query returns no data.
Solution:
$__timeFilter macro is using the correct time column.Cause: TimescaleDB-specific functions like time_bucket are not available in the query builder.
Solution:
timescaledb extension is created: CREATE EXTENSION IF NOT EXISTS timescaledb;Cause: The visualization doesn't show the most recent data.
Solution:
If you continue to experience issues after following this troubleshooting guide: