<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>PostgreSQL data source on Grafana Labs</title><link>https://grafana.com/docs/grafana/v13.1/datasources/postgres/</link><description>Recent content in PostgreSQL data source on Grafana Labs</description><generator>Hugo -- gohugo.io</generator><language>en</language><atom:link href="/docs/grafana/v13.1/datasources/postgres/index.xml" rel="self" type="application/rss+xml"/><item><title>Configure the PostgreSQL data source</title><link>https://grafana.com/docs/grafana/v13.1/datasources/postgres/configure/</link><pubDate>Tue, 23 Jun 2026 13:06:40 +0000</pubDate><guid>https://grafana.com/docs/grafana/v13.1/datasources/postgres/configure/</guid><content><![CDATA[&lt;h1 id=&#34;configure-the-postgresql-data-source&#34;&gt;Configure the PostgreSQL data source&lt;/h1&gt;
&lt;p&gt;This document explains how to configure the PostgreSQL data source and lists all configuration options. For general information on managing data sources, refer to 
    &lt;a href=&#34;/docs/grafana/v13.1/administration/data-source-management/&#34;&gt;Data source management&lt;/a&gt;.&lt;/p&gt;
&lt;h2 id=&#34;before-you-begin&#34;&gt;Before you begin&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;You need the &lt;code&gt;Organization administrator&lt;/code&gt; role to configure the data source. You can also &lt;a href=&#34;#provision-the-data-source&#34;&gt;configure it via YAML&lt;/a&gt; using Grafana provisioning or &lt;a href=&#34;#configure-with-terraform&#34;&gt;using Terraform&lt;/a&gt;.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Grafana includes a built-in PostgreSQL data source; no plugin installation is required.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Have your PostgreSQL security details ready (certificates and client keys, if using TLS/SSL).&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Note your PostgreSQL version; you’ll be prompted for it during configuration.&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;


&lt;div class=&#34;admonition admonition-note&#34;&gt;&lt;blockquote&gt;&lt;p class=&#34;title text-uppercase&#34;&gt;Note&lt;/p&gt;&lt;p&gt;When adding a data source, the database user you specify should have only &lt;code&gt;SELECT&lt;/code&gt; permissions on the relevant schemas and tables. Grafana does not validate the safety of queries, so users could run potentially harmful SQL (for example, &lt;code&gt;DROP TABLE&lt;/code&gt;). Create a dedicated PostgreSQL user with restricted permissions to limit risk.&lt;/p&gt;&lt;/blockquote&gt;&lt;/div&gt;

&lt;p&gt;Example:&lt;/p&gt;

&lt;div class=&#34;code-snippet &#34;&gt;&lt;div class=&#34;lang-toolbar&#34;&gt;
    &lt;span class=&#34;lang-toolbar__item lang-toolbar__item-active&#34;&gt;SQL&lt;/span&gt;
    &lt;span class=&#34;code-clipboard&#34;&gt;
      &lt;button x-data=&#34;app_code_snippet()&#34; x-init=&#34;init()&#34; @click=&#34;copy()&#34;&gt;
        &lt;img class=&#34;code-clipboard__icon&#34; src=&#34;/media/images/icons/icon-copy-small-2.svg&#34; alt=&#34;Copy code to clipboard&#34; width=&#34;14&#34; height=&#34;13&#34;&gt;
        &lt;span&gt;Copy&lt;/span&gt;
      &lt;/button&gt;
    &lt;/span&gt;
    &lt;div class=&#34;lang-toolbar__border&#34;&gt;&lt;/div&gt;
  &lt;/div&gt;&lt;div class=&#34;code-snippet &#34;&gt;
    &lt;pre data-expanded=&#34;false&#34;&gt;&lt;code class=&#34;language-sql&#34;&gt;CREATE USER grafanareader WITH PASSWORD &amp;#39;password&amp;#39;;
GRANT USAGE ON SCHEMA schema TO grafanareader;
GRANT SELECT ON schema.table TO grafanareader;&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;Replace &lt;code&gt;schema&lt;/code&gt; and &lt;code&gt;table&lt;/code&gt; with your schema and table names.&lt;/p&gt;
&lt;h2 id=&#34;add-the-postgresql-data-source&#34;&gt;Add the PostgreSQL data source&lt;/h2&gt;
&lt;p&gt;Complete the following steps to set up a new PostgreSQL data source:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;Click &lt;strong&gt;Connections&lt;/strong&gt; in the left-side menu.&lt;/li&gt;
&lt;li&gt;Click &lt;strong&gt;Add new connection&lt;/strong&gt;.&lt;/li&gt;
&lt;li&gt;Type &lt;code&gt;PostgreSQL&lt;/code&gt; in the search bar.&lt;/li&gt;
&lt;li&gt;Select the &lt;strong&gt;PostgreSQL data source&lt;/strong&gt;.&lt;/li&gt;
&lt;li&gt;Click &lt;strong&gt;Add new data source&lt;/strong&gt; in the upper right.&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;You are taken to the &lt;strong&gt;Settings&lt;/strong&gt; tab where you will configure the data source.&lt;/p&gt;
&lt;h2 id=&#34;postgresql-configuration-options&#34;&gt;PostgreSQL configuration options&lt;/h2&gt;
&lt;p&gt;Following is a list of PostgreSQL configuration options:&lt;/p&gt;
&lt;section class=&#34;expand-table-wrapper&#34;&gt;&lt;div class=&#34;button-div&#34;&gt;
      &lt;button class=&#34;expand-table-btn&#34;&gt;Expand table&lt;/button&gt;
    &lt;/div&gt;&lt;div class=&#34;responsive-table-wrapper&#34;&gt;
    &lt;table&gt;
      &lt;thead&gt;
          &lt;tr&gt;
              &lt;th&gt;Setting&lt;/th&gt;
              &lt;th&gt;Description&lt;/th&gt;
          &lt;/tr&gt;
      &lt;/thead&gt;
      &lt;tbody&gt;
          &lt;tr&gt;
              &lt;td&gt;Name&lt;/td&gt;
              &lt;td&gt;Sets the name you use to refer to the data source in panels and queries. Examples: &lt;code&gt;PostgreSQL-DB-1&lt;/code&gt;.&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;Default&lt;/td&gt;
              &lt;td&gt;Toggle to set this specific PostgreSQL data source as the default pre-selected data source in panels and visualizations.&lt;/td&gt;
          &lt;/tr&gt;
      &lt;/tbody&gt;
    &lt;/table&gt;
  &lt;/div&gt;
&lt;/section&gt;&lt;p&gt;&lt;strong&gt;Connection section:&lt;/strong&gt;&lt;/p&gt;


&lt;div class=&#34;admonition admonition-note&#34;&gt;&lt;blockquote&gt;&lt;p class=&#34;title text-uppercase&#34;&gt;Note&lt;/p&gt;&lt;p&gt;&lt;strong&gt;Grafana Cloud users:&lt;/strong&gt; Grafana Cloud can&amp;rsquo;t reach databases on &lt;code&gt;localhost&lt;/code&gt;, &lt;code&gt;127.0.0.1&lt;/code&gt;, or private IP ranges (&lt;code&gt;10.x&lt;/code&gt;, &lt;code&gt;172.16.x&lt;/code&gt;, &lt;code&gt;192.168.x&lt;/code&gt;) directly. If your PostgreSQL instance isn&amp;rsquo;t publicly accessible, you must set up &lt;a href=&#34;/docs/grafana-cloud/connect-externally-hosted/private-data-source-connect/&#34;&gt;Private data source connect (PDC)&lt;/a&gt; to establish a secure tunnel between Grafana Cloud and your private network. If you experience intermittent connection drops with the Docker-based PDC agent, try switching to the binary-based agent instead.&lt;/p&gt;
&lt;p&gt;If your database is publicly accessible but protected by a firewall, you must allowlist the Grafana Cloud outbound IP addresses. Grafana Cloud doesn&amp;rsquo;t provide per-stack static IP addresses—only service-level IP ranges. For the current list of outbound IP addresses, refer to &lt;a href=&#34;/docs/grafana-cloud/connect-externally-hosted/allow-grafana-cloud-ips/&#34;&gt;Allow Grafana Cloud IP addresses in a firewall&lt;/a&gt;.&lt;/p&gt;&lt;/blockquote&gt;&lt;/div&gt;

&lt;section class=&#34;expand-table-wrapper&#34;&gt;&lt;div class=&#34;button-div&#34;&gt;
      &lt;button class=&#34;expand-table-btn&#34;&gt;Expand table&lt;/button&gt;
    &lt;/div&gt;&lt;div class=&#34;responsive-table-wrapper&#34;&gt;
    &lt;table&gt;
      &lt;thead&gt;
          &lt;tr&gt;
              &lt;th&gt;Setting&lt;/th&gt;
              &lt;th&gt;Description&lt;/th&gt;
          &lt;/tr&gt;
      &lt;/thead&gt;
      &lt;tbody&gt;
          &lt;tr&gt;
              &lt;td&gt;Host URL&lt;/td&gt;
              &lt;td&gt;The IP address/hostname and optional port of your PostgreSQL instance. The default PostgreSQL port is &lt;code&gt;5432&lt;/code&gt;. For IPv6 addresses, use the format &lt;code&gt;[::1]:5432&lt;/code&gt;. To connect through a Unix socket, enter the socket directory path (for example, &lt;code&gt;/var/run/postgresql&lt;/code&gt;).&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;Database name&lt;/td&gt;
              &lt;td&gt;The name of your PostgreSQL database. This database is used as the default for queries in the 
    &lt;a href=&#34;/docs/grafana/v13.1/datasources/postgres/query-editor/&#34;&gt;query editor&lt;/a&gt;.&lt;/td&gt;
          &lt;/tr&gt;
      &lt;/tbody&gt;
    &lt;/table&gt;
  &lt;/div&gt;
&lt;/section&gt;&lt;p&gt;&lt;strong&gt;Authentication section:&lt;/strong&gt;&lt;/p&gt;
&lt;section class=&#34;expand-table-wrapper&#34;&gt;&lt;div class=&#34;button-div&#34;&gt;
      &lt;button class=&#34;expand-table-btn&#34;&gt;Expand table&lt;/button&gt;
    &lt;/div&gt;&lt;div class=&#34;responsive-table-wrapper&#34;&gt;
    &lt;table&gt;
      &lt;thead&gt;
          &lt;tr&gt;
              &lt;th&gt;Setting&lt;/th&gt;
              &lt;th&gt;Description&lt;/th&gt;
          &lt;/tr&gt;
      &lt;/thead&gt;
      &lt;tbody&gt;
          &lt;tr&gt;
              &lt;td&gt;Username&lt;/td&gt;
              &lt;td&gt;Enter the username used to connect to your PostgreSQL database.&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;Password&lt;/td&gt;
              &lt;td&gt;Enter the password used to connect to the PostgreSQL database. This field is optional. If left empty, the PostgreSQL client driver resolves the password using the standard &lt;a href=&#34;https://www.postgresql.org/docs/current/static/libpq-pgpass.html&#34; target=&#34;_blank&#34; rel=&#34;noopener noreferrer&#34;&gt;PostgreSQL password file&lt;/a&gt; (&lt;code&gt;.pgpass&lt;/code&gt;). To use a non-default password file location, set the &lt;code&gt;PGPASSFILE&lt;/code&gt; environment variable in the Grafana server process.&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;TLS/SSL Mode&lt;/td&gt;
              &lt;td&gt;Determines whether and how a secure TLS/SSL connection is negotiated with the server. Refer to the &lt;a href=&#34;#tlsssl-mode-reference&#34;&gt;TLS/SSL mode reference&lt;/a&gt; for guidance on each mode. When set to &lt;code&gt;disable&lt;/code&gt;, the TLS/SSL Method and Auth Details options aren&amp;rsquo;t visible.&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;TLS/SSL Method&lt;/td&gt;
              &lt;td&gt;Determines how TLS/SSL certificates are configured.&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;- File system path&lt;/td&gt;
              &lt;td&gt;This option allows you to configure certificates by specifying paths to existing certificates on the local file system where Grafana is running. Ensure this file is readable by the user executing the Grafana process.&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;- Certificate content&lt;/td&gt;
              &lt;td&gt;This option allows you to configure certificates by specifying their content. The content is stored and encrypted in the Grafana database. When connecting to the database, the certificates are saved as files, on the local filesystem, in the Grafana data path.&lt;/td&gt;
          &lt;/tr&gt;
      &lt;/tbody&gt;
    &lt;/table&gt;
  &lt;/div&gt;
&lt;/section&gt;&lt;h3 id=&#34;tlsssl-mode-reference&#34;&gt;TLS/SSL mode reference&lt;/h3&gt;
&lt;p&gt;Choose the TLS/SSL mode based on your security requirements and where your database is hosted:&lt;/p&gt;
&lt;section class=&#34;expand-table-wrapper&#34;&gt;&lt;div class=&#34;button-div&#34;&gt;
      &lt;button class=&#34;expand-table-btn&#34;&gt;Expand table&lt;/button&gt;
    &lt;/div&gt;&lt;div class=&#34;responsive-table-wrapper&#34;&gt;
    &lt;table&gt;
      &lt;thead&gt;
          &lt;tr&gt;
              &lt;th&gt;Mode&lt;/th&gt;
              &lt;th&gt;Encryption&lt;/th&gt;
              &lt;th&gt;Server identity verified&lt;/th&gt;
              &lt;th&gt;When to use&lt;/th&gt;
          &lt;/tr&gt;
      &lt;/thead&gt;
      &lt;tbody&gt;
          &lt;tr&gt;
              &lt;td&gt;&lt;code&gt;disable&lt;/code&gt;&lt;/td&gt;
              &lt;td&gt;No&lt;/td&gt;
              &lt;td&gt;No&lt;/td&gt;
              &lt;td&gt;Local development or trusted private networks only. Don&amp;rsquo;t use in production.&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;&lt;code&gt;require&lt;/code&gt;&lt;/td&gt;
              &lt;td&gt;Yes&lt;/td&gt;
              &lt;td&gt;No&lt;/td&gt;
              &lt;td&gt;&lt;strong&gt;Recommended minimum for cloud-hosted databases&lt;/strong&gt; such as Amazon RDS, Azure Database for PostgreSQL, and Google Cloud SQL. Encrypts the connection but doesn&amp;rsquo;t verify the server&amp;rsquo;s certificate.&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;&lt;code&gt;verify-ca&lt;/code&gt;&lt;/td&gt;
              &lt;td&gt;Yes&lt;/td&gt;
              &lt;td&gt;CA only&lt;/td&gt;
              &lt;td&gt;Use when you need to confirm the server certificate is signed by a trusted CA but don&amp;rsquo;t need to verify the hostname.&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;&lt;code&gt;verify-full&lt;/code&gt;&lt;/td&gt;
              &lt;td&gt;Yes&lt;/td&gt;
              &lt;td&gt;CA &#43; hostname&lt;/td&gt;
              &lt;td&gt;&lt;strong&gt;Most secure option.&lt;/strong&gt; Verifies both the CA and that the server hostname matches the certificate. Recommended for production when you control the certificates.&lt;/td&gt;
          &lt;/tr&gt;
      &lt;/tbody&gt;
    &lt;/table&gt;
  &lt;/div&gt;
&lt;/section&gt;

&lt;div class=&#34;admonition admonition-note&#34;&gt;&lt;blockquote&gt;&lt;p class=&#34;title text-uppercase&#34;&gt;Note&lt;/p&gt;&lt;p&gt;Most cloud-hosted PostgreSQL services (Amazon RDS, Azure Database for PostgreSQL, Google Cloud SQL) require at minimum &lt;code&gt;require&lt;/code&gt; mode. If you leave TLS/SSL Mode set to &lt;code&gt;disable&lt;/code&gt;, the connection may be rejected by the server. Check your cloud provider&amp;rsquo;s documentation for the recommended &lt;code&gt;sslmode&lt;/code&gt; setting.&lt;/p&gt;&lt;/blockquote&gt;&lt;/div&gt;

&lt;p&gt;&lt;strong&gt;TLS/SSL Auth Details:&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;If you select the TLS/SSL Mode options &lt;strong&gt;require&lt;/strong&gt;, &lt;strong&gt;verify-ca&lt;/strong&gt; or &lt;strong&gt;verify-full&lt;/strong&gt; and &lt;strong&gt;file system path&lt;/strong&gt; the following are required:&lt;/p&gt;
&lt;section class=&#34;expand-table-wrapper&#34;&gt;&lt;div class=&#34;button-div&#34;&gt;
      &lt;button class=&#34;expand-table-btn&#34;&gt;Expand table&lt;/button&gt;
    &lt;/div&gt;&lt;div class=&#34;responsive-table-wrapper&#34;&gt;
    &lt;table&gt;
      &lt;thead&gt;
          &lt;tr&gt;
              &lt;th&gt;Setting&lt;/th&gt;
              &lt;th&gt;Description&lt;/th&gt;
          &lt;/tr&gt;
      &lt;/thead&gt;
      &lt;tbody&gt;
          &lt;tr&gt;
              &lt;td&gt;TLS/SSL Root Certificate&lt;/td&gt;
              &lt;td&gt;Specify the path to the root certificate file.&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;TLS/SSL Client Certificate&lt;/td&gt;
              &lt;td&gt;Specify the path to the client certificate and ensure the file is accessible to the user running the Grafana process.&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;TLS/SSL Client Key&lt;/td&gt;
              &lt;td&gt;Specify the path to the client key file and ensure the file is accessible to the user running the Grafana process.&lt;/td&gt;
          &lt;/tr&gt;
      &lt;/tbody&gt;
    &lt;/table&gt;
  &lt;/div&gt;
&lt;/section&gt;&lt;p&gt;If you select the TLS/SSL Mode option &lt;strong&gt;require&lt;/strong&gt; and TLS/SSL Method certificate content the following are required:&lt;/p&gt;
&lt;section class=&#34;expand-table-wrapper&#34;&gt;&lt;div class=&#34;button-div&#34;&gt;
      &lt;button class=&#34;expand-table-btn&#34;&gt;Expand table&lt;/button&gt;
    &lt;/div&gt;&lt;div class=&#34;responsive-table-wrapper&#34;&gt;
    &lt;table&gt;
      &lt;thead&gt;
          &lt;tr&gt;
              &lt;th&gt;Setting&lt;/th&gt;
              &lt;th&gt;Description&lt;/th&gt;
          &lt;/tr&gt;
      &lt;/thead&gt;
      &lt;tbody&gt;
          &lt;tr&gt;
              &lt;td&gt;TLS/SSL Client Certificate&lt;/td&gt;
              &lt;td&gt;Provide the client certificate.&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;TLS/SSL Client Key&lt;/td&gt;
              &lt;td&gt;Provide the client key.&lt;/td&gt;
          &lt;/tr&gt;
      &lt;/tbody&gt;
    &lt;/table&gt;
  &lt;/div&gt;
&lt;/section&gt;&lt;p&gt;If you select the TLS/SSL Mode options &lt;strong&gt;verify-ca&lt;/strong&gt; or &lt;strong&gt;verify-full&lt;/strong&gt; with the TLS/SSL Method certificate content the following are required:&lt;/p&gt;
&lt;section class=&#34;expand-table-wrapper&#34;&gt;&lt;div class=&#34;button-div&#34;&gt;
      &lt;button class=&#34;expand-table-btn&#34;&gt;Expand table&lt;/button&gt;
    &lt;/div&gt;&lt;div class=&#34;responsive-table-wrapper&#34;&gt;
    &lt;table&gt;
      &lt;thead&gt;
          &lt;tr&gt;
              &lt;th&gt;Setting&lt;/th&gt;
              &lt;th&gt;Description&lt;/th&gt;
          &lt;/tr&gt;
      &lt;/thead&gt;
      &lt;tbody&gt;
          &lt;tr&gt;
              &lt;td&gt;TLS/SSL Client Certificate&lt;/td&gt;
              &lt;td&gt;Provide the client certificate.&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;TLS/SSL Root Certificate&lt;/td&gt;
              &lt;td&gt;Provide the root certificate.&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;TLS/SSL Client Key&lt;/td&gt;
              &lt;td&gt;Provide the client key.&lt;/td&gt;
          &lt;/tr&gt;
      &lt;/tbody&gt;
    &lt;/table&gt;
  &lt;/div&gt;
&lt;/section&gt;&lt;p&gt;&lt;strong&gt;PostgreSQL Options:&lt;/strong&gt;&lt;/p&gt;
&lt;section class=&#34;expand-table-wrapper&#34;&gt;&lt;div class=&#34;button-div&#34;&gt;
      &lt;button class=&#34;expand-table-btn&#34;&gt;Expand table&lt;/button&gt;
    &lt;/div&gt;&lt;div class=&#34;responsive-table-wrapper&#34;&gt;
    &lt;table&gt;
      &lt;thead&gt;
          &lt;tr&gt;
              &lt;th&gt;Setting&lt;/th&gt;
              &lt;th&gt;Description&lt;/th&gt;
          &lt;/tr&gt;
      &lt;/thead&gt;
      &lt;tbody&gt;
          &lt;tr&gt;
              &lt;td&gt;Version&lt;/td&gt;
              &lt;td&gt;The PostgreSQL server version. Determines which functions are available in the query builder. The default is 9.3. When you save the data source, Grafana auto-detects the server version and updates this field if it can connect successfully.&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;Min time interval&lt;/td&gt;
              &lt;td&gt;Defines a lower limit for the auto group by time interval. Grafana recommends aligning this setting with the data write frequency. For example, set it to &lt;code&gt;1m&lt;/code&gt; if your data is written every minute. Refer to &lt;a href=&#34;#min-time-interval&#34;&gt;Min time interval&lt;/a&gt; for format examples.&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;TimescaleDB&lt;/td&gt;
              &lt;td&gt;A time-series database built as a PostgreSQL extension. When enabled, Grafana uses &lt;code&gt;time_bucket&lt;/code&gt; in the &lt;code&gt;$__timeGroup&lt;/code&gt; macro and displays TimescaleDB-specific aggregate functions in the query builder. Grafana auto-detects TimescaleDB on save if your server is version 9.6 or later and the extension is installed. For more information, refer to &lt;a href=&#34;https://docs.timescale.com/timescaledb/latest/tutorials/grafana/grafana-timescalecloud/#connect-timescaledb-and-grafana&#34; target=&#34;_blank&#34; rel=&#34;noopener noreferrer&#34;&gt;TimescaleDB documentation&lt;/a&gt;.&lt;/td&gt;
          &lt;/tr&gt;
      &lt;/tbody&gt;
    &lt;/table&gt;
  &lt;/div&gt;
&lt;/section&gt;&lt;p&gt;&lt;strong&gt;Connection limits:&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;These settings control how Grafana manages connections to your PostgreSQL server. Tune these values if you share the database with other applications or use connection pooling software such as PgBouncer.&lt;/p&gt;
&lt;section class=&#34;expand-table-wrapper&#34;&gt;&lt;div class=&#34;button-div&#34;&gt;
      &lt;button class=&#34;expand-table-btn&#34;&gt;Expand table&lt;/button&gt;
    &lt;/div&gt;&lt;div class=&#34;responsive-table-wrapper&#34;&gt;
    &lt;table&gt;
      &lt;thead&gt;
          &lt;tr&gt;
              &lt;th&gt;Setting&lt;/th&gt;
              &lt;th&gt;Description&lt;/th&gt;
          &lt;/tr&gt;
      &lt;/thead&gt;
      &lt;tbody&gt;
          &lt;tr&gt;
              &lt;td&gt;Max open&lt;/td&gt;
              &lt;td&gt;The maximum number of open connections to the database. The default is &lt;code&gt;100&lt;/code&gt;. Reduce this if your PostgreSQL server has a low &lt;code&gt;max_connections&lt;/code&gt; limit or if multiple Grafana instances connect to the same database.&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;Auto max idle&lt;/td&gt;
              &lt;td&gt;Toggle to set the maximum number of idle connections to the number of maximum open connections. This setting is toggled on by default.&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;Max idle&lt;/td&gt;
              &lt;td&gt;The maximum number of connections in the idle connection pool. The default is &lt;code&gt;100&lt;/code&gt;. When using PgBouncer or similar connection pooling software, consider lowering this to avoid holding unnecessary connections.&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;Max lifetime&lt;/td&gt;
              &lt;td&gt;The maximum amount of time in seconds a connection may be reused. The default is &lt;code&gt;14400&lt;/code&gt; (4 hours). Set a lower value if your network or security policy requires periodic reconnection.&lt;/td&gt;
          &lt;/tr&gt;
      &lt;/tbody&gt;
    &lt;/table&gt;
  &lt;/div&gt;
&lt;/section&gt;&lt;p&gt;&lt;strong&gt;Private data source connect:&lt;/strong&gt;&lt;/p&gt;
&lt;section class=&#34;expand-table-wrapper&#34;&gt;&lt;div class=&#34;button-div&#34;&gt;
      &lt;button class=&#34;expand-table-btn&#34;&gt;Expand table&lt;/button&gt;
    &lt;/div&gt;&lt;div class=&#34;responsive-table-wrapper&#34;&gt;
    &lt;table&gt;
      &lt;thead&gt;
          &lt;tr&gt;
              &lt;th&gt;Setting&lt;/th&gt;
              &lt;th&gt;Description&lt;/th&gt;
          &lt;/tr&gt;
      &lt;/thead&gt;
      &lt;tbody&gt;
          &lt;tr&gt;
              &lt;td&gt;Private data source connect&lt;/td&gt;
              &lt;td&gt;&lt;em&gt;Only for Grafana Cloud users.&lt;/em&gt; Private data source connect, or PDC, allows you to establish a private, secured connection between a Grafana Cloud instance, or stack, and data sources secured within a private network. Click the drop-down to locate the URL for PDC. For more information, refer to &lt;a href=&#34;/docs/grafana-cloud/connect-externally-hosted/private-data-source-connect/&#34;&gt;Private data source connect (PDC)&lt;/a&gt;.&lt;/td&gt;
          &lt;/tr&gt;
      &lt;/tbody&gt;
    &lt;/table&gt;
  &lt;/div&gt;
&lt;/section&gt;&lt;p&gt;Click &lt;strong&gt;Manage private data source connect&lt;/strong&gt; to be taken to your PDC connection page, where you’ll find your PDC configuration details.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Secure SOCKS proxy:&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;If your Grafana instance has the Secure SOCKS proxy feature enabled, a toggle appears in the data source settings. When enabled, Grafana routes PostgreSQL connections through a SOCKS proxy for secure access to databases in private networks. For more information, refer to 
    &lt;a href=&#34;/docs/grafana/v13.1/setup-grafana/configure-grafana/proxy/&#34;&gt;Configure a Secure SOCKS5 proxy&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;After you have added your PostgreSQL connection settings, click &lt;strong&gt;Save &amp;amp; test&lt;/strong&gt; to test and save the data source connection.&lt;/p&gt;
&lt;h3 id=&#34;min-time-interval&#34;&gt;Min time interval&lt;/h3&gt;
&lt;p&gt;The &lt;strong&gt;Min time interval&lt;/strong&gt; setting defines a lower limit for the 
    &lt;a href=&#34;/docs/grafana/v13.1/dashboards/variables/add-template-variables/#__interval&#34;&gt;&lt;code&gt;$__interval&lt;/code&gt;&lt;/a&gt; and 
    &lt;a href=&#34;/docs/grafana/v13.1/dashboards/variables/add-template-variables/#__interval_ms&#34;&gt;&lt;code&gt;$__interval_ms&lt;/code&gt;&lt;/a&gt; variables.&lt;/p&gt;
&lt;p&gt;This option can also be configured or overridden in the dashboard panel under the data source settings.&lt;/p&gt;
&lt;p&gt;This value must be formatted as a number followed by a valid time identifier:&lt;/p&gt;
&lt;section class=&#34;expand-table-wrapper&#34;&gt;&lt;div class=&#34;button-div&#34;&gt;
      &lt;button class=&#34;expand-table-btn&#34;&gt;Expand table&lt;/button&gt;
    &lt;/div&gt;&lt;div class=&#34;responsive-table-wrapper&#34;&gt;
    &lt;table&gt;
      &lt;thead&gt;
          &lt;tr&gt;
              &lt;th&gt;Identifier&lt;/th&gt;
              &lt;th&gt;Description&lt;/th&gt;
          &lt;/tr&gt;
      &lt;/thead&gt;
      &lt;tbody&gt;
          &lt;tr&gt;
              &lt;td&gt;&lt;code&gt;y&lt;/code&gt;&lt;/td&gt;
              &lt;td&gt;year&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;&lt;code&gt;M&lt;/code&gt;&lt;/td&gt;
              &lt;td&gt;month&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;&lt;code&gt;w&lt;/code&gt;&lt;/td&gt;
              &lt;td&gt;week&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;&lt;code&gt;d&lt;/code&gt;&lt;/td&gt;
              &lt;td&gt;day&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;&lt;code&gt;h&lt;/code&gt;&lt;/td&gt;
              &lt;td&gt;hour&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;&lt;code&gt;m&lt;/code&gt;&lt;/td&gt;
              &lt;td&gt;minute&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;&lt;code&gt;s&lt;/code&gt;&lt;/td&gt;
              &lt;td&gt;second&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;&lt;code&gt;ms&lt;/code&gt;&lt;/td&gt;
              &lt;td&gt;millisecond&lt;/td&gt;
          &lt;/tr&gt;
      &lt;/tbody&gt;
    &lt;/table&gt;
  &lt;/div&gt;
&lt;/section&gt;&lt;h2 id=&#34;provision-the-data-source&#34;&gt;Provision the data source&lt;/h2&gt;
&lt;p&gt;You can define and configure the data source in YAML files with 
    &lt;a href=&#34;/docs/grafana/v13.1/administration/provisioning/#data-sources&#34;&gt;provisioning&lt;/a&gt;. For more information about provisioning and available configuration options, refer to 
    &lt;a href=&#34;/docs/grafana/v13.1/administration/provisioning/#datasources&#34;&gt;Provision Grafana&lt;/a&gt;.&lt;/p&gt;
&lt;h3 id=&#34;basic-provisioning-example&#34;&gt;Basic provisioning example&lt;/h3&gt;
&lt;p&gt;The following example provisions a PostgreSQL data source with password authentication and SSL disabled:&lt;/p&gt;

&lt;div class=&#34;code-snippet &#34;&gt;&lt;div class=&#34;lang-toolbar&#34;&gt;
    &lt;span class=&#34;lang-toolbar__item lang-toolbar__item-active&#34;&gt;YAML&lt;/span&gt;
    &lt;span class=&#34;code-clipboard&#34;&gt;
      &lt;button x-data=&#34;app_code_snippet()&#34; x-init=&#34;init()&#34; @click=&#34;copy()&#34;&gt;
        &lt;img class=&#34;code-clipboard__icon&#34; src=&#34;/media/images/icons/icon-copy-small-2.svg&#34; alt=&#34;Copy code to clipboard&#34; width=&#34;14&#34; height=&#34;13&#34;&gt;
        &lt;span&gt;Copy&lt;/span&gt;
      &lt;/button&gt;
    &lt;/span&gt;
    &lt;div class=&#34;lang-toolbar__border&#34;&gt;&lt;/div&gt;
  &lt;/div&gt;&lt;div class=&#34;code-snippet &#34;&gt;
    &lt;pre data-expanded=&#34;false&#34;&gt;&lt;code class=&#34;language-yaml&#34;&gt;apiVersion: 1

datasources:
  - name: Postgres
    type: postgres
    url: localhost:5432
    user: grafana
    secureJsonData:
      password: &amp;#39;Password!&amp;#39;
    jsonData:
      database: grafana
      sslmode: &amp;#39;disable&amp;#39; # disable/require/verify-ca/verify-full
      maxOpenConns: 100
      maxIdleConns: 100
      maxIdleConnsAuto: true
      connMaxLifetime: 14400
      postgresVersion: 903 # 903=9.3, 904=9.4, 905=9.5, 906=9.6, 1000=10
      timescaledb: false&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;h3 id=&#34;provisioning-with-tls&#34;&gt;Provisioning with TLS&lt;/h3&gt;
&lt;p&gt;The following example provisions a PostgreSQL data source with &lt;code&gt;verify-full&lt;/code&gt; TLS mode using file system paths for certificates:&lt;/p&gt;

&lt;div class=&#34;code-snippet &#34;&gt;&lt;div class=&#34;lang-toolbar&#34;&gt;
    &lt;span class=&#34;lang-toolbar__item lang-toolbar__item-active&#34;&gt;YAML&lt;/span&gt;
    &lt;span class=&#34;code-clipboard&#34;&gt;
      &lt;button x-data=&#34;app_code_snippet()&#34; x-init=&#34;init()&#34; @click=&#34;copy()&#34;&gt;
        &lt;img class=&#34;code-clipboard__icon&#34; src=&#34;/media/images/icons/icon-copy-small-2.svg&#34; alt=&#34;Copy code to clipboard&#34; width=&#34;14&#34; height=&#34;13&#34;&gt;
        &lt;span&gt;Copy&lt;/span&gt;
      &lt;/button&gt;
    &lt;/span&gt;
    &lt;div class=&#34;lang-toolbar__border&#34;&gt;&lt;/div&gt;
  &lt;/div&gt;&lt;div class=&#34;code-snippet &#34;&gt;
    &lt;pre data-expanded=&#34;false&#34;&gt;&lt;code class=&#34;language-yaml&#34;&gt;apiVersion: 1

datasources:
  - name: Postgres-TLS
    type: postgres
    url: db.example.com:5432
    user: grafana
    secureJsonData:
      password: &amp;#39;&amp;lt;PASSWORD&amp;gt;&amp;#39;
    jsonData:
      database: grafana
      sslmode: &amp;#39;verify-full&amp;#39;
      tlsConfigurationMethod: &amp;#39;file-path&amp;#39;
      sslRootCertFile: &amp;#39;/etc/grafana/certs/root.crt&amp;#39;
      sslCertFile: &amp;#39;/etc/grafana/certs/client.crt&amp;#39;
      sslKeyFile: &amp;#39;/etc/grafana/certs/client.key&amp;#39;&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;Replace &lt;code&gt;&amp;lt;PASSWORD&amp;gt;&lt;/code&gt; with your database password and update the certificate paths to match your environment.&lt;/p&gt;
&lt;h3 id=&#34;provisioning-with-timescaledb&#34;&gt;Provisioning with TimescaleDB&lt;/h3&gt;
&lt;p&gt;The following example enables TimescaleDB support:&lt;/p&gt;

&lt;div class=&#34;code-snippet &#34;&gt;&lt;div class=&#34;lang-toolbar&#34;&gt;
    &lt;span class=&#34;lang-toolbar__item lang-toolbar__item-active&#34;&gt;YAML&lt;/span&gt;
    &lt;span class=&#34;code-clipboard&#34;&gt;
      &lt;button x-data=&#34;app_code_snippet()&#34; x-init=&#34;init()&#34; @click=&#34;copy()&#34;&gt;
        &lt;img class=&#34;code-clipboard__icon&#34; src=&#34;/media/images/icons/icon-copy-small-2.svg&#34; alt=&#34;Copy code to clipboard&#34; width=&#34;14&#34; height=&#34;13&#34;&gt;
        &lt;span&gt;Copy&lt;/span&gt;
      &lt;/button&gt;
    &lt;/span&gt;
    &lt;div class=&#34;lang-toolbar__border&#34;&gt;&lt;/div&gt;
  &lt;/div&gt;&lt;div class=&#34;code-snippet &#34;&gt;
    &lt;pre data-expanded=&#34;false&#34;&gt;&lt;code class=&#34;language-yaml&#34;&gt;apiVersion: 1

datasources:
  - name: Postgres-TimescaleDB
    type: postgres
    url: timescale.example.com:5432
    user: grafana
    secureJsonData:
      password: &amp;#39;&amp;lt;PASSWORD&amp;gt;&amp;#39;
    jsonData:
      database: metrics
      sslmode: &amp;#39;require&amp;#39;
      postgresVersion: 1000
      timescaledb: true&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;Replace &lt;code&gt;&amp;lt;PASSWORD&amp;gt;&lt;/code&gt; with your database password.&lt;/p&gt;
&lt;h3 id=&#34;provisioning-with-a-unix-socket&#34;&gt;Provisioning with a Unix socket&lt;/h3&gt;
&lt;p&gt;The following example connects through a Unix socket instead of TCP:&lt;/p&gt;

&lt;div class=&#34;code-snippet &#34;&gt;&lt;div class=&#34;lang-toolbar&#34;&gt;
    &lt;span class=&#34;lang-toolbar__item lang-toolbar__item-active&#34;&gt;YAML&lt;/span&gt;
    &lt;span class=&#34;code-clipboard&#34;&gt;
      &lt;button x-data=&#34;app_code_snippet()&#34; x-init=&#34;init()&#34; @click=&#34;copy()&#34;&gt;
        &lt;img class=&#34;code-clipboard__icon&#34; src=&#34;/media/images/icons/icon-copy-small-2.svg&#34; alt=&#34;Copy code to clipboard&#34; width=&#34;14&#34; height=&#34;13&#34;&gt;
        &lt;span&gt;Copy&lt;/span&gt;
      &lt;/button&gt;
    &lt;/span&gt;
    &lt;div class=&#34;lang-toolbar__border&#34;&gt;&lt;/div&gt;
  &lt;/div&gt;&lt;div class=&#34;code-snippet &#34;&gt;
    &lt;pre data-expanded=&#34;false&#34;&gt;&lt;code class=&#34;language-yaml&#34;&gt;apiVersion: 1

datasources:
  - name: Postgres-Socket
    type: postgres
    url: /var/run/postgresql
    user: grafana
    secureJsonData:
      password: &amp;#39;&amp;lt;PASSWORD&amp;gt;&amp;#39;
    jsonData:
      database: grafana
      sslmode: &amp;#39;disable&amp;#39;&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;Replace &lt;code&gt;&amp;lt;PASSWORD&amp;gt;&lt;/code&gt; with your database password. When using a Unix socket, set &lt;code&gt;url&lt;/code&gt; to the socket directory path. Don&amp;rsquo;t include a port number.&lt;/p&gt;
&lt;h3 id=&#34;provisioning-with-environment-variables&#34;&gt;Provisioning with environment variables&lt;/h3&gt;
&lt;p&gt;You can use the &lt;code&gt;$__env{}&lt;/code&gt; syntax to reference environment variables in provisioning files. This avoids storing credentials in plain text YAML:&lt;/p&gt;

&lt;div class=&#34;code-snippet &#34;&gt;&lt;div class=&#34;lang-toolbar&#34;&gt;
    &lt;span class=&#34;lang-toolbar__item lang-toolbar__item-active&#34;&gt;YAML&lt;/span&gt;
    &lt;span class=&#34;code-clipboard&#34;&gt;
      &lt;button x-data=&#34;app_code_snippet()&#34; x-init=&#34;init()&#34; @click=&#34;copy()&#34;&gt;
        &lt;img class=&#34;code-clipboard__icon&#34; src=&#34;/media/images/icons/icon-copy-small-2.svg&#34; alt=&#34;Copy code to clipboard&#34; width=&#34;14&#34; height=&#34;13&#34;&gt;
        &lt;span&gt;Copy&lt;/span&gt;
      &lt;/button&gt;
    &lt;/span&gt;
    &lt;div class=&#34;lang-toolbar__border&#34;&gt;&lt;/div&gt;
  &lt;/div&gt;&lt;div class=&#34;code-snippet &#34;&gt;
    &lt;pre data-expanded=&#34;false&#34;&gt;&lt;code class=&#34;language-yaml&#34;&gt;apiVersion: 1

datasources:
  - name: Postgres
    type: postgres
    url: $__env{PG_HOST}:$__env{PG_PORT}
    user: $__env{PG_USER}
    secureJsonData:
      password: $__env{PG_PASSWORD}
    jsonData:
      database: $__env{PG_DATABASE}
      sslmode: &amp;#39;require&amp;#39;&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;h3 id=&#34;provisioning-configuration-reference&#34;&gt;Provisioning configuration reference&lt;/h3&gt;
&lt;p&gt;The following table lists all &lt;code&gt;jsonData&lt;/code&gt; and &lt;code&gt;secureJsonData&lt;/code&gt; fields supported when provisioning the PostgreSQL data source:&lt;/p&gt;
&lt;section class=&#34;expand-table-wrapper&#34;&gt;&lt;div class=&#34;button-div&#34;&gt;
      &lt;button class=&#34;expand-table-btn&#34;&gt;Expand table&lt;/button&gt;
    &lt;/div&gt;&lt;div class=&#34;responsive-table-wrapper&#34;&gt;
    &lt;table&gt;
      &lt;thead&gt;
          &lt;tr&gt;
              &lt;th&gt;Field&lt;/th&gt;
              &lt;th&gt;Location&lt;/th&gt;
              &lt;th&gt;Description&lt;/th&gt;
          &lt;/tr&gt;
      &lt;/thead&gt;
      &lt;tbody&gt;
          &lt;tr&gt;
              &lt;td&gt;&lt;code&gt;database&lt;/code&gt;&lt;/td&gt;
              &lt;td&gt;&lt;code&gt;jsonData&lt;/code&gt;&lt;/td&gt;
              &lt;td&gt;The database name.&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;&lt;code&gt;sslmode&lt;/code&gt;&lt;/td&gt;
              &lt;td&gt;&lt;code&gt;jsonData&lt;/code&gt;&lt;/td&gt;
              &lt;td&gt;TLS/SSL mode: &lt;code&gt;disable&lt;/code&gt;, &lt;code&gt;require&lt;/code&gt;, &lt;code&gt;verify-ca&lt;/code&gt;, or &lt;code&gt;verify-full&lt;/code&gt;.&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;&lt;code&gt;maxOpenConns&lt;/code&gt;&lt;/td&gt;
              &lt;td&gt;&lt;code&gt;jsonData&lt;/code&gt;&lt;/td&gt;
              &lt;td&gt;Maximum open connections. Default: &lt;code&gt;100&lt;/code&gt;.&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;&lt;code&gt;maxIdleConns&lt;/code&gt;&lt;/td&gt;
              &lt;td&gt;&lt;code&gt;jsonData&lt;/code&gt;&lt;/td&gt;
              &lt;td&gt;Maximum idle connections. Default: &lt;code&gt;100&lt;/code&gt;.&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;&lt;code&gt;maxIdleConnsAuto&lt;/code&gt;&lt;/td&gt;
              &lt;td&gt;&lt;code&gt;jsonData&lt;/code&gt;&lt;/td&gt;
              &lt;td&gt;Set max idle to max open automatically. Default: &lt;code&gt;true&lt;/code&gt;.&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;&lt;code&gt;connMaxLifetime&lt;/code&gt;&lt;/td&gt;
              &lt;td&gt;&lt;code&gt;jsonData&lt;/code&gt;&lt;/td&gt;
              &lt;td&gt;Connection max lifetime in seconds. Default: &lt;code&gt;14400&lt;/code&gt;.&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;&lt;code&gt;postgresVersion&lt;/code&gt;&lt;/td&gt;
              &lt;td&gt;&lt;code&gt;jsonData&lt;/code&gt;&lt;/td&gt;
              &lt;td&gt;Server version code: &lt;code&gt;903&lt;/code&gt; (9.3), &lt;code&gt;904&lt;/code&gt; (9.4), &lt;code&gt;905&lt;/code&gt; (9.5), &lt;code&gt;906&lt;/code&gt; (9.6), &lt;code&gt;1000&lt;/code&gt; (10&#43;).&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;&lt;code&gt;timescaledb&lt;/code&gt;&lt;/td&gt;
              &lt;td&gt;&lt;code&gt;jsonData&lt;/code&gt;&lt;/td&gt;
              &lt;td&gt;Enable TimescaleDB support. Default: &lt;code&gt;false&lt;/code&gt;.&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;&lt;code&gt;tlsConfigurationMethod&lt;/code&gt;&lt;/td&gt;
              &lt;td&gt;&lt;code&gt;jsonData&lt;/code&gt;&lt;/td&gt;
              &lt;td&gt;TLS cert method: &lt;code&gt;file-path&lt;/code&gt; or &lt;code&gt;file-content&lt;/code&gt;.&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;&lt;code&gt;sslRootCertFile&lt;/code&gt;&lt;/td&gt;
              &lt;td&gt;&lt;code&gt;jsonData&lt;/code&gt;&lt;/td&gt;
              &lt;td&gt;Path to root CA certificate (when using &lt;code&gt;file-path&lt;/code&gt; method).&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;&lt;code&gt;sslCertFile&lt;/code&gt;&lt;/td&gt;
              &lt;td&gt;&lt;code&gt;jsonData&lt;/code&gt;&lt;/td&gt;
              &lt;td&gt;Path to client certificate (when using &lt;code&gt;file-path&lt;/code&gt; method).&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;&lt;code&gt;sslKeyFile&lt;/code&gt;&lt;/td&gt;
              &lt;td&gt;&lt;code&gt;jsonData&lt;/code&gt;&lt;/td&gt;
              &lt;td&gt;Path to client key (when using &lt;code&gt;file-path&lt;/code&gt; method).&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;&lt;code&gt;password&lt;/code&gt;&lt;/td&gt;
              &lt;td&gt;&lt;code&gt;secureJsonData&lt;/code&gt;&lt;/td&gt;
              &lt;td&gt;Database password.&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;&lt;code&gt;tlsCACert&lt;/code&gt;&lt;/td&gt;
              &lt;td&gt;&lt;code&gt;secureJsonData&lt;/code&gt;&lt;/td&gt;
              &lt;td&gt;Root CA certificate content (when using &lt;code&gt;file-content&lt;/code&gt; method).&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;&lt;code&gt;tlsClientCert&lt;/code&gt;&lt;/td&gt;
              &lt;td&gt;&lt;code&gt;secureJsonData&lt;/code&gt;&lt;/td&gt;
              &lt;td&gt;Client certificate content (when using &lt;code&gt;file-content&lt;/code&gt; method).&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;&lt;code&gt;tlsClientKey&lt;/code&gt;&lt;/td&gt;
              &lt;td&gt;&lt;code&gt;secureJsonData&lt;/code&gt;&lt;/td&gt;
              &lt;td&gt;Client key content (when using &lt;code&gt;file-content&lt;/code&gt; method).&lt;/td&gt;
          &lt;/tr&gt;
      &lt;/tbody&gt;
    &lt;/table&gt;
  &lt;/div&gt;
&lt;/section&gt;&lt;h4 id=&#34;troubleshoot-provisioning-issues&#34;&gt;Troubleshoot provisioning issues&lt;/h4&gt;
&lt;p&gt;If you encounter metric request errors or other issues when provisioning, refer to 
    &lt;a href=&#34;/docs/grafana/v13.1/datasources/postgres/troubleshooting/#provisioning-errors&#34;&gt;Provisioning errors&lt;/a&gt; in the PostgreSQL troubleshooting guide.&lt;/p&gt;
&lt;h2 id=&#34;configure-with-terraform&#34;&gt;Configure with Terraform&lt;/h2&gt;
&lt;p&gt;You can configure the PostgreSQL data source using &lt;a href=&#34;https://www.terraform.io/&#34; target=&#34;_blank&#34; rel=&#34;noopener noreferrer&#34;&gt;Terraform&lt;/a&gt; with the &lt;a href=&#34;https://registry.terraform.io/providers/grafana/grafana/latest/docs&#34; target=&#34;_blank&#34; rel=&#34;noopener noreferrer&#34;&gt;Grafana Terraform provider&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;For more information about provisioning resources with Terraform, refer to &lt;a href=&#34;/docs/grafana-cloud/developer-resources/infrastructure-as-code/terraform/&#34;&gt;Grafana as code using Terraform&lt;/a&gt;.&lt;/p&gt;
&lt;h3 id=&#34;terraform-example&#34;&gt;Terraform example&lt;/h3&gt;
&lt;p&gt;The following example creates a basic PostgreSQL data source:&lt;/p&gt;

&lt;div class=&#34;code-snippet &#34;&gt;&lt;div class=&#34;lang-toolbar&#34;&gt;
    &lt;span class=&#34;lang-toolbar__item lang-toolbar__item-active&#34;&gt;hcl&lt;/span&gt;
    &lt;span class=&#34;code-clipboard&#34;&gt;
      &lt;button x-data=&#34;app_code_snippet()&#34; x-init=&#34;init()&#34; @click=&#34;copy()&#34;&gt;
        &lt;img class=&#34;code-clipboard__icon&#34; src=&#34;/media/images/icons/icon-copy-small-2.svg&#34; alt=&#34;Copy code to clipboard&#34; width=&#34;14&#34; height=&#34;13&#34;&gt;
        &lt;span&gt;Copy&lt;/span&gt;
      &lt;/button&gt;
    &lt;/span&gt;
    &lt;div class=&#34;lang-toolbar__border&#34;&gt;&lt;/div&gt;
  &lt;/div&gt;&lt;div class=&#34;code-snippet &#34;&gt;
    &lt;pre data-expanded=&#34;false&#34;&gt;&lt;code class=&#34;language-hcl&#34;&gt;resource &amp;#34;grafana_data_source&amp;#34; &amp;#34;postgres&amp;#34; {
  name = &amp;#34;Postgres&amp;#34;
  type = &amp;#34;postgres&amp;#34;
  url  = &amp;#34;localhost:5432&amp;#34;
  user = &amp;#34;grafana&amp;#34;

  json_data_encoded = jsonencode({
    database         = &amp;#34;grafana&amp;#34;
    sslmode          = &amp;#34;disable&amp;#34;
    maxOpenConns     = 100
    maxIdleConns     = 100
    maxIdleConnsAuto = true
    connMaxLifetime  = 14400
    postgresVersion  = 903
    timescaledb      = false
  })

  secure_json_data_encoded = jsonencode({
    password = &amp;#34;Password!&amp;#34;
  })
}&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;For all available configuration options, refer to the &lt;a href=&#34;https://registry.terraform.io/providers/grafana/grafana/latest/docs/resources/data_source&#34; target=&#34;_blank&#34; rel=&#34;noopener noreferrer&#34;&gt;Grafana provider data source resource documentation&lt;/a&gt;.&lt;/p&gt;
&lt;h2 id=&#34;next-steps&#34;&gt;Next steps&lt;/h2&gt;
&lt;p&gt;After configuring your PostgreSQL data source, you can:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
    &lt;a href=&#34;/docs/grafana/v13.1/datasources/postgres/query-editor/&#34;&gt;Write queries&lt;/a&gt; using the query editor to explore and visualize your data.&lt;/li&gt;
&lt;li&gt;
    &lt;a href=&#34;/docs/grafana/v13.1/datasources/postgres/template-variables/&#34;&gt;Use template variables&lt;/a&gt; to create dynamic, reusable dashboards.&lt;/li&gt;
&lt;li&gt;
    &lt;a href=&#34;/docs/grafana/v13.1/datasources/postgres/annotations/&#34;&gt;Add annotations&lt;/a&gt; to overlay PostgreSQL events on your panels.&lt;/li&gt;
&lt;li&gt;
    &lt;a href=&#34;/docs/grafana/v13.1/datasources/postgres/alerting/&#34;&gt;Set up alerting&lt;/a&gt; to create alert rules based on your PostgreSQL data (time series format only).&lt;/li&gt;
&lt;li&gt;
    &lt;a href=&#34;/docs/grafana/v13.1/datasources/postgres/troubleshooting/&#34;&gt;Troubleshoot issues&lt;/a&gt; if you encounter problems with your data source.&lt;/li&gt;
&lt;/ul&gt;
]]></content><description>&lt;h1 id="configure-the-postgresql-data-source">Configure the PostgreSQL data source&lt;/h1>
&lt;p>This document explains how to configure the PostgreSQL data source and lists all configuration options. For general information on managing data sources, refer to
&lt;a href="/docs/grafana/v13.1/administration/data-source-management/">Data source management&lt;/a>.&lt;/p></description></item><item><title>PostgreSQL query editor</title><link>https://grafana.com/docs/grafana/v13.1/datasources/postgres/query-editor/</link><pubDate>Tue, 23 Jun 2026 13:06:40 +0000</pubDate><guid>https://grafana.com/docs/grafana/v13.1/datasources/postgres/query-editor/</guid><content><![CDATA[&lt;h1 id=&#34;postgresql-query-editor&#34;&gt;PostgreSQL query editor&lt;/h1&gt;
&lt;p&gt;The PostgreSQL query editor lets you build and run queries against your data source. For general query editor and data transformation concepts, refer to 
    &lt;a href=&#34;/docs/grafana/v13.1/panels-visualizations/query-transform-data/&#34;&gt;Query and transform data&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;You can open the PostgreSQL query editor from the 
    &lt;a href=&#34;/docs/grafana/v13.1/explore/&#34;&gt;Explore page&lt;/a&gt; or from a dashboard panel—click the ellipsis in the upper right of the panel and select &lt;strong&gt;Edit&lt;/strong&gt;.&lt;/p&gt;


&lt;div class=&#34;admonition admonition-note&#34;&gt;&lt;blockquote&gt;&lt;p class=&#34;title text-uppercase&#34;&gt;Note&lt;/p&gt;&lt;p&gt;A default database must be configured in the data source settings. If none is set, or it is removed, the data source will not run queries until a database is configured again.&lt;/p&gt;&lt;/blockquote&gt;&lt;/div&gt;

&lt;h2 id=&#34;postgresql-query-editor-components&#34;&gt;PostgreSQL query editor components&lt;/h2&gt;
&lt;p&gt;The PostgreSQL query editor has two modes: &lt;strong&gt;Builder&lt;/strong&gt; and &lt;strong&gt;Code&lt;/strong&gt;.&lt;/p&gt;
&lt;p&gt;Builder mode helps you build a query using a visual interface. Code mode allows for advanced querying and offers support for complex SQL query writing.&lt;/p&gt;
&lt;h3 id=&#34;postgresql-builder-mode&#34;&gt;PostgreSQL Builder mode&lt;/h3&gt;
&lt;p&gt;The following components will help you build a PostgreSQL query:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Format&lt;/strong&gt; - Select the query result format from the drop-down. The default is &lt;strong&gt;Table&lt;/strong&gt;. If you use the &lt;strong&gt;Time series&lt;/strong&gt; format option, one of the columns must be &lt;code&gt;time&lt;/code&gt;. Refer to &lt;a href=&#34;#time-series-queries&#34;&gt;Time series queries&lt;/a&gt; for more information.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Table&lt;/strong&gt; - Select a table from the drop-down. Tables correspond to the chosen database.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Data operations&lt;/strong&gt; - &lt;em&gt;Optional&lt;/em&gt; Select an aggregation from the drop-down. You can add multiple data operations by clicking the &lt;strong&gt;&#43;&lt;/strong&gt; sign. Click the &lt;strong&gt;X&lt;/strong&gt; sign to remove data operations.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Column&lt;/strong&gt; - Select a column on which to run the aggregation.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Alias&lt;/strong&gt; - &lt;em&gt;Optional&lt;/em&gt; Add an alias from the drop-down. You can also add your own alias by typing it in the box and clicking &lt;strong&gt;Enter&lt;/strong&gt;. Remove an alias by clicking the &lt;strong&gt;X&lt;/strong&gt;.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Filter&lt;/strong&gt; - Toggle to add filters.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Filter by column value&lt;/strong&gt; - &lt;em&gt;Optional&lt;/em&gt; If you toggle &lt;strong&gt;Filter&lt;/strong&gt;, you can add a column to filter by from the drop-down. To filter on more columns, click the &lt;strong&gt;&#43;&lt;/strong&gt; sign to the right of the condition drop-down. Choose an operator from the drop-down next to the condition. When multiple filters are added, you can add an &lt;code&gt;AND&lt;/code&gt; operator to display all true conditions or an &lt;code&gt;OR&lt;/code&gt; operator to display any true conditions. Use the second drop-down to choose a filter value. To remove a filter, click the &lt;strong&gt;X&lt;/strong&gt; next to that filter&amp;rsquo;s drop-down. After selecting a date-type column, you can choose &lt;strong&gt;Macros&lt;/strong&gt; from the operators list and select &lt;code&gt;timeFilter&lt;/code&gt; to add the &lt;code&gt;$__timeFilter&lt;/code&gt; macro to the query with the selected date column.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Group&lt;/strong&gt; - Toggle to add &lt;strong&gt;Group by column&lt;/strong&gt;.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Group by column&lt;/strong&gt; - Select a column to group by from the drop-down. Click the &lt;strong&gt;&#43;&lt;/strong&gt; sign to group by multiple columns. Click the &lt;strong&gt;X&lt;/strong&gt; to remove a column.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Order&lt;/strong&gt; - Toggle to add an &lt;code&gt;ORDER BY&lt;/code&gt; statement.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Order by&lt;/strong&gt; - Select a column to order by from the drop-down. Select ascending (&lt;code&gt;ASC&lt;/code&gt;) or descending (&lt;code&gt;DESC&lt;/code&gt;) order.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Limit&lt;/strong&gt; - You can add an optional limit on the number of retrieved results. Default is 50.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Preview&lt;/strong&gt; - Toggle for a preview of the SQL query generated by the query builder. Preview is toggled on by default.&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&#34;postgresql-code-mode&#34;&gt;PostgreSQL Code mode&lt;/h2&gt;
&lt;p&gt;To create advanced queries, switch to &lt;strong&gt;Code mode&lt;/strong&gt; by clicking &lt;strong&gt;Code&lt;/strong&gt; in the upper right of the editor window. Code mode supports the auto-completion of tables, columns, SQL keywords, standard SQL functions, Grafana template variables, and Grafana macros. Columns cannot be completed before a table has been specified.&lt;/p&gt;


&lt;div class=&#34;admonition admonition-note&#34;&gt;&lt;blockquote&gt;&lt;p class=&#34;title text-uppercase&#34;&gt;Note&lt;/p&gt;&lt;p&gt;If a table or column name is a reserved word or contains mixed case or special characters, use double quotes in SQL. For example, &lt;code&gt;&amp;quot;user&amp;quot;&lt;/code&gt; or &lt;code&gt;&amp;quot;Created At&amp;quot;&lt;/code&gt;.&lt;/p&gt;&lt;/blockquote&gt;&lt;/div&gt;

&lt;figure
    class=&#34;figure-wrapper figure-wrapper__lightbox w-100p docs-image--no-shadow&#34;
    style=&#34;max-width: 963px;&#34;
    itemprop=&#34;associatedMedia&#34;
    itemscope=&#34;&#34;
    itemtype=&#34;http://schema.org/ImageObject&#34;
  &gt;&lt;a
        class=&#34;lightbox-link&#34;
        href=&#34;/static/img/docs/v92/sql_code_editor.png&#34;
        itemprop=&#34;contentUrl&#34;
      &gt;&lt;div class=&#34;img-wrapper w-100p h-auto&#34;&gt;&lt;img
          class=&#34;lazyload &#34;
          data-src=&#34;/static/img/docs/v92/sql_code_editor.png&#34;data-srcset=&#34;/static/img/docs/v92/sql_code_editor.png?w=320 320w, /static/img/docs/v92/sql_code_editor.png?w=550 550w, /static/img/docs/v92/sql_code_editor.png?w=750 750w, /static/img/docs/v92/sql_code_editor.png?w=900 900w, /static/img/docs/v92/sql_code_editor.png?w=1040 1040w, /static/img/docs/v92/sql_code_editor.png?w=1240 1240w, /static/img/docs/v92/sql_code_editor.png?w=1920 1920w&#34;data-sizes=&#34;auto&#34;alt=&#34;&#34;width=&#34;963&#34;height=&#34;326&#34;/&gt;
        &lt;noscript&gt;
          &lt;img
            src=&#34;/static/img/docs/v92/sql_code_editor.png&#34;
            alt=&#34;&#34;width=&#34;963&#34;height=&#34;326&#34;class=&#34;docs-image--no-shadow&#34;/&gt;
        &lt;/noscript&gt;&lt;/div&gt;&lt;/a&gt;&lt;/figure&gt;
&lt;p&gt;Select &lt;strong&gt;Table&lt;/strong&gt; or &lt;strong&gt;Time Series&lt;/strong&gt; as the format. Click the &lt;strong&gt;{}&lt;/strong&gt; in the bottom right to format the query. Click the &lt;strong&gt;downward caret&lt;/strong&gt; to expand the Code mode editor. &lt;strong&gt;CTRL/CMD &#43; Return&lt;/strong&gt; serves as a keyboard shortcut to execute the query.&lt;/p&gt;


&lt;div class=&#34;admonition admonition-warning&#34;&gt;&lt;blockquote&gt;&lt;p class=&#34;title text-uppercase&#34;&gt;Warning&lt;/p&gt;&lt;p&gt;Changes made to a query in Code mode will not transfer to Builder mode and will be discarded. You will be prompted to copy your code to the clipboard to save any changes.&lt;/p&gt;&lt;/blockquote&gt;&lt;/div&gt;

&lt;h2 id=&#34;macros&#34;&gt;Macros&lt;/h2&gt;
&lt;p&gt;You can add macros to your queries to simplify the syntax and enable dynamic elements, such as date range filters.&lt;/p&gt;
&lt;p&gt;Grafana expands macros into native PostgreSQL SQL before executing the query. When the &lt;a href=&#34;https://www.timescale.com/&#34; target=&#34;_blank&#34; rel=&#34;noopener noreferrer&#34;&gt;TimescaleDB&lt;/a&gt; extension is enabled, &lt;code&gt;$__timeGroup&lt;/code&gt; and &lt;code&gt;$__timeGroupAlias&lt;/code&gt; use &lt;code&gt;time_bucket()&lt;/code&gt; for more efficient grouping.&lt;/p&gt;
&lt;h3 id=&#34;time-series-macros&#34;&gt;Time-series macros&lt;/h3&gt;
&lt;section class=&#34;expand-table-wrapper&#34;&gt;&lt;div class=&#34;button-div&#34;&gt;
      &lt;button class=&#34;expand-table-btn&#34;&gt;Expand table&lt;/button&gt;
    &lt;/div&gt;&lt;div class=&#34;responsive-table-wrapper&#34;&gt;
    &lt;table&gt;
      &lt;thead&gt;
          &lt;tr&gt;
              &lt;th&gt;Macro example&lt;/th&gt;
              &lt;th&gt;Description&lt;/th&gt;
          &lt;/tr&gt;
      &lt;/thead&gt;
      &lt;tbody&gt;
          &lt;tr&gt;
              &lt;td&gt;&lt;code&gt;$__time(dateColumn)&lt;/code&gt;&lt;/td&gt;
              &lt;td&gt;Renames the column to &lt;code&gt;time&lt;/code&gt;. Example: &lt;code&gt;dateColumn AS &amp;quot;time&amp;quot;&lt;/code&gt;. Use for native date/time columns.&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;&lt;code&gt;$__timeEpoch(dateColumn)&lt;/code&gt;&lt;/td&gt;
              &lt;td&gt;Converts to UNIX epoch (seconds) and renames the column to &lt;code&gt;time&lt;/code&gt;. Example: &lt;code&gt;extract(epoch from dateColumn) as &amp;quot;time&amp;quot;&lt;/code&gt;. Requires a column argument.&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;&lt;code&gt;$__timeFilter(dateColumn)&lt;/code&gt;&lt;/td&gt;
              &lt;td&gt;Replaces the value with a time range filter using the specified column name. Example: &lt;code&gt;dateColumn BETWEEN &#39;2020-07-13T20:19:09.254Z&#39; AND &#39;2020-07-13T21:19:09.254Z&#39;&lt;/code&gt;.&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;&lt;code&gt;$__timeFrom()&lt;/code&gt;&lt;/td&gt;
              &lt;td&gt;Replaces the value with the start of the currently active time selection (RFC3339Nano). Example: &lt;code&gt;&#39;2020-07-13T20:19:09.254Z&#39;&lt;/code&gt;.&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;&lt;code&gt;$__timeTo()&lt;/code&gt;&lt;/td&gt;
              &lt;td&gt;Replaces the value with the end of the currently active time selection (RFC3339Nano). Example: &lt;code&gt;&#39;2020-07-13T20:19:09.254Z&#39;&lt;/code&gt;.&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;&lt;code&gt;$__timeGroup(dateColumn,&#39;5m&#39;)&lt;/code&gt;&lt;/td&gt;
              &lt;td&gt;Replaces the value with an expression suitable for use in a &lt;code&gt;GROUP BY&lt;/code&gt; clause. Example: &lt;code&gt;floor(extract(epoch from dateColumn)/300)*300&lt;/code&gt;. With TimescaleDB: &lt;code&gt;time_bucket(&#39;300s&#39;, dateColumn)&lt;/code&gt;.&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;&lt;code&gt;$__timeGroup(dateColumn,&#39;5m&#39;, 0)&lt;/code&gt;&lt;/td&gt;
              &lt;td&gt;Same as &lt;code&gt;$__timeGroup(dateColumn,&#39;5m&#39;)&lt;/code&gt;, but includes a fill parameter to ensure missing points in the series are added by Grafana, using &lt;code&gt;0&lt;/code&gt; as the default value. Fill only applies to time series queries.&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;&lt;code&gt;$__timeGroup(dateColumn,&#39;5m&#39;, NULL)&lt;/code&gt;&lt;/td&gt;
              &lt;td&gt;Same as &lt;code&gt;$__timeGroup(dateColumn,&#39;5m&#39;, 0)&lt;/code&gt; but &lt;code&gt;NULL&lt;/code&gt; is used as the value for missing points. Fill only applies to time series queries.&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;&lt;code&gt;$__timeGroup(dateColumn,&#39;5m&#39;, previous)&lt;/code&gt;&lt;/td&gt;
              &lt;td&gt;Same as &lt;code&gt;$__timeGroup(dateColumn,&#39;5m&#39;, 0)&lt;/code&gt; but uses the previous value in the series as the fill value. If no previous value exists, it uses &lt;code&gt;NULL&lt;/code&gt;. Fill only applies to time series queries.&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;&lt;code&gt;$__timeGroupAlias(dateColumn,&#39;5m&#39;)&lt;/code&gt;&lt;/td&gt;
              &lt;td&gt;Same as &lt;code&gt;$__timeGroup&lt;/code&gt; but with an added column alias &lt;code&gt;AS &amp;quot;time&amp;quot;&lt;/code&gt;. With TimescaleDB, uses &lt;code&gt;time_bucket()&lt;/code&gt;.&lt;/td&gt;
          &lt;/tr&gt;
      &lt;/tbody&gt;
    &lt;/table&gt;
  &lt;/div&gt;
&lt;/section&gt;&lt;h3 id=&#34;unix-epoch-macros&#34;&gt;UNIX epoch macros&lt;/h3&gt;
&lt;section class=&#34;expand-table-wrapper&#34;&gt;&lt;div class=&#34;button-div&#34;&gt;
      &lt;button class=&#34;expand-table-btn&#34;&gt;Expand table&lt;/button&gt;
    &lt;/div&gt;&lt;div class=&#34;responsive-table-wrapper&#34;&gt;
    &lt;table&gt;
      &lt;thead&gt;
          &lt;tr&gt;
              &lt;th&gt;Macro example&lt;/th&gt;
              &lt;th&gt;Description&lt;/th&gt;
          &lt;/tr&gt;
      &lt;/thead&gt;
      &lt;tbody&gt;
          &lt;tr&gt;
              &lt;td&gt;&lt;code&gt;$__unixEpochFilter(dateColumn)&lt;/code&gt;&lt;/td&gt;
              &lt;td&gt;Replaces the value with a time range filter for columns storing UNIX epoch (seconds). Example: &lt;code&gt;dateColumn &amp;gt;= 1494410783 AND dateColumn &amp;lt;= 1494497183&lt;/code&gt;.&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;&lt;code&gt;$__unixEpochFrom()&lt;/code&gt;&lt;/td&gt;
              &lt;td&gt;Replaces the value with the start of the currently active time selection as a UNIX timestamp (seconds). Example: &lt;code&gt;1494410783&lt;/code&gt;.&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;&lt;code&gt;$__unixEpochTo()&lt;/code&gt;&lt;/td&gt;
              &lt;td&gt;Replaces the value with the end of the currently active time selection as a UNIX timestamp (seconds). Example: &lt;code&gt;1494497183&lt;/code&gt;.&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;&lt;code&gt;$__unixEpochNanoFilter(dateColumn)&lt;/code&gt;&lt;/td&gt;
              &lt;td&gt;Replaces the value with a time range filter for columns storing UNIX epoch in nanoseconds. Example: &lt;code&gt;dateColumn &amp;gt;= 1494410783152415214 AND dateColumn &amp;lt;= 1494497183142514872&lt;/code&gt;.&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;&lt;code&gt;$__unixEpochNanoFrom()&lt;/code&gt;&lt;/td&gt;
              &lt;td&gt;Replaces the value with the start of the currently active time selection as a nanosecond timestamp. Example: &lt;code&gt;1494410783152415214&lt;/code&gt;.&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;&lt;code&gt;$__unixEpochNanoTo()&lt;/code&gt;&lt;/td&gt;
              &lt;td&gt;Replaces the value with the end of the currently active time selection as a nanosecond timestamp. Example: &lt;code&gt;1494497183142514872&lt;/code&gt;.&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;&lt;code&gt;$__unixEpochGroup(dateColumn,&#39;5m&#39;, [fillmode])&lt;/code&gt;&lt;/td&gt;
              &lt;td&gt;Same as &lt;code&gt;$__timeGroup&lt;/code&gt; but for columns storing UNIX epoch (seconds). Example: &lt;code&gt;floor((dateColumn)/300)*300&lt;/code&gt;. &lt;code&gt;fillMode&lt;/code&gt; only applies to time series queries.&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;&lt;code&gt;$__unixEpochGroupAlias(dateColumn,&#39;5m&#39;, [fillmode])&lt;/code&gt;&lt;/td&gt;
              &lt;td&gt;Same as &lt;code&gt;$__unixEpochGroup&lt;/code&gt; but with an added column alias &lt;code&gt;AS &amp;quot;time&amp;quot;&lt;/code&gt;. &lt;code&gt;fillMode&lt;/code&gt; only applies to time series queries.&lt;/td&gt;
          &lt;/tr&gt;
      &lt;/tbody&gt;
    &lt;/table&gt;
  &lt;/div&gt;
&lt;/section&gt;&lt;h3 id=&#34;interval-variables&#34;&gt;Interval variables&lt;/h3&gt;
&lt;p&gt;In addition to the macros listed, the following Grafana 
    &lt;a href=&#34;/docs/grafana/v13.1/dashboards/variables/add-template-variables/#__interval&#34;&gt;interval variables&lt;/a&gt; are replaced before query execution:&lt;/p&gt;
&lt;section class=&#34;expand-table-wrapper&#34;&gt;&lt;div class=&#34;button-div&#34;&gt;
      &lt;button class=&#34;expand-table-btn&#34;&gt;Expand table&lt;/button&gt;
    &lt;/div&gt;&lt;div class=&#34;responsive-table-wrapper&#34;&gt;
    &lt;table&gt;
      &lt;thead&gt;
          &lt;tr&gt;
              &lt;th&gt;Variable&lt;/th&gt;
              &lt;th&gt;Description&lt;/th&gt;
          &lt;/tr&gt;
      &lt;/thead&gt;
      &lt;tbody&gt;
          &lt;tr&gt;
              &lt;td&gt;&lt;code&gt;$__interval&lt;/code&gt;&lt;/td&gt;
              &lt;td&gt;Replaced with the calculated interval based on the time range and panel width (for example, &lt;code&gt;5m&lt;/code&gt;). Use in &lt;code&gt;$__timeGroup&lt;/code&gt; or directly in custom expressions.&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;&lt;code&gt;$__interval_ms&lt;/code&gt;&lt;/td&gt;
              &lt;td&gt;Same as &lt;code&gt;$__interval&lt;/code&gt; but in milliseconds (for example, &lt;code&gt;300000&lt;/code&gt;).&lt;/td&gt;
          &lt;/tr&gt;
      &lt;/tbody&gt;
    &lt;/table&gt;
  &lt;/div&gt;
&lt;/section&gt;&lt;p&gt;You can set a lower bound for these variables with the &lt;strong&gt;Min time interval&lt;/strong&gt; option in the 
    &lt;a href=&#34;/docs/grafana/v13.1/datasources/postgres/configure/#min-time-interval&#34;&gt;data source configuration&lt;/a&gt; or the panel&amp;rsquo;s query options.&lt;/p&gt;
&lt;h3 id=&#34;macro-behavior&#34;&gt;Macro behavior&lt;/h3&gt;
&lt;p&gt;Keep the following behavior in mind when using macros:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Comment stripping:&lt;/strong&gt; Grafana strips SQL comments (&lt;code&gt;--&lt;/code&gt; line comments and &lt;code&gt;/* */&lt;/code&gt; block comments) before expanding macros. Macros placed inside comments aren&amp;rsquo;t expanded.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;TimescaleDB mode:&lt;/strong&gt; When the &lt;strong&gt;TimescaleDB&lt;/strong&gt; toggle is enabled in the data source configuration, &lt;code&gt;$__timeGroup&lt;/code&gt; and &lt;code&gt;$__timeGroupAlias&lt;/code&gt; use PostgreSQL&amp;rsquo;s &lt;code&gt;time_bucket()&lt;/code&gt; function instead of &lt;code&gt;floor(extract(epoch ...))&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Trailing comma pattern:&lt;/strong&gt; A &lt;code&gt;$__timeGroup(...)&lt;/code&gt; call followed immediately by a comma (&lt;code&gt;,&lt;/code&gt;) is automatically treated as &lt;code&gt;$__timeGroupAlias(...)&lt;/code&gt;, adding the &lt;code&gt;AS &amp;quot;time&amp;quot;&lt;/code&gt; alias. This is a legacy convenience—use &lt;code&gt;$__timeGroupAlias&lt;/code&gt; explicitly for clarity.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Inspect expanded SQL:&lt;/strong&gt; To view the final SQL after macro expansion, open the 
    &lt;a href=&#34;/docs/grafana/v13.1/panels-visualizations/query-transform-data/#query-inspector&#34;&gt;Query inspector&lt;/a&gt; in a panel and check the query that was sent to the database.&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&#34;table-queries&#34;&gt;Table queries&lt;/h2&gt;
&lt;p&gt;If the &lt;strong&gt;Format&lt;/strong&gt; option is set to &lt;strong&gt;Table&lt;/strong&gt;, you can execute virtually any type of SQL query. The Table panel automatically displays the resulting columns and rows from your query.&lt;/p&gt;
&lt;p&gt;&lt;img
  class=&#34;lazyload d-inline-block&#34;
  data-src=&#34;/media/docs/postgres/PostgreSQL-query-editor-v11.4.png&#34;
  alt=&#34;Table query&#34; width=&#34;1305&#34;
     height=&#34;513&#34;/&gt;&lt;/p&gt;
&lt;p&gt;You can change or customize the name of a Table panel column by using the SQL keyword &lt;code&gt;AS&lt;/code&gt; syntax.&lt;/p&gt;

&lt;div class=&#34;code-snippet &#34;&gt;&lt;div class=&#34;lang-toolbar&#34;&gt;
    &lt;span class=&#34;lang-toolbar__item lang-toolbar__item-active&#34;&gt;SQL&lt;/span&gt;
    &lt;span class=&#34;code-clipboard&#34;&gt;
      &lt;button x-data=&#34;app_code_snippet()&#34; x-init=&#34;init()&#34; @click=&#34;copy()&#34;&gt;
        &lt;img class=&#34;code-clipboard__icon&#34; src=&#34;/media/images/icons/icon-copy-small-2.svg&#34; alt=&#34;Copy code to clipboard&#34; width=&#34;14&#34; height=&#34;13&#34;&gt;
        &lt;span&gt;Copy&lt;/span&gt;
      &lt;/button&gt;
    &lt;/span&gt;
    &lt;div class=&#34;lang-toolbar__border&#34;&gt;&lt;/div&gt;
  &lt;/div&gt;&lt;div class=&#34;code-snippet &#34;&gt;
    &lt;pre data-expanded=&#34;false&#34;&gt;&lt;code class=&#34;language-sql&#34;&gt;SELECT
  title as &amp;#34;Title&amp;#34;,
  &amp;#34;user&amp;#34;.login as &amp;#34;Created By&amp;#34;,
  dashboard.created as &amp;#34;Created On&amp;#34;
FROM dashboard
INNER JOIN &amp;#34;user&amp;#34; on &amp;#34;user&amp;#34;.id = dashboard.created_by
WHERE $__timeFilter(dashboard.created)&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;You can use 
    &lt;a href=&#34;/docs/grafana/v13.1/datasources/postgres/template-variables/&#34;&gt;template variables&lt;/a&gt; in queries to create dynamic, reusable dashboards. For example, to filter by a variable named &lt;code&gt;hostname&lt;/code&gt;:&lt;/p&gt;

&lt;div class=&#34;code-snippet &#34;&gt;&lt;div class=&#34;lang-toolbar&#34;&gt;
    &lt;span class=&#34;lang-toolbar__item lang-toolbar__item-active&#34;&gt;SQL&lt;/span&gt;
    &lt;span class=&#34;code-clipboard&#34;&gt;
      &lt;button x-data=&#34;app_code_snippet()&#34; x-init=&#34;init()&#34; @click=&#34;copy()&#34;&gt;
        &lt;img class=&#34;code-clipboard__icon&#34; src=&#34;/media/images/icons/icon-copy-small-2.svg&#34; alt=&#34;Copy code to clipboard&#34; width=&#34;14&#34; height=&#34;13&#34;&gt;
        &lt;span&gt;Copy&lt;/span&gt;
      &lt;/button&gt;
    &lt;/span&gt;
    &lt;div class=&#34;lang-toolbar__border&#34;&gt;&lt;/div&gt;
  &lt;/div&gt;&lt;div class=&#34;code-snippet &#34;&gt;
    &lt;pre data-expanded=&#34;false&#34;&gt;&lt;code class=&#34;language-sql&#34;&gt;SELECT
  $__time(&amp;#34;time_date_time&amp;#34;),
  value_double AS value,
  hostname
FROM test_data
WHERE
  $__timeFilter(&amp;#34;time_date_time&amp;#34;)
  AND hostname IN($hostname)
ORDER BY time&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;For more information on creating and using template variables with PostgreSQL, refer to 
    &lt;a href=&#34;/docs/grafana/v13.1/datasources/postgres/template-variables/&#34;&gt;PostgreSQL template variables&lt;/a&gt;.&lt;/p&gt;
&lt;h3 id=&#34;table-query-with-time-range-columns&#34;&gt;Table query with time range columns&lt;/h3&gt;
&lt;p&gt;Table format queries support a &lt;code&gt;timeend&lt;/code&gt; column in addition to the &lt;code&gt;time&lt;/code&gt; column. When both are present, Grafana treats the row as a time range rather than a single point. This is useful for displaying events with duration, such as maintenance windows or deployments.&lt;/p&gt;

&lt;div class=&#34;code-snippet &#34;&gt;&lt;div class=&#34;lang-toolbar&#34;&gt;
    &lt;span class=&#34;lang-toolbar__item lang-toolbar__item-active&#34;&gt;SQL&lt;/span&gt;
    &lt;span class=&#34;code-clipboard&#34;&gt;
      &lt;button x-data=&#34;app_code_snippet()&#34; x-init=&#34;init()&#34; @click=&#34;copy()&#34;&gt;
        &lt;img class=&#34;code-clipboard__icon&#34; src=&#34;/media/images/icons/icon-copy-small-2.svg&#34; alt=&#34;Copy code to clipboard&#34; width=&#34;14&#34; height=&#34;13&#34;&gt;
        &lt;span&gt;Copy&lt;/span&gt;
      &lt;/button&gt;
    &lt;/span&gt;
    &lt;div class=&#34;lang-toolbar__border&#34;&gt;&lt;/div&gt;
  &lt;/div&gt;&lt;div class=&#34;code-snippet &#34;&gt;
    &lt;pre data-expanded=&#34;false&#34;&gt;&lt;code class=&#34;language-sql&#34;&gt;SELECT
  start_time AS &amp;#34;time&amp;#34;,
  end_time AS &amp;#34;timeend&amp;#34;,
  description,
  status
FROM maintenance_windows
WHERE $__timeFilter(start_time)&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;h2 id=&#34;time-series-queries&#34;&gt;Time series queries&lt;/h2&gt;
&lt;p&gt;Set the &lt;strong&gt;Format&lt;/strong&gt; option to &lt;strong&gt;Time series&lt;/strong&gt; to create and run time series queries.&lt;/p&gt;


&lt;div class=&#34;admonition admonition-note&#34;&gt;&lt;blockquote&gt;&lt;p class=&#34;title text-uppercase&#34;&gt;Note&lt;/p&gt;&lt;p&gt;To run a time series query you must include a column named &lt;code&gt;time&lt;/code&gt; that returns either a SQL &lt;code&gt;datetime&lt;/code&gt; value or a numeric datatype representing the UNIX epoch time in seconds. Additionally, the query results must be sorted by the &lt;code&gt;time&lt;/code&gt; column for proper visualization in panels.&lt;/p&gt;&lt;/blockquote&gt;&lt;/div&gt;

&lt;p&gt;The examples in this section refer to the data in the following table:&lt;/p&gt;

&lt;div class=&#34;code-snippet &#34;&gt;&lt;div class=&#34;lang-toolbar&#34;&gt;
    &lt;span class=&#34;lang-toolbar__item lang-toolbar__item-active&#34;&gt;text&lt;/span&gt;
    &lt;span class=&#34;code-clipboard&#34;&gt;
      &lt;button x-data=&#34;app_code_snippet()&#34; x-init=&#34;init()&#34; @click=&#34;copy()&#34;&gt;
        &lt;img class=&#34;code-clipboard__icon&#34; src=&#34;/media/images/icons/icon-copy-small-2.svg&#34; alt=&#34;Copy code to clipboard&#34; width=&#34;14&#34; height=&#34;13&#34;&gt;
        &lt;span&gt;Copy&lt;/span&gt;
      &lt;/button&gt;
    &lt;/span&gt;
    &lt;div class=&#34;lang-toolbar__border&#34;&gt;&lt;/div&gt;
  &lt;/div&gt;&lt;div class=&#34;code-snippet &#34;&gt;
    &lt;pre data-expanded=&#34;false&#34;&gt;&lt;code class=&#34;language-text&#34;&gt;&amp;#43;---------------------&amp;#43;--------------&amp;#43;---------------------&amp;#43;----------&amp;#43;
| time_date_time      | value_double | CreatedAt           | hostname |
&amp;#43;---------------------&amp;#43;--------------&amp;#43;---------------------&amp;#43;----------&amp;#43;
| 2020-01-02 03:05:00 | 3.0          | 2020-01-02 03:05:00 | 10.0.1.1 |
| 2020-01-02 03:06:00 | 4.0          | 2020-01-02 03:06:00 | 10.0.1.2 |
| 2020-01-02 03:10:00 | 6.0          | 2020-01-02 03:10:00 | 10.0.1.1 |
| 2020-01-02 03:11:00 | 7.0          | 2020-01-02 03:11:00 | 10.0.1.2 |
| 2020-01-02 03:20:00 | 5.0          | 2020-01-02 03:20:00 | 10.0.1.2 |
&amp;#43;---------------------&amp;#43;--------------&amp;#43;---------------------&amp;#43;----------&amp;#43;&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;Time series query results are returned in &lt;a href=&#34;/developers/plugin-tools/key-concepts/data-frames#wide-format&#34;&gt;wide data frame format&lt;/a&gt;. In the data frame query result, any column, except for time or string-type columns, transforms into value fields. String columns become field labels.&lt;/p&gt;
&lt;h3 id=&#34;metric-column-detection&#34;&gt;Metric column detection&lt;/h3&gt;
&lt;p&gt;The PostgreSQL plugin identifies &lt;strong&gt;string-type columns&lt;/strong&gt; (&lt;code&gt;text&lt;/code&gt;, &lt;code&gt;varchar&lt;/code&gt;, &lt;code&gt;char&lt;/code&gt;, &lt;code&gt;bpchar&lt;/code&gt;) as label columns that split the result into multiple series. Numeric and time columns become value fields.&lt;/p&gt;


&lt;div class=&#34;admonition admonition-note&#34;&gt;&lt;blockquote&gt;&lt;p class=&#34;title text-uppercase&#34;&gt;Note&lt;/p&gt;&lt;p&gt;For backward compatibility, an exception to this rule applies to queries that return three columns, one of which is a string column named &lt;code&gt;metric&lt;/code&gt;. Instead of converting the metric column into field labels, it&amp;rsquo;s used as the field name, while the series name is set to its value. Refer to the following example.&lt;/p&gt;&lt;/blockquote&gt;&lt;/div&gt;

&lt;h3 id=&#34;fill-missing-time-series-points&#34;&gt;Fill missing time series points&lt;/h3&gt;
&lt;p&gt;When using &lt;code&gt;$__timeGroup&lt;/code&gt; or &lt;code&gt;$__unixEpochGroup&lt;/code&gt; with a fill parameter (the third argument), Grafana fills gaps in your time series data. This is useful when your data has irregular intervals or missing data points. Fill only works with time series format queries.&lt;/p&gt;
&lt;p&gt;The available fill modes are:&lt;/p&gt;
&lt;section class=&#34;expand-table-wrapper&#34;&gt;&lt;div class=&#34;button-div&#34;&gt;
      &lt;button class=&#34;expand-table-btn&#34;&gt;Expand table&lt;/button&gt;
    &lt;/div&gt;&lt;div class=&#34;responsive-table-wrapper&#34;&gt;
    &lt;table&gt;
      &lt;thead&gt;
          &lt;tr&gt;
              &lt;th&gt;Fill mode&lt;/th&gt;
              &lt;th&gt;Behavior&lt;/th&gt;
          &lt;/tr&gt;
      &lt;/thead&gt;
      &lt;tbody&gt;
          &lt;tr&gt;
              &lt;td&gt;&lt;code&gt;0&lt;/code&gt; (or any number)&lt;/td&gt;
              &lt;td&gt;Missing points are filled with the specified numeric value.&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;&lt;code&gt;NULL&lt;/code&gt;&lt;/td&gt;
              &lt;td&gt;Missing points are filled with &lt;code&gt;NULL&lt;/code&gt;, which creates gaps in line charts.&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;&lt;code&gt;previous&lt;/code&gt;&lt;/td&gt;
              &lt;td&gt;Missing points use the last known value. If no previous value exists, &lt;code&gt;NULL&lt;/code&gt; is used.&lt;/td&gt;
          &lt;/tr&gt;
      &lt;/tbody&gt;
    &lt;/table&gt;
  &lt;/div&gt;
&lt;/section&gt;&lt;p&gt;For example, &lt;code&gt;$__timeGroupAlias(&amp;quot;CreatedAt&amp;quot;,&#39;5m&#39;, 0)&lt;/code&gt; groups data into 5-minute intervals and fills any gaps with &lt;code&gt;0&lt;/code&gt;.&lt;/p&gt;
&lt;h3 id=&#34;row-limits&#34;&gt;Row limits&lt;/h3&gt;
&lt;p&gt;Grafana applies a server-side row limit to query results to protect against excessive memory usage. If your query returns more rows than the limit, the result is truncated. To reduce the number of rows returned, narrow the dashboard time range, increase the &lt;code&gt;$__timeGroup&lt;/code&gt; interval, or add a &lt;code&gt;LIMIT&lt;/code&gt; clause to your query.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Example with &lt;code&gt;metric&lt;/code&gt; column:&lt;/strong&gt;&lt;/p&gt;

&lt;div class=&#34;code-snippet &#34;&gt;&lt;div class=&#34;lang-toolbar&#34;&gt;
    &lt;span class=&#34;lang-toolbar__item lang-toolbar__item-active&#34;&gt;SQL&lt;/span&gt;
    &lt;span class=&#34;code-clipboard&#34;&gt;
      &lt;button x-data=&#34;app_code_snippet()&#34; x-init=&#34;init()&#34; @click=&#34;copy()&#34;&gt;
        &lt;img class=&#34;code-clipboard__icon&#34; src=&#34;/media/images/icons/icon-copy-small-2.svg&#34; alt=&#34;Copy code to clipboard&#34; width=&#34;14&#34; height=&#34;13&#34;&gt;
        &lt;span&gt;Copy&lt;/span&gt;
      &lt;/button&gt;
    &lt;/span&gt;
    &lt;div class=&#34;lang-toolbar__border&#34;&gt;&lt;/div&gt;
  &lt;/div&gt;&lt;div class=&#34;code-snippet &#34;&gt;
    &lt;pre data-expanded=&#34;false&#34;&gt;&lt;code class=&#34;language-sql&#34;&gt;SELECT
  $__timeGroupAlias(&amp;#34;time_date_time&amp;#34;,&amp;#39;5m&amp;#39;),
  min(&amp;#34;value_double&amp;#34;),
  &amp;#39;min&amp;#39; as metric
FROM test_data
WHERE $__timeFilter(&amp;#34;time_date_time&amp;#34;)
GROUP BY time
ORDER BY time&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;Data frame result:&lt;/p&gt;

&lt;div class=&#34;code-snippet &#34;&gt;&lt;div class=&#34;lang-toolbar&#34;&gt;
    &lt;span class=&#34;lang-toolbar__item lang-toolbar__item-active&#34;&gt;text&lt;/span&gt;
    &lt;span class=&#34;code-clipboard&#34;&gt;
      &lt;button x-data=&#34;app_code_snippet()&#34; x-init=&#34;init()&#34; @click=&#34;copy()&#34;&gt;
        &lt;img class=&#34;code-clipboard__icon&#34; src=&#34;/media/images/icons/icon-copy-small-2.svg&#34; alt=&#34;Copy code to clipboard&#34; width=&#34;14&#34; height=&#34;13&#34;&gt;
        &lt;span&gt;Copy&lt;/span&gt;
      &lt;/button&gt;
    &lt;/span&gt;
    &lt;div class=&#34;lang-toolbar__border&#34;&gt;&lt;/div&gt;
  &lt;/div&gt;&lt;div class=&#34;code-snippet &#34;&gt;
    &lt;pre data-expanded=&#34;false&#34;&gt;&lt;code class=&#34;language-text&#34;&gt;&amp;#43;---------------------&amp;#43;-----------------&amp;#43;
| Name: time          | Name: min       |
| Labels:             | Labels:         |
| Type: []time.Time   | Type: []float64 |
&amp;#43;---------------------&amp;#43;-----------------&amp;#43;
| 2020-01-02 03:05:00 | 3               |
| 2020-01-02 03:10:00 | 6               |
&amp;#43;---------------------&amp;#43;-----------------&amp;#43;&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;To customize default series name formatting, refer to 
    &lt;a href=&#34;/docs/grafana/v13.1/panels-visualizations/configure-standard-options/#display-name&#34;&gt;Standard options definitions&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;Following are time series query examples.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Example with no grouping (raw points):&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;To return raw time and value points without grouping, use &lt;code&gt;$__time&lt;/code&gt; to alias your date/time column as &lt;code&gt;time&lt;/code&gt;:&lt;/p&gt;

&lt;div class=&#34;code-snippet &#34;&gt;&lt;div class=&#34;lang-toolbar&#34;&gt;
    &lt;span class=&#34;lang-toolbar__item lang-toolbar__item-active&#34;&gt;SQL&lt;/span&gt;
    &lt;span class=&#34;code-clipboard&#34;&gt;
      &lt;button x-data=&#34;app_code_snippet()&#34; x-init=&#34;init()&#34; @click=&#34;copy()&#34;&gt;
        &lt;img class=&#34;code-clipboard__icon&#34; src=&#34;/media/images/icons/icon-copy-small-2.svg&#34; alt=&#34;Copy code to clipboard&#34; width=&#34;14&#34; height=&#34;13&#34;&gt;
        &lt;span&gt;Copy&lt;/span&gt;
      &lt;/button&gt;
    &lt;/span&gt;
    &lt;div class=&#34;lang-toolbar__border&#34;&gt;&lt;/div&gt;
  &lt;/div&gt;&lt;div class=&#34;code-snippet &#34;&gt;
    &lt;pre data-expanded=&#34;false&#34;&gt;&lt;code class=&#34;language-sql&#34;&gt;SELECT
  $__time(&amp;#34;time_date_time&amp;#34;),
  &amp;#34;value_double&amp;#34; as value
FROM test_data
WHERE $__timeFilter(&amp;#34;time_date_time&amp;#34;)
ORDER BY time&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;&lt;strong&gt;Example using the fill parameter in the $__timeGroupAlias macro to convert null values to zero:&lt;/strong&gt;&lt;/p&gt;

&lt;div class=&#34;code-snippet &#34;&gt;&lt;div class=&#34;lang-toolbar&#34;&gt;
    &lt;span class=&#34;lang-toolbar__item lang-toolbar__item-active&#34;&gt;SQL&lt;/span&gt;
    &lt;span class=&#34;code-clipboard&#34;&gt;
      &lt;button x-data=&#34;app_code_snippet()&#34; x-init=&#34;init()&#34; @click=&#34;copy()&#34;&gt;
        &lt;img class=&#34;code-clipboard__icon&#34; src=&#34;/media/images/icons/icon-copy-small-2.svg&#34; alt=&#34;Copy code to clipboard&#34; width=&#34;14&#34; height=&#34;13&#34;&gt;
        &lt;span&gt;Copy&lt;/span&gt;
      &lt;/button&gt;
    &lt;/span&gt;
    &lt;div class=&#34;lang-toolbar__border&#34;&gt;&lt;/div&gt;
  &lt;/div&gt;&lt;div class=&#34;code-snippet &#34;&gt;
    &lt;pre data-expanded=&#34;false&#34;&gt;&lt;code class=&#34;language-sql&#34;&gt;SELECT
  $__timeGroupAlias(&amp;#34;CreatedAt&amp;#34;,&amp;#39;5m&amp;#39;,0),
  sum(value) as value,
  hostname
FROM test_data
WHERE
  $__timeFilter(&amp;#34;CreatedAt&amp;#34;)
GROUP BY time, hostname
ORDER BY time&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;Based on the data frame result in the following example, the time series panel will generate two series named &lt;em&gt;value 10.0.1.1&lt;/em&gt; and &lt;em&gt;value 10.0.1.2&lt;/em&gt;. To display the series names as &lt;em&gt;10.0.1.1&lt;/em&gt; and &lt;em&gt;10.0.1.2&lt;/em&gt;, use the 
    &lt;a href=&#34;/docs/grafana/v13.1/panels-visualizations/configure-standard-options/#display-name&#34;&gt;Standard options definitions&lt;/a&gt; display value &lt;code&gt;${__field.labels.hostname}&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;Data frame result:&lt;/p&gt;

&lt;div class=&#34;code-snippet &#34;&gt;&lt;div class=&#34;lang-toolbar&#34;&gt;
    &lt;span class=&#34;lang-toolbar__item lang-toolbar__item-active&#34;&gt;text&lt;/span&gt;
    &lt;span class=&#34;code-clipboard&#34;&gt;
      &lt;button x-data=&#34;app_code_snippet()&#34; x-init=&#34;init()&#34; @click=&#34;copy()&#34;&gt;
        &lt;img class=&#34;code-clipboard__icon&#34; src=&#34;/media/images/icons/icon-copy-small-2.svg&#34; alt=&#34;Copy code to clipboard&#34; width=&#34;14&#34; height=&#34;13&#34;&gt;
        &lt;span&gt;Copy&lt;/span&gt;
      &lt;/button&gt;
    &lt;/span&gt;
    &lt;div class=&#34;lang-toolbar__border&#34;&gt;&lt;/div&gt;
  &lt;/div&gt;&lt;div class=&#34;code-snippet &#34;&gt;
    &lt;pre data-expanded=&#34;false&#34;&gt;&lt;code class=&#34;language-text&#34;&gt;&amp;#43;---------------------&amp;#43;---------------------------&amp;#43;---------------------------&amp;#43;
| Name: time          | Name: value               | Name: value               |
| Labels:             | Labels: hostname=10.0.1.1 | Labels: hostname=10.0.1.2 |
| Type: []time.Time   | Type: []float64           | Type: []float64           |
&amp;#43;---------------------&amp;#43;---------------------------&amp;#43;---------------------------&amp;#43;
| 2020-01-02 03:05:00 | 3                         | 4                         |
| 2020-01-02 03:10:00 | 6                         | 7                         |
&amp;#43;---------------------&amp;#43;---------------------------&amp;#43;---------------------------&amp;#43;&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;&lt;strong&gt;Example with multiple columns:&lt;/strong&gt;&lt;/p&gt;

&lt;div class=&#34;code-snippet &#34;&gt;&lt;div class=&#34;lang-toolbar&#34;&gt;
    &lt;span class=&#34;lang-toolbar__item lang-toolbar__item-active&#34;&gt;SQL&lt;/span&gt;
    &lt;span class=&#34;code-clipboard&#34;&gt;
      &lt;button x-data=&#34;app_code_snippet()&#34; x-init=&#34;init()&#34; @click=&#34;copy()&#34;&gt;
        &lt;img class=&#34;code-clipboard__icon&#34; src=&#34;/media/images/icons/icon-copy-small-2.svg&#34; alt=&#34;Copy code to clipboard&#34; width=&#34;14&#34; height=&#34;13&#34;&gt;
        &lt;span&gt;Copy&lt;/span&gt;
      &lt;/button&gt;
    &lt;/span&gt;
    &lt;div class=&#34;lang-toolbar__border&#34;&gt;&lt;/div&gt;
  &lt;/div&gt;&lt;div class=&#34;code-snippet &#34;&gt;
    &lt;pre data-expanded=&#34;false&#34;&gt;&lt;code class=&#34;language-sql&#34;&gt;SELECT
  $__timeGroupAlias(&amp;#34;time_date_time&amp;#34;,&amp;#39;5m&amp;#39;),
  min(&amp;#34;value_double&amp;#34;) as &amp;#34;min_value&amp;#34;,
  max(&amp;#34;value_double&amp;#34;) as &amp;#34;max_value&amp;#34;
FROM test_data
WHERE $__timeFilter(&amp;#34;time_date_time&amp;#34;)
GROUP BY time
ORDER BY time&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;Data frame result:&lt;/p&gt;

&lt;div class=&#34;code-snippet &#34;&gt;&lt;div class=&#34;lang-toolbar&#34;&gt;
    &lt;span class=&#34;lang-toolbar__item lang-toolbar__item-active&#34;&gt;text&lt;/span&gt;
    &lt;span class=&#34;code-clipboard&#34;&gt;
      &lt;button x-data=&#34;app_code_snippet()&#34; x-init=&#34;init()&#34; @click=&#34;copy()&#34;&gt;
        &lt;img class=&#34;code-clipboard__icon&#34; src=&#34;/media/images/icons/icon-copy-small-2.svg&#34; alt=&#34;Copy code to clipboard&#34; width=&#34;14&#34; height=&#34;13&#34;&gt;
        &lt;span&gt;Copy&lt;/span&gt;
      &lt;/button&gt;
    &lt;/span&gt;
    &lt;div class=&#34;lang-toolbar__border&#34;&gt;&lt;/div&gt;
  &lt;/div&gt;&lt;div class=&#34;code-snippet &#34;&gt;
    &lt;pre data-expanded=&#34;false&#34;&gt;&lt;code class=&#34;language-text&#34;&gt;&amp;#43;---------------------&amp;#43;-----------------&amp;#43;-----------------&amp;#43;
| Name: time          | Name: min_value | Name: max_value |
| Labels:             | Labels:         | Labels:         |
| Type: []time.Time   | Type: []float64 | Type: []float64 |
&amp;#43;---------------------&amp;#43;-----------------&amp;#43;-----------------&amp;#43;
| 2020-01-02 03:04:00 | 3               | 4               |
| 2020-01-02 03:05:00 | 6               | 7               |
&amp;#43;---------------------&amp;#43;-----------------&amp;#43;-----------------&amp;#43;&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;&lt;strong&gt;Example with UNIX epoch time column:&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;When your time column stores UNIX epoch (seconds), use &lt;code&gt;$__timeEpoch&lt;/code&gt; to alias it as &lt;code&gt;time&lt;/code&gt; and &lt;code&gt;$__unixEpochFilter&lt;/code&gt; in the WHERE clause:&lt;/p&gt;

&lt;div class=&#34;code-snippet &#34;&gt;&lt;div class=&#34;lang-toolbar&#34;&gt;
    &lt;span class=&#34;lang-toolbar__item lang-toolbar__item-active&#34;&gt;SQL&lt;/span&gt;
    &lt;span class=&#34;code-clipboard&#34;&gt;
      &lt;button x-data=&#34;app_code_snippet()&#34; x-init=&#34;init()&#34; @click=&#34;copy()&#34;&gt;
        &lt;img class=&#34;code-clipboard__icon&#34; src=&#34;/media/images/icons/icon-copy-small-2.svg&#34; alt=&#34;Copy code to clipboard&#34; width=&#34;14&#34; height=&#34;13&#34;&gt;
        &lt;span&gt;Copy&lt;/span&gt;
      &lt;/button&gt;
    &lt;/span&gt;
    &lt;div class=&#34;lang-toolbar__border&#34;&gt;&lt;/div&gt;
  &lt;/div&gt;&lt;div class=&#34;code-snippet &#34;&gt;
    &lt;pre data-expanded=&#34;false&#34;&gt;&lt;code class=&#34;language-sql&#34;&gt;SELECT
  $__timeEpoch(epoch_seconds_column),
  value_column as value
FROM my_table
WHERE $__unixEpochFilter(epoch_seconds_column)
ORDER BY time&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;For grouped time series with epoch columns, use &lt;code&gt;$__unixEpochGroupAlias&lt;/code&gt; and &lt;code&gt;$__unixEpochFilter&lt;/code&gt;. Refer to the &lt;a href=&#34;#macros&#34;&gt;Macros&lt;/a&gt; table for details.&lt;/p&gt;
&lt;h2 id=&#34;explain-queries&#34;&gt;EXPLAIN queries&lt;/h2&gt;
&lt;p&gt;You can run &lt;code&gt;EXPLAIN&lt;/code&gt; and &lt;code&gt;EXPLAIN ANALYZE&lt;/code&gt; queries in Code mode to inspect query execution plans. The results are returned as a table, which is useful for diagnosing slow queries directly within Grafana.&lt;/p&gt;

&lt;div class=&#34;code-snippet &#34;&gt;&lt;div class=&#34;lang-toolbar&#34;&gt;
    &lt;span class=&#34;lang-toolbar__item lang-toolbar__item-active&#34;&gt;SQL&lt;/span&gt;
    &lt;span class=&#34;code-clipboard&#34;&gt;
      &lt;button x-data=&#34;app_code_snippet()&#34; x-init=&#34;init()&#34; @click=&#34;copy()&#34;&gt;
        &lt;img class=&#34;code-clipboard__icon&#34; src=&#34;/media/images/icons/icon-copy-small-2.svg&#34; alt=&#34;Copy code to clipboard&#34; width=&#34;14&#34; height=&#34;13&#34;&gt;
        &lt;span&gt;Copy&lt;/span&gt;
      &lt;/button&gt;
    &lt;/span&gt;
    &lt;div class=&#34;lang-toolbar__border&#34;&gt;&lt;/div&gt;
  &lt;/div&gt;&lt;div class=&#34;code-snippet &#34;&gt;
    &lt;pre data-expanded=&#34;false&#34;&gt;&lt;code class=&#34;language-sql&#34;&gt;EXPLAIN ANALYZE
SELECT
  $__timeGroupAlias(&amp;#34;time_date_time&amp;#34;, &amp;#39;5m&amp;#39;),
  avg(&amp;#34;value_double&amp;#34;) AS value
FROM test_data
WHERE $__timeFilter(&amp;#34;time_date_time&amp;#34;)
GROUP BY time
ORDER BY time&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;Grafana macros are expanded before the query runs, so you can use &lt;code&gt;$__timeFilter&lt;/code&gt; and other macros in your &lt;code&gt;EXPLAIN&lt;/code&gt; queries to see the actual execution plan for the dashboard&amp;rsquo;s time range. Set the &lt;strong&gt;Format&lt;/strong&gt; to &lt;strong&gt;Table&lt;/strong&gt; to display the plan output.&lt;/p&gt;
&lt;h2 id=&#34;next-steps&#34;&gt;Next steps&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;Use 
    &lt;a href=&#34;/docs/grafana/v13.1/datasources/postgres/template-variables/&#34;&gt;template variables&lt;/a&gt; to create dynamic, reusable dashboards.&lt;/li&gt;
&lt;li&gt;Add 
    &lt;a href=&#34;/docs/grafana/v13.1/datasources/postgres/annotations/&#34;&gt;annotations&lt;/a&gt; from PostgreSQL to overlay events on your panels.&lt;/li&gt;
&lt;li&gt;
    &lt;a href=&#34;/docs/grafana/v13.1/datasources/postgres/alerting/&#34;&gt;Set up alerting&lt;/a&gt; to get notified when metrics cross thresholds (time series format only).&lt;/li&gt;
&lt;li&gt;
    &lt;a href=&#34;/docs/grafana/v13.1/datasources/postgres/troubleshooting/&#34;&gt;Troubleshoot&lt;/a&gt; issues if you encounter problems with queries.&lt;/li&gt;
&lt;/ul&gt;
]]></content><description>&lt;h1 id="postgresql-query-editor">PostgreSQL query editor&lt;/h1>
&lt;p>The PostgreSQL query editor lets you build and run queries against your data source. For general query editor and data transformation concepts, refer to
&lt;a href="/docs/grafana/v13.1/panels-visualizations/query-transform-data/">Query and transform data&lt;/a>.&lt;/p></description></item><item><title>PostgreSQL template variables</title><link>https://grafana.com/docs/grafana/v13.1/datasources/postgres/template-variables/</link><pubDate>Tue, 23 Jun 2026 13:06:40 +0000</pubDate><guid>https://grafana.com/docs/grafana/v13.1/datasources/postgres/template-variables/</guid><content><![CDATA[&lt;h1 id=&#34;postgresql-template-variables&#34;&gt;PostgreSQL template variables&lt;/h1&gt;
&lt;p&gt;Instead of hard-coding details such as server, application, and sensor names in metric queries, you can use variables.
Grafana displays these variables in drop-down select boxes at the top of the dashboard to help you change the data displayed in your dashboard.
Grafana refers to such variables as &lt;strong&gt;template variables&lt;/strong&gt;.&lt;/p&gt;
&lt;p&gt;For an introduction to templating and template variables, refer to 
    &lt;a href=&#34;/docs/grafana/v13.1/dashboards/variables/&#34;&gt;Templating&lt;/a&gt; and 
    &lt;a href=&#34;/docs/grafana/v13.1/dashboards/variables/add-template-variables/&#34;&gt;Add and manage variables&lt;/a&gt;.&lt;/p&gt;
&lt;h2 id=&#34;query-variable&#34;&gt;Query variable&lt;/h2&gt;
&lt;p&gt;A query variable in Grafana dynamically retrieves values from your data source using a query. With a query variable, you can write a PostgreSQL query that returns values such as measurement names, key names, or key values that are shown in a drop-down select box.&lt;/p&gt;
&lt;p&gt;The PostgreSQL data source includes a dedicated variable query editor with the full SQL editor (Code mode with auto-completion and syntax highlighting) and &lt;strong&gt;Value Field&lt;/strong&gt; / &lt;strong&gt;Text Field&lt;/strong&gt; drop-downs. After you write and run a query, the editor automatically detects the returned columns and populates the field drop-downs so you can map which column provides the variable value and which provides the display label.&lt;/p&gt;
&lt;p&gt;To create a query variable:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;Navigate to &lt;strong&gt;Dashboard settings&lt;/strong&gt; &amp;gt; &lt;strong&gt;Variables&lt;/strong&gt;.&lt;/li&gt;
&lt;li&gt;Click &lt;strong&gt;Add variable&lt;/strong&gt;.&lt;/li&gt;
&lt;li&gt;Select &lt;strong&gt;Query&lt;/strong&gt; as the variable type.&lt;/li&gt;
&lt;li&gt;Select your PostgreSQL data source.&lt;/li&gt;
&lt;li&gt;Write a SQL query in the editor. Macros like &lt;code&gt;$__timeFilter&lt;/code&gt; are supported.&lt;/li&gt;
&lt;li&gt;Optionally set &lt;strong&gt;Value Field&lt;/strong&gt; and &lt;strong&gt;Text Field&lt;/strong&gt; to control which columns map to the variable value and display label.&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;For example, the following query returns all values from the &lt;code&gt;hostname&lt;/code&gt; column:&lt;/p&gt;

&lt;div class=&#34;code-snippet &#34;&gt;&lt;div class=&#34;lang-toolbar&#34;&gt;
    &lt;span class=&#34;lang-toolbar__item lang-toolbar__item-active&#34;&gt;SQL&lt;/span&gt;
    &lt;span class=&#34;code-clipboard&#34;&gt;
      &lt;button x-data=&#34;app_code_snippet()&#34; x-init=&#34;init()&#34; @click=&#34;copy()&#34;&gt;
        &lt;img class=&#34;code-clipboard__icon&#34; src=&#34;/media/images/icons/icon-copy-small-2.svg&#34; alt=&#34;Copy code to clipboard&#34; width=&#34;14&#34; height=&#34;13&#34;&gt;
        &lt;span&gt;Copy&lt;/span&gt;
      &lt;/button&gt;
    &lt;/span&gt;
    &lt;div class=&#34;lang-toolbar__border&#34;&gt;&lt;/div&gt;
  &lt;/div&gt;&lt;div class=&#34;code-snippet &#34;&gt;
    &lt;pre data-expanded=&#34;false&#34;&gt;&lt;code class=&#34;language-sql&#34;&gt;SELECT hostname FROM host&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;A query can return multiple columns, and Grafana automatically generates a list using the values from those columns. For example, the following query returns values from both the &lt;code&gt;hostname&lt;/code&gt; and &lt;code&gt;hostname2&lt;/code&gt; columns, which are included in the variable&amp;rsquo;s drop-down list.&lt;/p&gt;

&lt;div class=&#34;code-snippet &#34;&gt;&lt;div class=&#34;lang-toolbar&#34;&gt;
    &lt;span class=&#34;lang-toolbar__item lang-toolbar__item-active&#34;&gt;SQL&lt;/span&gt;
    &lt;span class=&#34;code-clipboard&#34;&gt;
      &lt;button x-data=&#34;app_code_snippet()&#34; x-init=&#34;init()&#34; @click=&#34;copy()&#34;&gt;
        &lt;img class=&#34;code-clipboard__icon&#34; src=&#34;/media/images/icons/icon-copy-small-2.svg&#34; alt=&#34;Copy code to clipboard&#34; width=&#34;14&#34; height=&#34;13&#34;&gt;
        &lt;span&gt;Copy&lt;/span&gt;
      &lt;/button&gt;
    &lt;/span&gt;
    &lt;div class=&#34;lang-toolbar__border&#34;&gt;&lt;/div&gt;
  &lt;/div&gt;&lt;div class=&#34;code-snippet &#34;&gt;
    &lt;pre data-expanded=&#34;false&#34;&gt;&lt;code class=&#34;language-sql&#34;&gt;SELECT host.hostname, other_host.hostname2 FROM host JOIN other_host ON host.city = other_host.city&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;To use time range dependent macros like &lt;code&gt;$__timeFilter(column)&lt;/code&gt; in your query, you must set the template variable&amp;rsquo;s refresh mode to &lt;strong&gt;On Time Range Change&lt;/strong&gt;.&lt;/p&gt;

&lt;div class=&#34;code-snippet &#34;&gt;&lt;div class=&#34;lang-toolbar&#34;&gt;
    &lt;span class=&#34;lang-toolbar__item lang-toolbar__item-active&#34;&gt;SQL&lt;/span&gt;
    &lt;span class=&#34;code-clipboard&#34;&gt;
      &lt;button x-data=&#34;app_code_snippet()&#34; x-init=&#34;init()&#34; @click=&#34;copy()&#34;&gt;
        &lt;img class=&#34;code-clipboard__icon&#34; src=&#34;/media/images/icons/icon-copy-small-2.svg&#34; alt=&#34;Copy code to clipboard&#34; width=&#34;14&#34; height=&#34;13&#34;&gt;
        &lt;span&gt;Copy&lt;/span&gt;
      &lt;/button&gt;
    &lt;/span&gt;
    &lt;div class=&#34;lang-toolbar__border&#34;&gt;&lt;/div&gt;
  &lt;/div&gt;&lt;div class=&#34;code-snippet &#34;&gt;
    &lt;pre data-expanded=&#34;false&#34;&gt;&lt;code class=&#34;language-sql&#34;&gt;SELECT event_name FROM event_log WHERE $__timeFilter(time_column)&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;h3 id=&#34;keyvalue-variables&#34;&gt;Key/value variables&lt;/h3&gt;
&lt;p&gt;You can create a key/value variable so the drop-down shows a user-friendly label (for example, hostname) while panel queries use a different value (for example, ID). Use the variable editor’s &lt;strong&gt;Value field&lt;/strong&gt; and &lt;strong&gt;Text field&lt;/strong&gt; at the bottom of the query section to specify which query columns supply the value and the label. Your query can use any column names; you do not need &lt;code&gt;__value&lt;/code&gt; or &lt;code&gt;__text&lt;/code&gt; in the SQL.&lt;/p&gt;
&lt;p&gt;Example: run a query that returns &lt;code&gt;hostname&lt;/code&gt; and &lt;code&gt;id&lt;/code&gt;, then set &lt;strong&gt;Text field&lt;/strong&gt; to &lt;code&gt;hostname&lt;/code&gt; and &lt;strong&gt;Value field&lt;/strong&gt; to &lt;code&gt;id&lt;/code&gt;.&lt;/p&gt;

&lt;div class=&#34;code-snippet &#34;&gt;&lt;div class=&#34;lang-toolbar&#34;&gt;
    &lt;span class=&#34;lang-toolbar__item lang-toolbar__item-active&#34;&gt;SQL&lt;/span&gt;
    &lt;span class=&#34;code-clipboard&#34;&gt;
      &lt;button x-data=&#34;app_code_snippet()&#34; x-init=&#34;init()&#34; @click=&#34;copy()&#34;&gt;
        &lt;img class=&#34;code-clipboard__icon&#34; src=&#34;/media/images/icons/icon-copy-small-2.svg&#34; alt=&#34;Copy code to clipboard&#34; width=&#34;14&#34; height=&#34;13&#34;&gt;
        &lt;span&gt;Copy&lt;/span&gt;
      &lt;/button&gt;
    &lt;/span&gt;
    &lt;div class=&#34;lang-toolbar__border&#34;&gt;&lt;/div&gt;
  &lt;/div&gt;&lt;div class=&#34;code-snippet &#34;&gt;
    &lt;pre data-expanded=&#34;false&#34;&gt;&lt;code class=&#34;language-sql&#34;&gt;SELECT hostname, id FROM host&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;Note that the values in the text column should be unique. If there are duplicates, Grafana uses only the first matching entry.&lt;/p&gt;
&lt;p&gt;Alternatively, you can use the legacy approach: return columns named &lt;code&gt;__text&lt;/code&gt; and &lt;code&gt;__value&lt;/code&gt; in your query (for example, &lt;code&gt;SELECT hostname AS __text, id AS __value FROM host&lt;/code&gt;).&lt;/p&gt;
&lt;h3 id=&#34;nested-variables&#34;&gt;Nested variables&lt;/h3&gt;
&lt;p&gt;You can create nested variables, where one variable depends on the value of another. For example, if you have a variable named &lt;code&gt;region&lt;/code&gt;, you can configure a &lt;code&gt;hosts&lt;/code&gt; variable to only show hosts from the selected region. If &lt;code&gt;region&lt;/code&gt; is a multi-value variable, use the &lt;code&gt;IN&lt;/code&gt; operator instead of &lt;code&gt;=&lt;/code&gt; to match against multiple selected values.&lt;/p&gt;

&lt;div class=&#34;code-snippet &#34;&gt;&lt;div class=&#34;lang-toolbar&#34;&gt;
    &lt;span class=&#34;lang-toolbar__item lang-toolbar__item-active&#34;&gt;SQL&lt;/span&gt;
    &lt;span class=&#34;code-clipboard&#34;&gt;
      &lt;button x-data=&#34;app_code_snippet()&#34; x-init=&#34;init()&#34; @click=&#34;copy()&#34;&gt;
        &lt;img class=&#34;code-clipboard__icon&#34; src=&#34;/media/images/icons/icon-copy-small-2.svg&#34; alt=&#34;Copy code to clipboard&#34; width=&#34;14&#34; height=&#34;13&#34;&gt;
        &lt;span&gt;Copy&lt;/span&gt;
      &lt;/button&gt;
    &lt;/span&gt;
    &lt;div class=&#34;lang-toolbar__border&#34;&gt;&lt;/div&gt;
  &lt;/div&gt;&lt;div class=&#34;code-snippet &#34;&gt;
    &lt;pre data-expanded=&#34;false&#34;&gt;&lt;code class=&#34;language-sql&#34;&gt;SELECT hostname FROM host WHERE region IN($region)&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;h3 id=&#34;filter-results-with-__searchfilter&#34;&gt;Filter results with &lt;code&gt;__searchFilter&lt;/code&gt;&lt;/h3&gt;
&lt;p&gt;Using &lt;code&gt;__searchFilter&lt;/code&gt; in the query field filters the query results based on user input in the drop-down selection box. If nothing is entered, the default value for &lt;code&gt;__searchFilter&lt;/code&gt; is &lt;code&gt;%&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;You must enclose the &lt;code&gt;__searchFilter&lt;/code&gt; expression in quotes because Grafana doesn&amp;rsquo;t add them automatically.&lt;/p&gt;
&lt;p&gt;The following example enables real-time searching for &lt;code&gt;hostname&lt;/code&gt; as the user types in the drop-down selection box:&lt;/p&gt;

&lt;div class=&#34;code-snippet &#34;&gt;&lt;div class=&#34;lang-toolbar&#34;&gt;
    &lt;span class=&#34;lang-toolbar__item lang-toolbar__item-active&#34;&gt;SQL&lt;/span&gt;
    &lt;span class=&#34;code-clipboard&#34;&gt;
      &lt;button x-data=&#34;app_code_snippet()&#34; x-init=&#34;init()&#34; @click=&#34;copy()&#34;&gt;
        &lt;img class=&#34;code-clipboard__icon&#34; src=&#34;/media/images/icons/icon-copy-small-2.svg&#34; alt=&#34;Copy code to clipboard&#34; width=&#34;14&#34; height=&#34;13&#34;&gt;
        &lt;span&gt;Copy&lt;/span&gt;
      &lt;/button&gt;
    &lt;/span&gt;
    &lt;div class=&#34;lang-toolbar__border&#34;&gt;&lt;/div&gt;
  &lt;/div&gt;&lt;div class=&#34;code-snippet &#34;&gt;
    &lt;pre data-expanded=&#34;false&#34;&gt;&lt;code class=&#34;language-sql&#34;&gt;SELECT hostname FROM host WHERE hostname LIKE &amp;#39;$__searchFilter&amp;#39;&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;For tables with a large number of rows, combine &lt;code&gt;__searchFilter&lt;/code&gt; with &lt;code&gt;LIMIT&lt;/code&gt; to keep the drop-down responsive:&lt;/p&gt;

&lt;div class=&#34;code-snippet &#34;&gt;&lt;div class=&#34;lang-toolbar&#34;&gt;
    &lt;span class=&#34;lang-toolbar__item lang-toolbar__item-active&#34;&gt;SQL&lt;/span&gt;
    &lt;span class=&#34;code-clipboard&#34;&gt;
      &lt;button x-data=&#34;app_code_snippet()&#34; x-init=&#34;init()&#34; @click=&#34;copy()&#34;&gt;
        &lt;img class=&#34;code-clipboard__icon&#34; src=&#34;/media/images/icons/icon-copy-small-2.svg&#34; alt=&#34;Copy code to clipboard&#34; width=&#34;14&#34; height=&#34;13&#34;&gt;
        &lt;span&gt;Copy&lt;/span&gt;
      &lt;/button&gt;
    &lt;/span&gt;
    &lt;div class=&#34;lang-toolbar__border&#34;&gt;&lt;/div&gt;
  &lt;/div&gt;&lt;div class=&#34;code-snippet &#34;&gt;
    &lt;pre data-expanded=&#34;false&#34;&gt;&lt;code class=&#34;language-sql&#34;&gt;SELECT DISTINCT hostname
FROM host
WHERE hostname LIKE &amp;#39;$__searchFilter&amp;#39;
ORDER BY hostname
LIMIT 100&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;h3 id=&#34;regex-variable&#34;&gt;Regex variable&lt;/h3&gt;
&lt;p&gt;You can use a &lt;strong&gt;Regex&lt;/strong&gt; type variable to filter or transform values from another variable. For example, if you have a variable named &lt;code&gt;server&lt;/code&gt; that returns values like &lt;code&gt;web-prod-01&lt;/code&gt;, &lt;code&gt;web-staging-01&lt;/code&gt;, and &lt;code&gt;db-prod-01&lt;/code&gt;, you can create a regular expression variable to extract only the environment:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;Create a new variable with &lt;strong&gt;Type: Query&lt;/strong&gt;.&lt;/li&gt;
&lt;li&gt;Set the query to return the raw values.&lt;/li&gt;
&lt;li&gt;In the &lt;strong&gt;Regex&lt;/strong&gt; field, enter a pattern to extract or filter. For example, &lt;code&gt;/^web-(.&#43;)-\d&#43;$/&lt;/code&gt; extracts &lt;code&gt;prod&lt;/code&gt; and &lt;code&gt;staging&lt;/code&gt; from web server names.&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;You can also use regular expression to filter a variable&amp;rsquo;s options. For example, setting the &lt;strong&gt;Regex&lt;/strong&gt; field to &lt;code&gt;/prod/&lt;/code&gt; on a variable that returns all server names limits the drop-down to only production servers.&lt;/p&gt;
&lt;h2 id=&#34;multi-property-variables&#34;&gt;Multi-property variables&lt;/h2&gt;
&lt;p&gt;The PostgreSQL data source supports &lt;strong&gt;multi-property variables&lt;/strong&gt;. Use them when the same logical concept has different identifiers in different contexts (for example, an environment called &lt;code&gt;dev&lt;/code&gt; in one system and &lt;code&gt;development&lt;/code&gt; in another). Instead of maintaining several variables in sync, you can map all of those values to one variable and reference the property you need in each panel or query.&lt;/p&gt;
&lt;figure
    class=&#34;figure-wrapper figure-wrapper__lightbox w-100p &#34;
    style=&#34;max-width: 601px;&#34;
    itemprop=&#34;associatedMedia&#34;
    itemscope=&#34;&#34;
    itemtype=&#34;http://schema.org/ImageObject&#34;
  &gt;&lt;a
        class=&#34;lightbox-link&#34;
        href=&#34;/media/docs/postgres/postgreSQL-multi-prop-variable-v12.3.png&#34;
        itemprop=&#34;contentUrl&#34;
      &gt;&lt;div class=&#34;img-wrapper w-100p h-auto&#34;&gt;&lt;img
          class=&#34;lazyload &#34;
          data-src=&#34;/media/docs/postgres/postgreSQL-multi-prop-variable-v12.3.png&#34;data-srcset=&#34;/media/docs/postgres/postgreSQL-multi-prop-variable-v12.3.png?w=320 320w, /media/docs/postgres/postgreSQL-multi-prop-variable-v12.3.png?w=550 550w, /media/docs/postgres/postgreSQL-multi-prop-variable-v12.3.png?w=750 750w, /media/docs/postgres/postgreSQL-multi-prop-variable-v12.3.png?w=900 900w, /media/docs/postgres/postgreSQL-multi-prop-variable-v12.3.png?w=1040 1040w, /media/docs/postgres/postgreSQL-multi-prop-variable-v12.3.png?w=1240 1240w, /media/docs/postgres/postgreSQL-multi-prop-variable-v12.3.png?w=1920 1920w&#34;data-sizes=&#34;auto&#34;alt=&#34;PostgreSQL multi-property variable example&#34;width=&#34;601&#34;height=&#34;475&#34;/&gt;
        &lt;noscript&gt;
          &lt;img
            src=&#34;/media/docs/postgres/postgreSQL-multi-prop-variable-v12.3.png&#34;
            alt=&#34;PostgreSQL multi-property variable example&#34;width=&#34;601&#34;height=&#34;475&#34;/&gt;
        &lt;/noscript&gt;&lt;/div&gt;&lt;/a&gt;&lt;/figure&gt;
&lt;p&gt;You can create a multi-property variable with either &lt;strong&gt;Type: Custom&lt;/strong&gt; or &lt;strong&gt;Type: Query&lt;/strong&gt;:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Type: Custom&lt;/strong&gt; – In &lt;strong&gt;Custom options&lt;/strong&gt; &amp;gt; &lt;strong&gt;JSON&lt;/strong&gt;, paste your own JSON array with the mapping. Each object in the array can have any number of properties; use &lt;code&gt;text&lt;/code&gt; and &lt;code&gt;value&lt;/code&gt; for the label and value shown in the drop-down, and add additional properties as needed. For the JSON format and examples, refer to 
    &lt;a href=&#34;/docs/grafana/v13.1/dashboards/variables/add-template-variables/#multi-property-custom-variables&#34;&gt;Multi-property custom variables&lt;/a&gt; in Add and manage variables.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Type: Query&lt;/strong&gt; – Write a SQL query that returns multiple columns. In the variable editor, set &lt;strong&gt;Value field&lt;/strong&gt; and &lt;strong&gt;Text field&lt;/strong&gt; to the columns that supply the value and the label for the drop-down. Add one column per property you want to reference; each column name becomes a property name. In panels and queries, reference a property with &lt;code&gt;${varName.columnName}&lt;/code&gt;.&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;strong&gt;Example (Type: Query):&lt;/strong&gt; A variable named &lt;code&gt;env&lt;/code&gt; that lists environments with different identifiers per cloud. In the variable editor, set &lt;strong&gt;Text field&lt;/strong&gt; to &lt;code&gt;name&lt;/code&gt; and &lt;strong&gt;Value field&lt;/strong&gt; to &lt;code&gt;id&lt;/code&gt;.&lt;/p&gt;

&lt;div class=&#34;code-snippet &#34;&gt;&lt;div class=&#34;lang-toolbar&#34;&gt;
    &lt;span class=&#34;lang-toolbar__item lang-toolbar__item-active&#34;&gt;SQL&lt;/span&gt;
    &lt;span class=&#34;code-clipboard&#34;&gt;
      &lt;button x-data=&#34;app_code_snippet()&#34; x-init=&#34;init()&#34; @click=&#34;copy()&#34;&gt;
        &lt;img class=&#34;code-clipboard__icon&#34; src=&#34;/media/images/icons/icon-copy-small-2.svg&#34; alt=&#34;Copy code to clipboard&#34; width=&#34;14&#34; height=&#34;13&#34;&gt;
        &lt;span&gt;Copy&lt;/span&gt;
      &lt;/button&gt;
    &lt;/span&gt;
    &lt;div class=&#34;lang-toolbar__border&#34;&gt;&lt;/div&gt;
  &lt;/div&gt;&lt;div class=&#34;code-snippet &#34;&gt;
    &lt;pre data-expanded=&#34;false&#34;&gt;&lt;code class=&#34;language-sql&#34;&gt;SELECT
  name,
  id,
  aws_identifier AS env_aws,
  azure_identifier AS env_azure
FROM environments&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;In a panel query you might use &lt;code&gt;$env.env_aws&lt;/code&gt; for an AWS-related query and &lt;code&gt;$env.env_azure&lt;/code&gt; for an Azure-related query. For more on the concept, refer to 
    &lt;a href=&#34;/docs/grafana/v13.1/dashboards/variables/add-template-variables/#configure-multi-property-variables&#34;&gt;Configure multi-property variables&lt;/a&gt; in 
    &lt;a href=&#34;/docs/grafana/v13.1/dashboards/variables/add-template-variables/&#34;&gt;Add and manage variables&lt;/a&gt;.&lt;/p&gt;
&lt;h2 id=&#34;use-variables-in-queries&#34;&gt;Use variables in queries&lt;/h2&gt;
&lt;p&gt;Grafana automatically quotes template variable values only when the template variable is a &lt;strong&gt;multi-value&lt;/strong&gt; variable.&lt;/p&gt;
&lt;p&gt;When using a multi-value variable, use the &lt;code&gt;IN&lt;/code&gt; comparison operator instead of &lt;code&gt;=&lt;/code&gt; to match against multiple values.&lt;/p&gt;
&lt;p&gt;Grafana supports two syntaxes for using variables in queries:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;&lt;code&gt;$&amp;lt;varname&amp;gt;&lt;/code&gt; syntax&lt;/strong&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Example with a template variable named &lt;code&gt;hostname&lt;/code&gt;:&lt;/p&gt;

&lt;div class=&#34;code-snippet &#34;&gt;&lt;div class=&#34;lang-toolbar&#34;&gt;
    &lt;span class=&#34;lang-toolbar__item lang-toolbar__item-active&#34;&gt;SQL&lt;/span&gt;
    &lt;span class=&#34;code-clipboard&#34;&gt;
      &lt;button x-data=&#34;app_code_snippet()&#34; x-init=&#34;init()&#34; @click=&#34;copy()&#34;&gt;
        &lt;img class=&#34;code-clipboard__icon&#34; src=&#34;/media/images/icons/icon-copy-small-2.svg&#34; alt=&#34;Copy code to clipboard&#34; width=&#34;14&#34; height=&#34;13&#34;&gt;
        &lt;span&gt;Copy&lt;/span&gt;
      &lt;/button&gt;
    &lt;/span&gt;
    &lt;div class=&#34;lang-toolbar__border&#34;&gt;&lt;/div&gt;
  &lt;/div&gt;&lt;div class=&#34;code-snippet &#34;&gt;
    &lt;pre data-expanded=&#34;false&#34;&gt;&lt;code class=&#34;language-sql&#34;&gt;SELECT
  atimestamp AS time,
  aint AS value
FROM table
WHERE $__timeFilter(atimestamp) AND hostname IN($hostname)
ORDER BY atimestamp ASC&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;&lt;code&gt;[[varname]]&lt;/code&gt; syntax&lt;/strong&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Example with a template variable named &lt;code&gt;hostname&lt;/code&gt;:&lt;/p&gt;

&lt;div class=&#34;code-snippet &#34;&gt;&lt;div class=&#34;lang-toolbar&#34;&gt;
    &lt;span class=&#34;lang-toolbar__item lang-toolbar__item-active&#34;&gt;SQL&lt;/span&gt;
    &lt;span class=&#34;code-clipboard&#34;&gt;
      &lt;button x-data=&#34;app_code_snippet()&#34; x-init=&#34;init()&#34; @click=&#34;copy()&#34;&gt;
        &lt;img class=&#34;code-clipboard__icon&#34; src=&#34;/media/images/icons/icon-copy-small-2.svg&#34; alt=&#34;Copy code to clipboard&#34; width=&#34;14&#34; height=&#34;13&#34;&gt;
        &lt;span&gt;Copy&lt;/span&gt;
      &lt;/button&gt;
    &lt;/span&gt;
    &lt;div class=&#34;lang-toolbar__border&#34;&gt;&lt;/div&gt;
  &lt;/div&gt;&lt;div class=&#34;code-snippet &#34;&gt;
    &lt;pre data-expanded=&#34;false&#34;&gt;&lt;code class=&#34;language-sql&#34;&gt;SELECT
  atimestamp AS time,
  aint AS value
FROM table
WHERE $__timeFilter(atimestamp) AND hostname IN([[hostname]])
ORDER BY atimestamp ASC&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;h3 id=&#34;multi-value-variable-with-in-clause&#34;&gt;Multi-value variable with IN clause&lt;/h3&gt;
&lt;p&gt;When a variable has &lt;strong&gt;Multi-value&lt;/strong&gt; enabled, Grafana automatically adds quotes around each selected value. For example, if the user selects &lt;code&gt;web01&lt;/code&gt; and &lt;code&gt;web02&lt;/code&gt;, &lt;code&gt;$hostname&lt;/code&gt; expands to &lt;code&gt;&#39;web01&#39;,&#39;web02&#39;&lt;/code&gt;. Use the &lt;code&gt;IN&lt;/code&gt; operator to match:&lt;/p&gt;

&lt;div class=&#34;code-snippet &#34;&gt;&lt;div class=&#34;lang-toolbar&#34;&gt;
    &lt;span class=&#34;lang-toolbar__item lang-toolbar__item-active&#34;&gt;SQL&lt;/span&gt;
    &lt;span class=&#34;code-clipboard&#34;&gt;
      &lt;button x-data=&#34;app_code_snippet()&#34; x-init=&#34;init()&#34; @click=&#34;copy()&#34;&gt;
        &lt;img class=&#34;code-clipboard__icon&#34; src=&#34;/media/images/icons/icon-copy-small-2.svg&#34; alt=&#34;Copy code to clipboard&#34; width=&#34;14&#34; height=&#34;13&#34;&gt;
        &lt;span&gt;Copy&lt;/span&gt;
      &lt;/button&gt;
    &lt;/span&gt;
    &lt;div class=&#34;lang-toolbar__border&#34;&gt;&lt;/div&gt;
  &lt;/div&gt;&lt;div class=&#34;code-snippet &#34;&gt;
    &lt;pre data-expanded=&#34;false&#34;&gt;&lt;code class=&#34;language-sql&#34;&gt;SELECT
  $__timeGroupAlias(&amp;#34;created_at&amp;#34;, &amp;#39;5m&amp;#39;),
  count(*) AS requests
FROM access_log
WHERE $__timeFilter(&amp;#34;created_at&amp;#34;)
  AND hostname IN($hostname)
GROUP BY time
ORDER BY time&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;If only a single value is selected, the &lt;code&gt;IN&lt;/code&gt; clause still works correctly—&lt;code&gt;IN(&#39;web01&#39;)&lt;/code&gt; is equivalent to &lt;code&gt;= &#39;web01&#39;&lt;/code&gt;.&lt;/p&gt;
&lt;h3 id=&#34;multi-value-variable-with-numeric-columns&#34;&gt;Multi-value variable with numeric columns&lt;/h3&gt;
&lt;p&gt;For numeric columns (such as IDs), disable quoting with the &lt;code&gt;csv&lt;/code&gt; format option so values aren&amp;rsquo;t wrapped in quotes:&lt;/p&gt;

&lt;div class=&#34;code-snippet &#34;&gt;&lt;div class=&#34;lang-toolbar&#34;&gt;
    &lt;span class=&#34;lang-toolbar__item lang-toolbar__item-active&#34;&gt;SQL&lt;/span&gt;
    &lt;span class=&#34;code-clipboard&#34;&gt;
      &lt;button x-data=&#34;app_code_snippet()&#34; x-init=&#34;init()&#34; @click=&#34;copy()&#34;&gt;
        &lt;img class=&#34;code-clipboard__icon&#34; src=&#34;/media/images/icons/icon-copy-small-2.svg&#34; alt=&#34;Copy code to clipboard&#34; width=&#34;14&#34; height=&#34;13&#34;&gt;
        &lt;span&gt;Copy&lt;/span&gt;
      &lt;/button&gt;
    &lt;/span&gt;
    &lt;div class=&#34;lang-toolbar__border&#34;&gt;&lt;/div&gt;
  &lt;/div&gt;&lt;div class=&#34;code-snippet &#34;&gt;
    &lt;pre data-expanded=&#34;false&#34;&gt;&lt;code class=&#34;language-sql&#34;&gt;SELECT name FROM host WHERE id IN(${host_id:csv})&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;If &lt;code&gt;host_id&lt;/code&gt; has values &lt;code&gt;1&lt;/code&gt;, &lt;code&gt;2&lt;/code&gt;, and &lt;code&gt;3&lt;/code&gt; selected, this expands to &lt;code&gt;IN(1,2,3)&lt;/code&gt; instead of &lt;code&gt;IN(&#39;1&#39;,&#39;2&#39;,&#39;3&#39;)&lt;/code&gt;.&lt;/p&gt;
&lt;h3 id=&#34;disable-quoting-for-multi-value-variables&#34;&gt;Disable quoting for multi-value variables&lt;/h3&gt;
&lt;p&gt;By default, Grafana formats multi-value variables as a quoted, comma-separated string. For example, if &lt;code&gt;server01&lt;/code&gt; and &lt;code&gt;server02&lt;/code&gt; are selected, the result is &lt;code&gt;&#39;server01&#39;,&#39;server02&#39;&lt;/code&gt;. To disable quoting, use the &lt;code&gt;csv&lt;/code&gt; formatting option:&lt;/p&gt;

&lt;div class=&#34;code-snippet &#34;&gt;&lt;div class=&#34;lang-toolbar&#34;&gt;
    &lt;span class=&#34;lang-toolbar__item lang-toolbar__item-active&#34;&gt;text&lt;/span&gt;
    &lt;span class=&#34;code-clipboard&#34;&gt;
      &lt;button x-data=&#34;app_code_snippet()&#34; x-init=&#34;init()&#34; @click=&#34;copy()&#34;&gt;
        &lt;img class=&#34;code-clipboard__icon&#34; src=&#34;/media/images/icons/icon-copy-small-2.svg&#34; alt=&#34;Copy code to clipboard&#34; width=&#34;14&#34; height=&#34;13&#34;&gt;
        &lt;span&gt;Copy&lt;/span&gt;
      &lt;/button&gt;
    &lt;/span&gt;
    &lt;div class=&#34;lang-toolbar__border&#34;&gt;&lt;/div&gt;
  &lt;/div&gt;&lt;div class=&#34;code-snippet &#34;&gt;
    &lt;pre data-expanded=&#34;false&#34;&gt;&lt;code class=&#34;language-text&#34;&gt;${servers:csv}&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;This outputs the values as an unquoted comma-separated list.&lt;/p&gt;
&lt;p&gt;Refer to 
    &lt;a href=&#34;/docs/grafana/v13.1/dashboards/variables/variable-syntax/#advanced-variable-format-options&#34;&gt;Advanced variable format options&lt;/a&gt; for additional information.&lt;/p&gt;
]]></content><description>&lt;h1 id="postgresql-template-variables">PostgreSQL template variables&lt;/h1>
&lt;p>Instead of hard-coding details such as server, application, and sensor names in metric queries, you can use variables.
Grafana displays these variables in drop-down select boxes at the top of the dashboard to help you change the data displayed in your dashboard.
Grafana refers to such variables as &lt;strong>template variables&lt;/strong>.&lt;/p></description></item><item><title>PostgreSQL annotations</title><link>https://grafana.com/docs/grafana/v13.1/datasources/postgres/annotations/</link><pubDate>Tue, 23 Jun 2026 13:06:40 +0000</pubDate><guid>https://grafana.com/docs/grafana/v13.1/datasources/postgres/annotations/</guid><content><![CDATA[&lt;h1 id=&#34;postgresql-annotations&#34;&gt;PostgreSQL annotations&lt;/h1&gt;
&lt;p&gt;Annotations overlay event data on your dashboard graphs, helping you correlate events with metrics.
You can use PostgreSQL as a data source for annotations to display events such as deployments, alerts, or other significant occurrences on your visualizations.&lt;/p&gt;
&lt;p&gt;For general information about annotations, refer to 
    &lt;a href=&#34;/docs/grafana/v13.1/dashboards/build-dashboards/annotate-visualizations/&#34;&gt;Annotate visualizations&lt;/a&gt;.&lt;/p&gt;
&lt;h2 id=&#34;before-you-begin&#34;&gt;Before you begin&lt;/h2&gt;
&lt;p&gt;Before creating PostgreSQL annotations, ensure you have:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
    &lt;a href=&#34;/docs/grafana/v13.1/datasources/postgres/configure/&#34;&gt;A configured PostgreSQL data source&lt;/a&gt;.&lt;/li&gt;
&lt;li&gt;Tables containing event data with timestamp fields.&lt;/li&gt;
&lt;li&gt;Read access to the tables containing your events.&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&#34;create-an-annotation-query&#34;&gt;Create an annotation query&lt;/h2&gt;
&lt;p&gt;To add a PostgreSQL annotation to your dashboard:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;Navigate to your dashboard and click &lt;strong&gt;Dashboard settings&lt;/strong&gt; (gear icon).&lt;/li&gt;
&lt;li&gt;Select &lt;strong&gt;Annotations&lt;/strong&gt; in the left menu.&lt;/li&gt;
&lt;li&gt;Click &lt;strong&gt;Add annotation query&lt;/strong&gt;.&lt;/li&gt;
&lt;li&gt;Enter a &lt;strong&gt;Name&lt;/strong&gt; for the annotation.&lt;/li&gt;
&lt;li&gt;Select your &lt;strong&gt;PostgreSQL&lt;/strong&gt; data source from the &lt;strong&gt;Data source&lt;/strong&gt; drop-down.&lt;/li&gt;
&lt;li&gt;Write a SQL query that returns the required columns.&lt;/li&gt;
&lt;li&gt;Click &lt;strong&gt;Save dashboard&lt;/strong&gt;.&lt;/li&gt;
&lt;/ol&gt;
&lt;h2 id=&#34;query-columns&#34;&gt;Query columns&lt;/h2&gt;
&lt;p&gt;Your annotation query must return a &lt;code&gt;time&lt;/code&gt; column and can optionally include &lt;code&gt;timeend&lt;/code&gt;, &lt;code&gt;text&lt;/code&gt;, and &lt;code&gt;tags&lt;/code&gt; columns.&lt;/p&gt;
&lt;section class=&#34;expand-table-wrapper&#34;&gt;&lt;div class=&#34;button-div&#34;&gt;
      &lt;button class=&#34;expand-table-btn&#34;&gt;Expand table&lt;/button&gt;
    &lt;/div&gt;&lt;div class=&#34;responsive-table-wrapper&#34;&gt;
    &lt;table&gt;
      &lt;thead&gt;
          &lt;tr&gt;
              &lt;th&gt;Column&lt;/th&gt;
              &lt;th&gt;Required&lt;/th&gt;
              &lt;th&gt;Description&lt;/th&gt;
          &lt;/tr&gt;
      &lt;/thead&gt;
      &lt;tbody&gt;
          &lt;tr&gt;
              &lt;td&gt;&lt;code&gt;time&lt;/code&gt;&lt;/td&gt;
              &lt;td&gt;Yes&lt;/td&gt;
              &lt;td&gt;The timestamp for the annotation. Can be a native SQL date/time type or UNIX epoch value.&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;&lt;code&gt;timeend&lt;/code&gt;&lt;/td&gt;
              &lt;td&gt;No&lt;/td&gt;
              &lt;td&gt;The end timestamp for range annotations. Creates a shaded region instead of a vertical line.&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;&lt;code&gt;text&lt;/code&gt;&lt;/td&gt;
              &lt;td&gt;No&lt;/td&gt;
              &lt;td&gt;The annotation description displayed when you hover over the annotation.&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;&lt;code&gt;tags&lt;/code&gt;&lt;/td&gt;
              &lt;td&gt;No&lt;/td&gt;
              &lt;td&gt;Tags for the annotation as a comma-separated string. Helps categorize and filter annotations.&lt;/td&gt;
          &lt;/tr&gt;
      &lt;/tbody&gt;
    &lt;/table&gt;
  &lt;/div&gt;
&lt;/section&gt;&lt;h2 id=&#34;example-queries&#34;&gt;Example queries&lt;/h2&gt;
&lt;p&gt;The following examples show common annotation query patterns.&lt;/p&gt;
&lt;h3 id=&#34;basic-annotation-with-epoch-time&#34;&gt;Basic annotation with epoch time&lt;/h3&gt;
&lt;p&gt;Display events using UNIX epoch timestamps:&lt;/p&gt;

&lt;div class=&#34;code-snippet &#34;&gt;&lt;div class=&#34;lang-toolbar&#34;&gt;
    &lt;span class=&#34;lang-toolbar__item lang-toolbar__item-active&#34;&gt;SQL&lt;/span&gt;
    &lt;span class=&#34;code-clipboard&#34;&gt;
      &lt;button x-data=&#34;app_code_snippet()&#34; x-init=&#34;init()&#34; @click=&#34;copy()&#34;&gt;
        &lt;img class=&#34;code-clipboard__icon&#34; src=&#34;/media/images/icons/icon-copy-small-2.svg&#34; alt=&#34;Copy code to clipboard&#34; width=&#34;14&#34; height=&#34;13&#34;&gt;
        &lt;span&gt;Copy&lt;/span&gt;
      &lt;/button&gt;
    &lt;/span&gt;
    &lt;div class=&#34;lang-toolbar__border&#34;&gt;&lt;/div&gt;
  &lt;/div&gt;&lt;div class=&#34;code-snippet &#34;&gt;
    &lt;pre data-expanded=&#34;false&#34;&gt;&lt;code class=&#34;language-sql&#34;&gt;SELECT
  epoch_time as time,
  metric1 as text,
  concat_ws(&amp;#39;, &amp;#39;, metric1::text, metric2::text) as tags
FROM public.test_data
WHERE $__unixEpochFilter(epoch_time)&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;h3 id=&#34;range-annotation-with-start-and-end-time&#34;&gt;Range annotation with start and end time&lt;/h3&gt;
&lt;p&gt;Display events with duration as shaded regions:&lt;/p&gt;

&lt;div class=&#34;code-snippet &#34;&gt;&lt;div class=&#34;lang-toolbar&#34;&gt;
    &lt;span class=&#34;lang-toolbar__item lang-toolbar__item-active&#34;&gt;SQL&lt;/span&gt;
    &lt;span class=&#34;code-clipboard&#34;&gt;
      &lt;button x-data=&#34;app_code_snippet()&#34; x-init=&#34;init()&#34; @click=&#34;copy()&#34;&gt;
        &lt;img class=&#34;code-clipboard__icon&#34; src=&#34;/media/images/icons/icon-copy-small-2.svg&#34; alt=&#34;Copy code to clipboard&#34; width=&#34;14&#34; height=&#34;13&#34;&gt;
        &lt;span&gt;Copy&lt;/span&gt;
      &lt;/button&gt;
    &lt;/span&gt;
    &lt;div class=&#34;lang-toolbar__border&#34;&gt;&lt;/div&gt;
  &lt;/div&gt;&lt;div class=&#34;code-snippet &#34;&gt;
    &lt;pre data-expanded=&#34;false&#34;&gt;&lt;code class=&#34;language-sql&#34;&gt;SELECT
  epoch_time as time,
  epoch_time_end as timeend,
  metric1 as text,
  concat_ws(&amp;#39;, &amp;#39;, metric1::text, metric2::text) as tags
FROM public.test_data
WHERE $__unixEpochFilter(epoch_time)&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;h3 id=&#34;annotation-with-native-sql-datetime&#34;&gt;Annotation with native SQL date/time&lt;/h3&gt;
&lt;p&gt;Display events using native PostgreSQL date/time columns:&lt;/p&gt;

&lt;div class=&#34;code-snippet &#34;&gt;&lt;div class=&#34;lang-toolbar&#34;&gt;
    &lt;span class=&#34;lang-toolbar__item lang-toolbar__item-active&#34;&gt;SQL&lt;/span&gt;
    &lt;span class=&#34;code-clipboard&#34;&gt;
      &lt;button x-data=&#34;app_code_snippet()&#34; x-init=&#34;init()&#34; @click=&#34;copy()&#34;&gt;
        &lt;img class=&#34;code-clipboard__icon&#34; src=&#34;/media/images/icons/icon-copy-small-2.svg&#34; alt=&#34;Copy code to clipboard&#34; width=&#34;14&#34; height=&#34;13&#34;&gt;
        &lt;span&gt;Copy&lt;/span&gt;
      &lt;/button&gt;
    &lt;/span&gt;
    &lt;div class=&#34;lang-toolbar__border&#34;&gt;&lt;/div&gt;
  &lt;/div&gt;&lt;div class=&#34;code-snippet &#34;&gt;
    &lt;pre data-expanded=&#34;false&#34;&gt;&lt;code class=&#34;language-sql&#34;&gt;SELECT
  native_date_time as time,
  metric1 as text,
  concat_ws(&amp;#39;, &amp;#39;, metric1::text, metric2::text) as tags
FROM public.test_data
WHERE $__timeFilter(native_date_time)&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;h3 id=&#34;deployment-annotations&#34;&gt;Deployment annotations&lt;/h3&gt;
&lt;p&gt;Display deployment events:&lt;/p&gt;

&lt;div class=&#34;code-snippet &#34;&gt;&lt;div class=&#34;lang-toolbar&#34;&gt;
    &lt;span class=&#34;lang-toolbar__item lang-toolbar__item-active&#34;&gt;SQL&lt;/span&gt;
    &lt;span class=&#34;code-clipboard&#34;&gt;
      &lt;button x-data=&#34;app_code_snippet()&#34; x-init=&#34;init()&#34; @click=&#34;copy()&#34;&gt;
        &lt;img class=&#34;code-clipboard__icon&#34; src=&#34;/media/images/icons/icon-copy-small-2.svg&#34; alt=&#34;Copy code to clipboard&#34; width=&#34;14&#34; height=&#34;13&#34;&gt;
        &lt;span&gt;Copy&lt;/span&gt;
      &lt;/button&gt;
    &lt;/span&gt;
    &lt;div class=&#34;lang-toolbar__border&#34;&gt;&lt;/div&gt;
  &lt;/div&gt;&lt;div class=&#34;code-snippet &#34;&gt;
    &lt;pre data-expanded=&#34;false&#34;&gt;&lt;code class=&#34;language-sql&#34;&gt;SELECT
  deployed_at as time,
  concat(&amp;#39;Deployed &amp;#39;, version, &amp;#39; to &amp;#39;, environment) as text,
  environment as tags
FROM deployments
WHERE $__timeFilter(deployed_at)&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;h3 id=&#34;range-annotation-for-maintenance-windows&#34;&gt;Range annotation for maintenance windows&lt;/h3&gt;
&lt;p&gt;Display maintenance windows as shaded regions:&lt;/p&gt;

&lt;div class=&#34;code-snippet &#34;&gt;&lt;div class=&#34;lang-toolbar&#34;&gt;
    &lt;span class=&#34;lang-toolbar__item lang-toolbar__item-active&#34;&gt;SQL&lt;/span&gt;
    &lt;span class=&#34;code-clipboard&#34;&gt;
      &lt;button x-data=&#34;app_code_snippet()&#34; x-init=&#34;init()&#34; @click=&#34;copy()&#34;&gt;
        &lt;img class=&#34;code-clipboard__icon&#34; src=&#34;/media/images/icons/icon-copy-small-2.svg&#34; alt=&#34;Copy code to clipboard&#34; width=&#34;14&#34; height=&#34;13&#34;&gt;
        &lt;span&gt;Copy&lt;/span&gt;
      &lt;/button&gt;
    &lt;/span&gt;
    &lt;div class=&#34;lang-toolbar__border&#34;&gt;&lt;/div&gt;
  &lt;/div&gt;&lt;div class=&#34;code-snippet &#34;&gt;
    &lt;pre data-expanded=&#34;false&#34;&gt;&lt;code class=&#34;language-sql&#34;&gt;SELECT
  start_time as time,
  end_time as timeend,
  concat(&amp;#39;Maintenance: &amp;#39;, description) as text,
  &amp;#39;maintenance&amp;#39; as tags
FROM maintenance_windows
WHERE $__timeFilter(start_time)&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;h2 id=&#34;macros&#34;&gt;Macros&lt;/h2&gt;
&lt;p&gt;Use these macros in your annotation queries to filter by the dashboard time range:&lt;/p&gt;
&lt;section class=&#34;expand-table-wrapper&#34;&gt;&lt;div class=&#34;button-div&#34;&gt;
      &lt;button class=&#34;expand-table-btn&#34;&gt;Expand table&lt;/button&gt;
    &lt;/div&gt;&lt;div class=&#34;responsive-table-wrapper&#34;&gt;
    &lt;table&gt;
      &lt;thead&gt;
          &lt;tr&gt;
              &lt;th&gt;Macro&lt;/th&gt;
              &lt;th&gt;Description&lt;/th&gt;
          &lt;/tr&gt;
      &lt;/thead&gt;
      &lt;tbody&gt;
          &lt;tr&gt;
              &lt;td&gt;&lt;code&gt;$__timeFilter(column)&lt;/code&gt;&lt;/td&gt;
              &lt;td&gt;Filters by time range using a native SQL date/time column.&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;&lt;code&gt;$__unixEpochFilter(column)&lt;/code&gt;&lt;/td&gt;
              &lt;td&gt;Filters by time range using a column with UNIX epoch timestamps.&lt;/td&gt;
          &lt;/tr&gt;
      &lt;/tbody&gt;
    &lt;/table&gt;
  &lt;/div&gt;
&lt;/section&gt;&lt;h2 id=&#34;best-practices&#34;&gt;Best practices&lt;/h2&gt;
&lt;p&gt;Follow these best practices when creating PostgreSQL annotations:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Use time filters:&lt;/strong&gt; Always include &lt;code&gt;$__timeFilter()&lt;/code&gt; or &lt;code&gt;$__unixEpochFilter()&lt;/code&gt; to limit results to the dashboard time range.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Keep queries efficient:&lt;/strong&gt; Add indexes on time columns and filter columns to improve query performance.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Use meaningful text:&lt;/strong&gt; Include descriptive information in the &lt;code&gt;text&lt;/code&gt; column to make annotations useful.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Organize with tags:&lt;/strong&gt; Use consistent tag values to categorize annotations and enable filtering.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Test queries first:&lt;/strong&gt; Verify your query returns expected results in Explore before adding it as an annotation.&lt;/li&gt;
&lt;/ul&gt;
]]></content><description>&lt;h1 id="postgresql-annotations">PostgreSQL annotations&lt;/h1>
&lt;p>Annotations overlay event data on your dashboard graphs, helping you correlate events with metrics.
You can use PostgreSQL as a data source for annotations to display events such as deployments, alerts, or other significant occurrences on your visualizations.&lt;/p></description></item><item><title>PostgreSQL alerting</title><link>https://grafana.com/docs/grafana/v13.1/datasources/postgres/alerting/</link><pubDate>Tue, 23 Jun 2026 13:06:40 +0000</pubDate><guid>https://grafana.com/docs/grafana/v13.1/datasources/postgres/alerting/</guid><content><![CDATA[&lt;h1 id=&#34;postgresql-alerting&#34;&gt;PostgreSQL alerting&lt;/h1&gt;
&lt;p&gt;The PostgreSQL data source supports 
    &lt;a href=&#34;/docs/grafana/v13.1/alerting/&#34;&gt;Grafana Alerting&lt;/a&gt;. You can create alert rules that evaluate time series queries against your PostgreSQL database and send notifications when conditions are met.&lt;/p&gt;
&lt;h2 id=&#34;before-you-begin&#34;&gt;Before you begin&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;Ensure your 
    &lt;a href=&#34;/docs/grafana/v13.1/datasources/postgres/configure/&#34;&gt;PostgreSQL data source is configured&lt;/a&gt;.&lt;/li&gt;
&lt;li&gt;Familiarize yourself with 
    &lt;a href=&#34;/docs/grafana/v13.1/alerting/fundamentals/alert-rules/&#34;&gt;Alert rules&lt;/a&gt; and 
    &lt;a href=&#34;/docs/grafana/v13.1/alerting/alerting-rules/create-grafana-managed-rule/&#34;&gt;Create a Grafana-managed alert rule&lt;/a&gt;.&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&#34;supported-query-format&#34;&gt;Supported query format&lt;/h2&gt;
&lt;p&gt;Only &lt;strong&gt;time series&lt;/strong&gt; queries can be used in alert rule conditions.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Your query must return a column named &lt;code&gt;time&lt;/code&gt; (native SQL date/time or UNIX epoch) and one or more numeric value columns.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Table&lt;/strong&gt; formatted queries aren&amp;rsquo;t supported in alert rule conditions.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;For details on writing time series queries, refer to 
    &lt;a href=&#34;/docs/grafana/v13.1/datasources/postgres/query-editor/#time-series-queries&#34;&gt;Time series queries&lt;/a&gt; in the PostgreSQL query editor.&lt;/p&gt;
&lt;h2 id=&#34;limitations&#34;&gt;Limitations&lt;/h2&gt;
&lt;p&gt;Keep the following limitations in mind when using PostgreSQL with Grafana Alerting:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Time series format only:&lt;/strong&gt; Alert rules require the query &lt;strong&gt;Format&lt;/strong&gt; set to &lt;strong&gt;Time series&lt;/strong&gt;. Table format queries can&amp;rsquo;t be used as alert conditions.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;No fill mode in alerts:&lt;/strong&gt; The fill parameter in &lt;code&gt;$__timeGroup&lt;/code&gt; (for example, &lt;code&gt;$__timeGroup(col, &#39;5m&#39;, 0)&lt;/code&gt;) isn&amp;rsquo;t applied during alert evaluation. Missing data points remain as gaps.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Single query per condition:&lt;/strong&gt; Each alert condition evaluates a single query. If you need to combine results from multiple queries, use 
    &lt;a href=&#34;/docs/grafana/v13.1/alerting/alerting-rules/create-grafana-managed-rule/#add-expressions&#34;&gt;math expressions&lt;/a&gt; in the alert rule.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Template variables aren&amp;rsquo;t supported:&lt;/strong&gt; Alert queries don&amp;rsquo;t support dashboard template variables because alerts evaluate independently of any dashboard context. Hard-code values or use 
    &lt;a href=&#34;/docs/grafana/v13.1/alerting/fundamentals/alert-rules/annotation-label/&#34;&gt;alert rule labels&lt;/a&gt; instead.&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&#34;create-an-alert-rule&#34;&gt;Create an alert rule&lt;/h2&gt;
&lt;p&gt;To create an alert rule that uses PostgreSQL:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;Go to &lt;strong&gt;Alerting&lt;/strong&gt; in the left menu and select &lt;strong&gt;Alert rules&lt;/strong&gt;.&lt;/li&gt;
&lt;li&gt;Click &lt;strong&gt;New alert rule&lt;/strong&gt;.&lt;/li&gt;
&lt;li&gt;In the query section, select your &lt;strong&gt;PostgreSQL&lt;/strong&gt; data source.&lt;/li&gt;
&lt;li&gt;Set the query &lt;strong&gt;Format&lt;/strong&gt; to &lt;strong&gt;Time series&lt;/strong&gt;.&lt;/li&gt;
&lt;li&gt;Write a SQL query that returns a &lt;code&gt;time&lt;/code&gt; column and one or more numeric values.&lt;/li&gt;
&lt;li&gt;Configure the condition, evaluation group, and notification settings.&lt;/li&gt;
&lt;li&gt;Save the rule.&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;For step-by-step guidance, refer to 
    &lt;a href=&#34;/docs/grafana/v13.1/alerting/alerting-rules/create-grafana-managed-rule/&#34;&gt;Create a Grafana-managed alert rule&lt;/a&gt;.&lt;/p&gt;
&lt;h2 id=&#34;example-queries-for-alerting&#34;&gt;Example queries for alerting&lt;/h2&gt;
&lt;p&gt;The following examples show common PostgreSQL alerting patterns.&lt;/p&gt;
&lt;h3 id=&#34;threshold-alert&#34;&gt;Threshold alert&lt;/h3&gt;
&lt;p&gt;The following query returns a time series suitable for a threshold alert (for example, alert when average value exceeds a limit):&lt;/p&gt;

&lt;div class=&#34;code-snippet &#34;&gt;&lt;div class=&#34;lang-toolbar&#34;&gt;
    &lt;span class=&#34;lang-toolbar__item lang-toolbar__item-active&#34;&gt;SQL&lt;/span&gt;
    &lt;span class=&#34;code-clipboard&#34;&gt;
      &lt;button x-data=&#34;app_code_snippet()&#34; x-init=&#34;init()&#34; @click=&#34;copy()&#34;&gt;
        &lt;img class=&#34;code-clipboard__icon&#34; src=&#34;/media/images/icons/icon-copy-small-2.svg&#34; alt=&#34;Copy code to clipboard&#34; width=&#34;14&#34; height=&#34;13&#34;&gt;
        &lt;span&gt;Copy&lt;/span&gt;
      &lt;/button&gt;
    &lt;/span&gt;
    &lt;div class=&#34;lang-toolbar__border&#34;&gt;&lt;/div&gt;
  &lt;/div&gt;&lt;div class=&#34;code-snippet &#34;&gt;
    &lt;pre data-expanded=&#34;false&#34;&gt;&lt;code class=&#34;language-sql&#34;&gt;SELECT
  $__timeGroupAlias(&amp;#34;time_date_time&amp;#34;, &amp;#39;5m&amp;#39;),
  avg(&amp;#34;value_double&amp;#34;) AS value
FROM test_data
WHERE $__timeFilter(&amp;#34;time_date_time&amp;#34;)
GROUP BY time
ORDER BY time&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;Use condition types such as &lt;strong&gt;Is above&lt;/strong&gt; or &lt;strong&gt;Is below&lt;/strong&gt; in the alert rule to evaluate the series.&lt;/p&gt;
&lt;h3 id=&#34;multi-dimensional-alert&#34;&gt;Multi-dimensional alert&lt;/h3&gt;
&lt;p&gt;To create separate alert instances for each value of a label column, include a string column in your query. Grafana creates one alert instance per unique label value, so you can monitor each host, service, or region independently.&lt;/p&gt;

&lt;div class=&#34;code-snippet &#34;&gt;&lt;div class=&#34;lang-toolbar&#34;&gt;
    &lt;span class=&#34;lang-toolbar__item lang-toolbar__item-active&#34;&gt;SQL&lt;/span&gt;
    &lt;span class=&#34;code-clipboard&#34;&gt;
      &lt;button x-data=&#34;app_code_snippet()&#34; x-init=&#34;init()&#34; @click=&#34;copy()&#34;&gt;
        &lt;img class=&#34;code-clipboard__icon&#34; src=&#34;/media/images/icons/icon-copy-small-2.svg&#34; alt=&#34;Copy code to clipboard&#34; width=&#34;14&#34; height=&#34;13&#34;&gt;
        &lt;span&gt;Copy&lt;/span&gt;
      &lt;/button&gt;
    &lt;/span&gt;
    &lt;div class=&#34;lang-toolbar__border&#34;&gt;&lt;/div&gt;
  &lt;/div&gt;&lt;div class=&#34;code-snippet &#34;&gt;
    &lt;pre data-expanded=&#34;false&#34;&gt;&lt;code class=&#34;language-sql&#34;&gt;SELECT
  $__timeGroupAlias(&amp;#34;time_date_time&amp;#34;, &amp;#39;5m&amp;#39;),
  avg(&amp;#34;value_double&amp;#34;) AS value,
  hostname
FROM test_data
WHERE $__timeFilter(&amp;#34;time_date_time&amp;#34;)
GROUP BY time, hostname
ORDER BY time&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;This query produces a separate time series for each &lt;code&gt;hostname&lt;/code&gt;. The alert rule evaluates the condition against each series independently, so you receive individual notifications per host.&lt;/p&gt;
&lt;h3 id=&#34;alert-on-row-count&#34;&gt;Alert on row count&lt;/h3&gt;
&lt;p&gt;To alert when the number of rows in a time window exceeds a threshold (for example, error count):&lt;/p&gt;

&lt;div class=&#34;code-snippet &#34;&gt;&lt;div class=&#34;lang-toolbar&#34;&gt;
    &lt;span class=&#34;lang-toolbar__item lang-toolbar__item-active&#34;&gt;SQL&lt;/span&gt;
    &lt;span class=&#34;code-clipboard&#34;&gt;
      &lt;button x-data=&#34;app_code_snippet()&#34; x-init=&#34;init()&#34; @click=&#34;copy()&#34;&gt;
        &lt;img class=&#34;code-clipboard__icon&#34; src=&#34;/media/images/icons/icon-copy-small-2.svg&#34; alt=&#34;Copy code to clipboard&#34; width=&#34;14&#34; height=&#34;13&#34;&gt;
        &lt;span&gt;Copy&lt;/span&gt;
      &lt;/button&gt;
    &lt;/span&gt;
    &lt;div class=&#34;lang-toolbar__border&#34;&gt;&lt;/div&gt;
  &lt;/div&gt;&lt;div class=&#34;code-snippet &#34;&gt;
    &lt;pre data-expanded=&#34;false&#34;&gt;&lt;code class=&#34;language-sql&#34;&gt;SELECT
  $__timeGroupAlias(&amp;#34;created_at&amp;#34;, &amp;#39;5m&amp;#39;),
  count(*) AS error_count
FROM error_logs
WHERE $__timeFilter(&amp;#34;created_at&amp;#34;)
  AND severity = &amp;#39;ERROR&amp;#39;
GROUP BY time
ORDER BY time&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;h2 id=&#34;template-annotations-and-labels&#34;&gt;Template annotations and labels&lt;/h2&gt;
&lt;p&gt;You can use 
    &lt;a href=&#34;/docs/grafana/v13.1/alerting/alerting-rules/templates/&#34;&gt;template annotations and labels&lt;/a&gt; to include query results or metadata in alert notifications and labels.&lt;/p&gt;
&lt;h2 id=&#34;best-practices&#34;&gt;Best practices&lt;/h2&gt;
&lt;p&gt;Follow these best practices when using PostgreSQL for alerting:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Keep queries fast:&lt;/strong&gt; Alert rules evaluate on a schedule (for example, every minute). Avoid expensive joins, subqueries, or scanning large tables without indexes. Add indexes on time columns and any columns used in &lt;code&gt;WHERE&lt;/code&gt; clauses.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Use &lt;code&gt;$__timeFilter&lt;/code&gt;:&lt;/strong&gt; Always include a &lt;code&gt;$__timeFilter&lt;/code&gt; or &lt;code&gt;$__unixEpochFilter&lt;/code&gt; macro to limit data to the evaluation window. Without it, the query scans the entire table on every evaluation.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Handle &lt;code&gt;NULL&lt;/code&gt; values:&lt;/strong&gt; If your data contains &lt;code&gt;NULL&lt;/code&gt; values, Grafana treats them as &amp;ldquo;no data.&amp;rdquo; Configure the alert rule&amp;rsquo;s &lt;strong&gt;No data&lt;/strong&gt; behavior to match your expectations (for example, &lt;strong&gt;Alerting&lt;/strong&gt;, &lt;strong&gt;No data&lt;/strong&gt;, or &lt;strong&gt;OK&lt;/strong&gt;).&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Test in Explore first:&lt;/strong&gt; Verify your query returns the expected time series in 
    &lt;a href=&#34;/docs/grafana/v13.1/explore/&#34;&gt;Explore&lt;/a&gt; before using it in an alert rule. Check the &lt;strong&gt;Format&lt;/strong&gt; is set to &lt;strong&gt;Time series&lt;/strong&gt; and results are sorted by time.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Set realistic evaluation intervals:&lt;/strong&gt; Choose an evaluation interval that gives your query enough time to complete. If your query takes 10 seconds, don&amp;rsquo;t evaluate every 10 seconds—allow for headroom.&lt;/li&gt;
&lt;/ul&gt;
]]></content><description>&lt;h1 id="postgresql-alerting">PostgreSQL alerting&lt;/h1>
&lt;p>The PostgreSQL data source supports
&lt;a href="/docs/grafana/v13.1/alerting/">Grafana Alerting&lt;/a>. You can create alert rules that evaluate time series queries against your PostgreSQL database and send notifications when conditions are met.&lt;/p></description></item><item><title>Troubleshoot PostgreSQL data source issues</title><link>https://grafana.com/docs/grafana/v13.1/datasources/postgres/troubleshooting/</link><pubDate>Tue, 23 Jun 2026 13:06:40 +0000</pubDate><guid>https://grafana.com/docs/grafana/v13.1/datasources/postgres/troubleshooting/</guid><content><![CDATA[&lt;h1 id=&#34;troubleshoot-postgresql-data-source-issues&#34;&gt;Troubleshoot PostgreSQL data source issues&lt;/h1&gt;
&lt;p&gt;This document provides troubleshooting information for common errors you may encounter when using the PostgreSQL data source in Grafana.&lt;/p&gt;
&lt;h2 id=&#34;connection-errors&#34;&gt;Connection errors&lt;/h2&gt;
&lt;p&gt;The following errors occur when Grafana cannot establish or maintain a connection to PostgreSQL.&lt;/p&gt;
&lt;h3 id=&#34;failed-to-connect-to-postgresql&#34;&gt;Failed to connect to PostgreSQL&lt;/h3&gt;
&lt;p&gt;&lt;strong&gt;Error message:&lt;/strong&gt; &lt;code&gt;failed to connect to ... : connect: connection refused&lt;/code&gt; or &lt;code&gt;dial tcp: connect: connection refused&lt;/code&gt;&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Cause:&lt;/strong&gt; Grafana cannot establish a network connection to the PostgreSQL server.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Solution:&lt;/strong&gt;&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;Verify that the Host URL is correct in the data source configuration.&lt;/li&gt;
&lt;li&gt;Check that PostgreSQL is running and accessible from the Grafana server.&lt;/li&gt;
&lt;li&gt;Verify the port is correct (the PostgreSQL default port is &lt;code&gt;5432&lt;/code&gt;).&lt;/li&gt;
&lt;li&gt;Ensure there are no firewall rules blocking the connection.&lt;/li&gt;
&lt;li&gt;Check that PostgreSQL is configured to accept connections from the Grafana server in &lt;code&gt;pg_hba.conf&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;For Grafana Cloud, ensure you have configured &lt;a href=&#34;/docs/grafana-cloud/connect-externally-hosted/private-data-source-connect/&#34;&gt;Private data source connect&lt;/a&gt; if your PostgreSQL instance is not publicly accessible.&lt;/li&gt;
&lt;/ol&gt;
&lt;h3 id=&#34;grafana-cloud-cant-reach-a-private-database&#34;&gt;Grafana Cloud can&amp;rsquo;t reach a private database&lt;/h3&gt;
&lt;p&gt;&lt;strong&gt;Error message:&lt;/strong&gt; &lt;code&gt;dial tcp: connect: connection refused&lt;/code&gt;, &lt;code&gt;i/o timeout&lt;/code&gt;, or &lt;code&gt;context deadline exceeded&lt;/code&gt; when using Grafana Cloud with a database on a private network.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Cause:&lt;/strong&gt; Grafana Cloud runs in a hosted environment and can&amp;rsquo;t directly reach databases on &lt;code&gt;localhost&lt;/code&gt;, &lt;code&gt;127.0.0.1&lt;/code&gt;, or private IP ranges (&lt;code&gt;10.x&lt;/code&gt;, &lt;code&gt;172.16.x&lt;/code&gt;, &lt;code&gt;192.168.x&lt;/code&gt;). This is the most common issue when migrating from self-hosted Grafana to Grafana Cloud.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Solution:&lt;/strong&gt;&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;Set up &lt;a href=&#34;/docs/grafana-cloud/connect-externally-hosted/private-data-source-connect/&#34;&gt;Private data source connect (PDC)&lt;/a&gt; to create a secure tunnel between Grafana Cloud and your private network.&lt;/li&gt;
&lt;li&gt;Install the PDC agent on a machine that has network access to your PostgreSQL instance.&lt;/li&gt;
&lt;li&gt;If you experience intermittent connection drops with the Docker-based PDC agent, try the binary-based agent instead—this has resolved stability issues in some environments.&lt;/li&gt;
&lt;li&gt;Update the &lt;strong&gt;Host URL&lt;/strong&gt; in the data source settings to use the hostname as seen from the PDC agent&amp;rsquo;s network (not &lt;code&gt;localhost&lt;/code&gt;).&lt;/li&gt;
&lt;/ol&gt;
&lt;h3 id=&#34;request-timed-out&#34;&gt;Request timed out&lt;/h3&gt;
&lt;p&gt;&lt;strong&gt;Error message:&lt;/strong&gt; &amp;ldquo;context deadline exceeded&amp;rdquo; or &amp;ldquo;i/o timeout&amp;rdquo;&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Cause:&lt;/strong&gt; The connection to PostgreSQL timed out before receiving a response.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Solution:&lt;/strong&gt;&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;Check the network latency between Grafana and PostgreSQL.&lt;/li&gt;
&lt;li&gt;Verify that PostgreSQL is not overloaded or experiencing performance issues.&lt;/li&gt;
&lt;li&gt;Increase the &lt;strong&gt;Max lifetime&lt;/strong&gt; setting in the data source configuration under &lt;strong&gt;Connection limits&lt;/strong&gt;.&lt;/li&gt;
&lt;li&gt;Reduce the time range or complexity of your query.&lt;/li&gt;
&lt;li&gt;Check if any network devices (load balancers, proxies) are timing out the connection.&lt;/li&gt;
&lt;/ol&gt;
&lt;h3 id=&#34;host-not-found&#34;&gt;Host not found&lt;/h3&gt;
&lt;p&gt;&lt;strong&gt;Error message:&lt;/strong&gt; &lt;code&gt;failed to connect to ... : hostname resolving error&lt;/code&gt; or &lt;code&gt;lookup hostname: no such host&lt;/code&gt;&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Cause:&lt;/strong&gt; The hostname specified in the data source configuration can&amp;rsquo;t be resolved.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Solution:&lt;/strong&gt;&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;Verify the hostname is spelled correctly.&lt;/li&gt;
&lt;li&gt;Check that DNS resolution is working on the Grafana server.&lt;/li&gt;
&lt;li&gt;Try using the database&amp;rsquo;s public IP address instead of a hostname. This is a useful diagnostic step and can serve as a workaround if DNS resolution is the issue.&lt;/li&gt;
&lt;li&gt;Ensure the PostgreSQL server is accessible from the Grafana server&amp;rsquo;s network.&lt;/li&gt;
&lt;li&gt;For Grafana Cloud, DNS resolution behavior can differ between stack regions and cloud providers. If a hostname resolves from one stack but not another, try the direct IP address and contact &lt;a href=&#34;/docs/grafana-cloud/account-management/support/&#34;&gt;Grafana Support&lt;/a&gt;.&lt;/li&gt;
&lt;/ol&gt;
&lt;h2 id=&#34;authentication-errors&#34;&gt;Authentication errors&lt;/h2&gt;
&lt;p&gt;The following errors occur when there are issues with authentication credentials or permissions.&lt;/p&gt;
&lt;h3 id=&#34;no-postgresql-user-name-specified&#34;&gt;No PostgreSQL user name specified&lt;/h3&gt;
&lt;p&gt;&lt;strong&gt;Error message:&lt;/strong&gt; &lt;code&gt;FATAL: no PostgreSQL user name specified in startup packet (SQLSTATE 28000)&lt;/code&gt;&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Cause:&lt;/strong&gt; The connection to PostgreSQL was attempted without a username. This typically means the &lt;strong&gt;Username&lt;/strong&gt; field in the data source configuration is empty or was cleared.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Solution:&lt;/strong&gt;&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;Open the data source settings and verify the &lt;strong&gt;Username&lt;/strong&gt; field contains a valid PostgreSQL user.&lt;/li&gt;
&lt;li&gt;Click &lt;strong&gt;Save &amp;amp; test&lt;/strong&gt; and confirm the connection succeeds.&lt;/li&gt;
&lt;li&gt;If the username disappears after saving, check your Grafana version. A bug in Grafana v13.1 on the fast release channel caused the username field to be cleared on save. Upgrading to a patched release or switching to the steady release channel resolves this issue.&lt;/li&gt;
&lt;/ol&gt;
&lt;h3 id=&#34;password-authentication-failed&#34;&gt;Password authentication failed&lt;/h3&gt;
&lt;p&gt;&lt;strong&gt;Error message:&lt;/strong&gt; &lt;code&gt;failed to connect to ... : server error: FATAL: password authentication failed for user &amp;quot;username&amp;quot; (SQLSTATE 28P01)&lt;/code&gt;&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Cause:&lt;/strong&gt; The username or password is incorrect.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Solution:&lt;/strong&gt;&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;Verify that the username and password are correct in the data source configuration.&lt;/li&gt;
&lt;li&gt;Check that the user exists in PostgreSQL.&lt;/li&gt;
&lt;li&gt;Verify the password has not expired.&lt;/li&gt;
&lt;li&gt;If no password is specified, ensure a &lt;a href=&#34;https://www.postgresql.org/docs/current/static/libpq-pgpass.html&#34; target=&#34;_blank&#34; rel=&#34;noopener noreferrer&#34;&gt;PostgreSQL password file&lt;/a&gt; is configured.&lt;/li&gt;
&lt;/ol&gt;
&lt;h3 id=&#34;permission-denied&#34;&gt;Permission denied&lt;/h3&gt;
&lt;p&gt;&lt;strong&gt;Error message:&lt;/strong&gt; &lt;code&gt;ERROR: permission denied for table table_name (SQLSTATE 42501)&lt;/code&gt; or &lt;code&gt;ERROR: permission denied for schema schema_name (SQLSTATE 42501)&lt;/code&gt;&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Cause:&lt;/strong&gt; The database user does not have permission to access the requested table or schema.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Solution:&lt;/strong&gt;&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;
&lt;p&gt;Verify the user has &lt;code&gt;SELECT&lt;/code&gt; permissions on the required tables.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Grant the necessary permissions:&lt;/p&gt;

&lt;div class=&#34;code-snippet &#34;&gt;&lt;div class=&#34;lang-toolbar&#34;&gt;
    &lt;span class=&#34;lang-toolbar__item lang-toolbar__item-active&#34;&gt;SQL&lt;/span&gt;
    &lt;span class=&#34;code-clipboard&#34;&gt;
      &lt;button x-data=&#34;app_code_snippet()&#34; x-init=&#34;init()&#34; @click=&#34;copy()&#34;&gt;
        &lt;img class=&#34;code-clipboard__icon&#34; src=&#34;/media/images/icons/icon-copy-small-2.svg&#34; alt=&#34;Copy code to clipboard&#34; width=&#34;14&#34; height=&#34;13&#34;&gt;
        &lt;span&gt;Copy&lt;/span&gt;
      &lt;/button&gt;
    &lt;/span&gt;
    &lt;div class=&#34;lang-toolbar__border&#34;&gt;&lt;/div&gt;
  &lt;/div&gt;&lt;div class=&#34;code-snippet &#34;&gt;
    &lt;pre data-expanded=&#34;false&#34;&gt;&lt;code class=&#34;language-sql&#34;&gt;GRANT USAGE ON SCHEMA schema_name TO grafanareader;
GRANT SELECT ON schema_name.table_name TO grafanareader;&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Check that the user has access to the correct database.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Verify the search path includes the schema containing your tables.&lt;/p&gt;
&lt;/li&gt;
&lt;/ol&gt;
&lt;h3 id=&#34;no-pg_hbaconf-entry&#34;&gt;No pg_hba.conf entry&lt;/h3&gt;
&lt;p&gt;&lt;strong&gt;Error message:&lt;/strong&gt; &lt;code&gt;failed to connect to ... : server error: FATAL: no pg_hba.conf entry for host &amp;quot;ip_address&amp;quot;, user &amp;quot;username&amp;quot;, database &amp;quot;database_name&amp;quot; (SQLSTATE 28000)&lt;/code&gt;&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Cause:&lt;/strong&gt; PostgreSQL is not configured to accept connections from the Grafana server.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Solution:&lt;/strong&gt;&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;
&lt;p&gt;Edit the &lt;code&gt;pg_hba.conf&lt;/code&gt; file on the PostgreSQL server.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Add an entry to allow connections from the Grafana server:&lt;/p&gt;

&lt;div class=&#34;code-snippet &#34;&gt;&lt;div class=&#34;lang-toolbar&#34;&gt;
    &lt;span class=&#34;lang-toolbar__item lang-toolbar__item-active&#34;&gt;text&lt;/span&gt;
    &lt;span class=&#34;code-clipboard&#34;&gt;
      &lt;button x-data=&#34;app_code_snippet()&#34; x-init=&#34;init()&#34; @click=&#34;copy()&#34;&gt;
        &lt;img class=&#34;code-clipboard__icon&#34; src=&#34;/media/images/icons/icon-copy-small-2.svg&#34; alt=&#34;Copy code to clipboard&#34; width=&#34;14&#34; height=&#34;13&#34;&gt;
        &lt;span&gt;Copy&lt;/span&gt;
      &lt;/button&gt;
    &lt;/span&gt;
    &lt;div class=&#34;lang-toolbar__border&#34;&gt;&lt;/div&gt;
  &lt;/div&gt;&lt;div class=&#34;code-snippet &#34;&gt;
    &lt;pre data-expanded=&#34;false&#34;&gt;&lt;code class=&#34;language-text&#34;&gt;host    database_name    username    grafana_ip/32    md5&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Reload PostgreSQL configuration: &lt;code&gt;SELECT pg_reload_conf();&lt;/code&gt;&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;If using SSL, ensure the correct authentication method is specified (for example, &lt;code&gt;hostssl&lt;/code&gt; instead of &lt;code&gt;host&lt;/code&gt;).&lt;/p&gt;
&lt;/li&gt;
&lt;/ol&gt;
&lt;h2 id=&#34;tls-and-certificate-errors&#34;&gt;TLS and certificate errors&lt;/h2&gt;
&lt;p&gt;The following errors occur when there are issues with TLS configuration.&lt;/p&gt;
&lt;h3 id=&#34;certificate-verification-failed&#34;&gt;Certificate verification failed&lt;/h3&gt;
&lt;p&gt;&lt;strong&gt;Error message:&lt;/strong&gt; &amp;ldquo;x509: certificate signed by unknown authority&amp;rdquo; or &amp;ldquo;certificate verify failed&amp;rdquo;&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Cause:&lt;/strong&gt; Grafana cannot verify the TLS certificate presented by PostgreSQL.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Solution:&lt;/strong&gt;&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;Set the &lt;strong&gt;TLS/SSL Mode&lt;/strong&gt; to the appropriate level (&lt;code&gt;require&lt;/code&gt;, &lt;code&gt;verify-ca&lt;/code&gt;, or &lt;code&gt;verify-full&lt;/code&gt;).&lt;/li&gt;
&lt;li&gt;If using a self-signed certificate, add the CA certificate in &lt;strong&gt;TLS/SSL Auth Details&lt;/strong&gt;.&lt;/li&gt;
&lt;li&gt;Verify the certificate chain is complete and valid.&lt;/li&gt;
&lt;li&gt;Ensure the certificate has not expired.&lt;/li&gt;
&lt;li&gt;For testing only, set &lt;strong&gt;TLS/SSL Mode&lt;/strong&gt; to &lt;code&gt;disable&lt;/code&gt; (not recommended for production).&lt;/li&gt;
&lt;/ol&gt;
&lt;h3 id=&#34;ssl-not-supported&#34;&gt;SSL not supported&lt;/h3&gt;
&lt;p&gt;&lt;strong&gt;Error message:&lt;/strong&gt; &lt;code&gt;failed to connect to ... : server refused TLS connection&lt;/code&gt; or &lt;code&gt;server does not support SSL&lt;/code&gt;&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Cause:&lt;/strong&gt; The PostgreSQL server is not configured for SSL connections, but the data source requires SSL.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Solution:&lt;/strong&gt;&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;Set &lt;strong&gt;TLS/SSL Mode&lt;/strong&gt; to &lt;code&gt;disable&lt;/code&gt; if SSL is not required.&lt;/li&gt;
&lt;li&gt;Alternatively, enable SSL on the PostgreSQL server by configuring &lt;code&gt;ssl = on&lt;/code&gt; in &lt;code&gt;postgresql.conf&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;Ensure the server has valid SSL certificates configured.&lt;/li&gt;
&lt;/ol&gt;
&lt;h3 id=&#34;client-certificate-error&#34;&gt;Client certificate error&lt;/h3&gt;
&lt;p&gt;&lt;strong&gt;Error message:&lt;/strong&gt; &amp;ldquo;TLS: failed to find any PEM data in certificate input&amp;rdquo; or &amp;ldquo;could not load client certificate&amp;rdquo;&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Cause:&lt;/strong&gt; The client certificate or key is invalid or incorrectly formatted.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Solution:&lt;/strong&gt;&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;Verify the certificate and key are in PEM format.&lt;/li&gt;
&lt;li&gt;Ensure the certificate file path is correct and readable by the Grafana process.&lt;/li&gt;
&lt;li&gt;Check that the certificate and key match (belong to the same key pair).&lt;/li&gt;
&lt;li&gt;If using certificate content, ensure you&amp;rsquo;ve pasted the complete certificate including headers.&lt;/li&gt;
&lt;/ol&gt;
&lt;h2 id=&#34;database-errors&#34;&gt;Database errors&lt;/h2&gt;
&lt;p&gt;The following errors occur when there are issues with the database configuration.&lt;/p&gt;
&lt;h3 id=&#34;database-does-not-exist&#34;&gt;Database does not exist&lt;/h3&gt;
&lt;p&gt;&lt;strong&gt;Error message:&lt;/strong&gt; &lt;code&gt;failed to connect to ... : server error: FATAL: database &amp;quot;database_name&amp;quot; does not exist (SQLSTATE 3D000)&lt;/code&gt;&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Cause:&lt;/strong&gt; The specified database name is incorrect or the database doesn&amp;rsquo;t exist.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Solution:&lt;/strong&gt;&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;Verify the database name in the data source configuration.&lt;/li&gt;
&lt;li&gt;Check that the database exists: &lt;code&gt;\l&lt;/code&gt; in &lt;code&gt;psql&lt;/code&gt; or &lt;code&gt;SELECT datname FROM pg_database;&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;Ensure the database name is case-sensitive and matches exactly.&lt;/li&gt;
&lt;li&gt;Verify the user has permission to connect to the database.&lt;/li&gt;
&lt;/ol&gt;
&lt;h3 id=&#34;relation-does-not-exist&#34;&gt;Relation does not exist&lt;/h3&gt;
&lt;p&gt;&lt;strong&gt;Error message:&lt;/strong&gt; &lt;code&gt;ERROR: relation &amp;quot;table_name&amp;quot; does not exist (SQLSTATE 42P01)&lt;/code&gt;&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Cause:&lt;/strong&gt; The specified table or view does not exist, or the user cannot access it.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Solution:&lt;/strong&gt;&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;Verify the table name is correct and exists in the database.&lt;/li&gt;
&lt;li&gt;Check the schema name if the table is not in the public schema.&lt;/li&gt;
&lt;li&gt;Use fully qualified names: &lt;code&gt;schema_name.table_name&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;Verify the user has &lt;code&gt;SELECT&lt;/code&gt; permission on the table.&lt;/li&gt;
&lt;li&gt;Check the search path: &lt;code&gt;SHOW search_path;&lt;/code&gt;&lt;/li&gt;
&lt;/ol&gt;
&lt;h2 id=&#34;query-errors&#34;&gt;Query errors&lt;/h2&gt;
&lt;p&gt;The following errors occur when there are issues with SQL syntax or query execution.&lt;/p&gt;
&lt;h3 id=&#34;query-truncated-by-double-dash-in-string-literals&#34;&gt;Query truncated by double-dash in string literals&lt;/h3&gt;
&lt;p&gt;&lt;strong&gt;Error message:&lt;/strong&gt; Unexpected syntax errors or truncated results when string values contain &lt;code&gt;--&lt;/code&gt; (double dash).&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Cause:&lt;/strong&gt; In Grafana versions before 13.1, the SQL comment-stripping parser didn&amp;rsquo;t correctly handle &lt;code&gt;--&lt;/code&gt; inside single-quoted strings. A query like &lt;code&gt;WHERE name = &#39;value--suffix&#39;&lt;/code&gt; would be truncated at the &lt;code&gt;--&lt;/code&gt;, causing the rest of the query to be silently dropped. This also affected strings with consecutive hyphens (for example, &lt;code&gt;&#39;10YDE-VE-------2&#39;&lt;/code&gt; would be truncated to &lt;code&gt;&#39;10YDE-VE&lt;/code&gt;).&lt;/p&gt;
&lt;p&gt;This was fixed in Grafana 13.1 with a quote-aware comment-stripping parser (PR #121772). The fix also handles PostgreSQL dollar-quoted strings (&lt;code&gt;$$...$$&lt;/code&gt;).&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Solution:&lt;/strong&gt;&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;
&lt;p&gt;Upgrade to Grafana 13.1 or later, which includes the fix.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;If you can&amp;rsquo;t upgrade immediately, work around the issue by using PostgreSQL string concatenation to avoid literal &lt;code&gt;--&lt;/code&gt; in your queries:&lt;/p&gt;

&lt;div class=&#34;code-snippet &#34;&gt;&lt;div class=&#34;lang-toolbar&#34;&gt;
    &lt;span class=&#34;lang-toolbar__item lang-toolbar__item-active&#34;&gt;SQL&lt;/span&gt;
    &lt;span class=&#34;code-clipboard&#34;&gt;
      &lt;button x-data=&#34;app_code_snippet()&#34; x-init=&#34;init()&#34; @click=&#34;copy()&#34;&gt;
        &lt;img class=&#34;code-clipboard__icon&#34; src=&#34;/media/images/icons/icon-copy-small-2.svg&#34; alt=&#34;Copy code to clipboard&#34; width=&#34;14&#34; height=&#34;13&#34;&gt;
        &lt;span&gt;Copy&lt;/span&gt;
      &lt;/button&gt;
    &lt;/span&gt;
    &lt;div class=&#34;lang-toolbar__border&#34;&gt;&lt;/div&gt;
  &lt;/div&gt;&lt;div class=&#34;code-snippet &#34;&gt;
    &lt;pre data-expanded=&#34;false&#34;&gt;&lt;code class=&#34;language-sql&#34;&gt;WHERE name = &amp;#39;value&amp;#39; || &amp;#39;--&amp;#39; || &amp;#39;suffix&amp;#39;&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Alternatively, use a parameterized approach with a template variable for the value.&lt;/p&gt;
&lt;/li&gt;
&lt;/ol&gt;
&lt;h3 id=&#34;query-syntax-error&#34;&gt;Query syntax error&lt;/h3&gt;
&lt;p&gt;&lt;strong&gt;Error message:&lt;/strong&gt; &lt;code&gt;ERROR: syntax error at or near &amp;quot;keyword&amp;quot; (SQLSTATE 42601)&lt;/code&gt;&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Cause:&lt;/strong&gt; The SQL query contains invalid syntax.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Solution:&lt;/strong&gt;&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;Check your query syntax for typos or invalid keywords.&lt;/li&gt;
&lt;li&gt;Verify column and table names are correctly quoted if they contain special characters or are reserved words.&lt;/li&gt;
&lt;li&gt;Use double quotes for identifiers: &lt;code&gt;&amp;quot;column_name&amp;quot;&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;Test the query directly in a PostgreSQL client such as &lt;code&gt;psql&lt;/code&gt;.&lt;/li&gt;
&lt;/ol&gt;
&lt;h3 id=&#34;column-does-not-exist&#34;&gt;Column does not exist&lt;/h3&gt;
&lt;p&gt;&lt;strong&gt;Error message:&lt;/strong&gt; &lt;code&gt;ERROR: column &amp;quot;column_name&amp;quot; does not exist (SQLSTATE 42703)&lt;/code&gt;&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Cause:&lt;/strong&gt; The specified column name is incorrect or doesn&amp;rsquo;t exist in the table.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Solution:&lt;/strong&gt;&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;Verify the column name is spelled correctly.&lt;/li&gt;
&lt;li&gt;Check that column names are case-sensitive in PostgreSQL when quoted.&lt;/li&gt;
&lt;li&gt;Use the correct quoting for column names: &lt;code&gt;&amp;quot;Column_Name&amp;quot;&lt;/code&gt; for case-sensitive names.&lt;/li&gt;
&lt;li&gt;Verify the column exists in the table: &lt;code&gt;\d table_name&lt;/code&gt; in &lt;code&gt;psql&lt;/code&gt;.&lt;/li&gt;
&lt;/ol&gt;
&lt;h3 id=&#34;no-time-column-found&#34;&gt;No time column found&lt;/h3&gt;
&lt;p&gt;&lt;strong&gt;Error message:&lt;/strong&gt; &amp;ldquo;no time column found&amp;rdquo; or time series visualization shows no data&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Cause:&lt;/strong&gt; The query result does not include a properly formatted time column.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Solution:&lt;/strong&gt;&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;Ensure your query includes a column named &lt;code&gt;time&lt;/code&gt; that returns a timestamp or epoch value.&lt;/li&gt;
&lt;li&gt;Use an alias to rename your time column: &lt;code&gt;SELECT created_at AS time&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;Ensure the time column is of type &lt;code&gt;timestamp&lt;/code&gt;, &lt;code&gt;timestamptz&lt;/code&gt;, or a numeric epoch value.&lt;/li&gt;
&lt;li&gt;Order results by the time column: &lt;code&gt;ORDER BY time ASC&lt;/code&gt;.&lt;/li&gt;
&lt;/ol&gt;
&lt;h3 id=&#34;macro-expansion-error&#34;&gt;Macro expansion error&lt;/h3&gt;
&lt;p&gt;&lt;strong&gt;Error message:&lt;/strong&gt; &amp;ldquo;macro &amp;lsquo;$__timeFilter&amp;rsquo; not found&amp;rdquo; or incorrect query results with macros&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Cause:&lt;/strong&gt; Grafana macros aren&amp;rsquo;t being properly expanded.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Solution:&lt;/strong&gt;&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;Verify the macro syntax is correct, for example &lt;code&gt;$\_\_timeFilter(time_column)&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;Ensure the column name passed to the macro exists in your table.&lt;/li&gt;
&lt;li&gt;Check that the macro isn&amp;rsquo;t inside a SQL comment (&lt;code&gt;--&lt;/code&gt; or &lt;code&gt;/* */&lt;/code&gt;). Grafana strips comments before expanding macros, so macros inside comments are silently ignored.&lt;/li&gt;
&lt;li&gt;Use the &lt;strong&gt;Preview&lt;/strong&gt; toggle in Builder mode to see the expanded query.&lt;/li&gt;
&lt;li&gt;Open the 
    &lt;a href=&#34;/docs/grafana/v13.1/panels-visualizations/query-transform-data/#query-inspector&#34;&gt;Query inspector&lt;/a&gt; to view the exact SQL sent to PostgreSQL after macro expansion.&lt;/li&gt;
&lt;li&gt;For time-based macros, ensure the column contains timestamp data.&lt;/li&gt;
&lt;/ol&gt;
&lt;h2 id=&#34;performance-issues&#34;&gt;Performance issues&lt;/h2&gt;
&lt;p&gt;The following issues relate to slow query execution or resource constraints.&lt;/p&gt;
&lt;h3 id=&#34;query-timeout&#34;&gt;Query timeout&lt;/h3&gt;
&lt;p&gt;&lt;strong&gt;Error message:&lt;/strong&gt; &amp;ldquo;canceling statement due to statement timeout&amp;rdquo; or &amp;ldquo;query timeout&amp;rdquo;&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Cause:&lt;/strong&gt; The query took longer than the configured timeout.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Solution:&lt;/strong&gt;&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;Reduce the time range of your query.&lt;/li&gt;
&lt;li&gt;Add indexes to columns used in WHERE clauses and joins.&lt;/li&gt;
&lt;li&gt;Use the &lt;code&gt;$\_\_timeFilter&lt;/code&gt; macro to limit data to the dashboard time range.&lt;/li&gt;
&lt;li&gt;Increase the statement timeout in PostgreSQL if you have admin access.&lt;/li&gt;
&lt;li&gt;Optimize your query to reduce complexity.&lt;/li&gt;
&lt;/ol&gt;
&lt;h3 id=&#34;too-many-connections&#34;&gt;Too many connections&lt;/h3&gt;
&lt;p&gt;&lt;strong&gt;Error message:&lt;/strong&gt; &lt;code&gt;failed to connect to ... : server error: FATAL: too many connections for role &amp;quot;username&amp;quot; (SQLSTATE 53300)&lt;/code&gt; or &lt;code&gt;connection pool exhausted&lt;/code&gt;&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Cause:&lt;/strong&gt; The maximum number of connections to PostgreSQL has been reached.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Solution:&lt;/strong&gt;&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;Reduce the &lt;strong&gt;Max open&lt;/strong&gt; connections setting in the data source configuration.&lt;/li&gt;
&lt;li&gt;Increase &lt;code&gt;max_connections&lt;/code&gt; in PostgreSQL&amp;rsquo;s &lt;code&gt;postgresql.conf&lt;/code&gt; if you have admin access.&lt;/li&gt;
&lt;li&gt;Check for connection leaks in other applications connecting to the same database.&lt;/li&gt;
&lt;li&gt;Enable &lt;strong&gt;Auto max idle&lt;/strong&gt; to automatically manage idle connections.&lt;/li&gt;
&lt;/ol&gt;
&lt;h3 id=&#34;slow-query-performance&#34;&gt;Slow query performance&lt;/h3&gt;
&lt;p&gt;&lt;strong&gt;Cause:&lt;/strong&gt; Queries take a long time to execute.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Solution:&lt;/strong&gt;&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;Reduce the time range of your query.&lt;/li&gt;
&lt;li&gt;Add appropriate indexes to your tables.&lt;/li&gt;
&lt;li&gt;Use the &lt;code&gt;$\_\_timeFilter&lt;/code&gt; macro to limit the data scanned.&lt;/li&gt;
&lt;li&gt;Increase the &lt;strong&gt;Min time interval&lt;/strong&gt; setting to reduce the number of data points.&lt;/li&gt;
&lt;li&gt;Use &lt;code&gt;EXPLAIN ANALYZE&lt;/code&gt; in PostgreSQL to identify query bottlenecks.&lt;/li&gt;
&lt;li&gt;Consider using materialized views for complex aggregations.&lt;/li&gt;
&lt;/ol&gt;
&lt;h2 id=&#34;provisioning-errors&#34;&gt;Provisioning errors&lt;/h2&gt;
&lt;p&gt;The following errors occur when provisioning the data source via YAML.&lt;/p&gt;
&lt;h3 id=&#34;invalid-provisioning-configuration&#34;&gt;Invalid provisioning configuration&lt;/h3&gt;
&lt;p&gt;&lt;strong&gt;Error message:&lt;/strong&gt; &amp;ldquo;metric request error&amp;rdquo; or data source test fails after provisioning&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Cause:&lt;/strong&gt; The provisioning YAML file contains incorrect configuration.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Solution:&lt;/strong&gt;&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;Ensure parameter names match the expected format exactly.&lt;/li&gt;
&lt;li&gt;Verify the database name is &lt;strong&gt;not&lt;/strong&gt; included in the URL.&lt;/li&gt;
&lt;li&gt;Use the correct format for the URL: &lt;code&gt;hostname:port&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;Check that string values are properly quoted in the YAML file.&lt;/li&gt;
&lt;li&gt;Refer to the 
    &lt;a href=&#34;/docs/grafana/v13.1/datasources/postgres/configure/#provision-the-data-source&#34;&gt;provisioning example&lt;/a&gt; for the correct format.&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;Example correct configuration:&lt;/p&gt;

&lt;div class=&#34;code-snippet &#34;&gt;&lt;div class=&#34;lang-toolbar&#34;&gt;
    &lt;span class=&#34;lang-toolbar__item lang-toolbar__item-active&#34;&gt;YAML&lt;/span&gt;
    &lt;span class=&#34;code-clipboard&#34;&gt;
      &lt;button x-data=&#34;app_code_snippet()&#34; x-init=&#34;init()&#34; @click=&#34;copy()&#34;&gt;
        &lt;img class=&#34;code-clipboard__icon&#34; src=&#34;/media/images/icons/icon-copy-small-2.svg&#34; alt=&#34;Copy code to clipboard&#34; width=&#34;14&#34; height=&#34;13&#34;&gt;
        &lt;span&gt;Copy&lt;/span&gt;
      &lt;/button&gt;
    &lt;/span&gt;
    &lt;div class=&#34;lang-toolbar__border&#34;&gt;&lt;/div&gt;
  &lt;/div&gt;&lt;div class=&#34;code-snippet &#34;&gt;
    &lt;pre data-expanded=&#34;false&#34;&gt;&lt;code class=&#34;language-yaml&#34;&gt;datasources:
  - name: Postgres
    type: postgres
    url: localhost:5432
    user: grafana
    secureJsonData:
      password: &amp;#39;Password!&amp;#39;
    jsonData:
      database: grafana
      sslmode: &amp;#39;disable&amp;#39;&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;h2 id=&#34;other-common-issues&#34;&gt;Other common issues&lt;/h2&gt;
&lt;p&gt;The following issues don&amp;rsquo;t produce specific error messages but are commonly encountered.&lt;/p&gt;
&lt;h3 id=&#34;empty-query-results&#34;&gt;Empty query results&lt;/h3&gt;
&lt;p&gt;&lt;strong&gt;Cause:&lt;/strong&gt; The query returns no data.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Solution:&lt;/strong&gt;&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;Verify the time range includes data in your database.&lt;/li&gt;
&lt;li&gt;Check that table and column names are correct.&lt;/li&gt;
&lt;li&gt;Test the query directly in PostgreSQL.&lt;/li&gt;
&lt;li&gt;Ensure filters are not excluding all data.&lt;/li&gt;
&lt;li&gt;Verify the &lt;code&gt;$\_\_timeFilter&lt;/code&gt; macro is using the correct time column.&lt;/li&gt;
&lt;/ol&gt;
&lt;h3 id=&#34;timescaledb-functions-not-available&#34;&gt;TimescaleDB functions not available&lt;/h3&gt;
&lt;p&gt;&lt;strong&gt;Cause:&lt;/strong&gt; TimescaleDB-specific functions like &lt;code&gt;time_bucket&lt;/code&gt; are not available in the query builder.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Solution:&lt;/strong&gt;&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;Enable the &lt;strong&gt;TimescaleDB&lt;/strong&gt; toggle in the data source configuration under &lt;strong&gt;PostgreSQL Options&lt;/strong&gt;.&lt;/li&gt;
&lt;li&gt;Verify TimescaleDB is installed and enabled in your PostgreSQL database.&lt;/li&gt;
&lt;li&gt;Check that the &lt;code&gt;timescaledb&lt;/code&gt; extension is created: &lt;code&gt;CREATE EXTENSION IF NOT EXISTS timescaledb;&lt;/code&gt;&lt;/li&gt;
&lt;/ol&gt;
&lt;h3 id=&#34;data-appears-delayed-or-missing-recent-points&#34;&gt;Data appears delayed or missing recent points&lt;/h3&gt;
&lt;p&gt;&lt;strong&gt;Cause:&lt;/strong&gt; The visualization doesn&amp;rsquo;t show the most recent data.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Solution:&lt;/strong&gt;&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;Check the dashboard time range and refresh settings.&lt;/li&gt;
&lt;li&gt;Verify the &lt;strong&gt;Min time interval&lt;/strong&gt; is not set too high.&lt;/li&gt;
&lt;li&gt;Ensure data has been committed to the database (not in an uncommitted transaction).&lt;/li&gt;
&lt;li&gt;Check for clock synchronization issues between Grafana and PostgreSQL.&lt;/li&gt;
&lt;/ol&gt;
&lt;h2 id=&#34;get-additional-help&#34;&gt;Get additional help&lt;/h2&gt;
&lt;p&gt;If you continue to experience issues after following this troubleshooting guide:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;Check the &lt;a href=&#34;https://www.postgresql.org/docs/&#34; target=&#34;_blank&#34; rel=&#34;noopener noreferrer&#34;&gt;PostgreSQL documentation&lt;/a&gt; for database-specific guidance.&lt;/li&gt;
&lt;li&gt;Review the &lt;a href=&#34;https://community.grafana.com/&#34; target=&#34;_blank&#34; rel=&#34;noopener noreferrer&#34;&gt;Grafana community forums&lt;/a&gt; for similar issues.&lt;/li&gt;
&lt;li&gt;Contact Grafana Support if you are a Cloud Pro, Cloud Contracted, or Enterprise user.&lt;/li&gt;
&lt;li&gt;When reporting issues, include:
&lt;ul&gt;
&lt;li&gt;Grafana version&lt;/li&gt;
&lt;li&gt;PostgreSQL version&lt;/li&gt;
&lt;li&gt;Error messages (redact sensitive information)&lt;/li&gt;
&lt;li&gt;Steps to reproduce&lt;/li&gt;
&lt;li&gt;Relevant configuration such as data source settings, TLS mode, and connection limits (redact passwords and other credentials)&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ol&gt;
]]></content><description>&lt;h1 id="troubleshoot-postgresql-data-source-issues">Troubleshoot PostgreSQL data source issues&lt;/h1>
&lt;p>This document provides troubleshooting information for common errors you may encounter when using the PostgreSQL data source in Grafana.&lt;/p>
&lt;h2 id="connection-errors">Connection errors&lt;/h2>
&lt;p>The following errors occur when Grafana cannot establish or maintain a connection to PostgreSQL.&lt;/p></description></item></channel></rss>