> ## Documentation Index
> Fetch the complete documentation index at: https://private-7c7dfe99-fix-nav-issues.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

> Introduction to using ClickHouse with Grafana

# ClickHouse data source plugin for Grafana

export const ClickHouseSupportedBadge = () => {
  return <div className="ClickHouseSupportedBadge">
            <div className="ClickHouseSupportedIcon">
                <svg width="16" height="16" viewBox="0 0 16 16" fill="none" xmlns="http://www.w3.org/2000/svg">
                    <path d="M1.30762 1.39073C1.30762 1.3103 1.37465 1.22986 1.46849 1.22986H2.64824C2.72868 1.22986 2.80912 1.29689 2.80912 1.39073V14.4886C2.80912 14.5691 2.74209 14.6495 2.64824 14.6495H1.46849C1.38805 14.6495 1.30762 14.5825 1.30762 14.4886V1.39073Z" fill="currentColor" />
                    <path d="M4.2832 1.39073C4.2832 1.3103 4.35023 1.22986 4.44408 1.22986H5.62383C5.70427 1.22986 5.7847 1.29689 5.7847 1.39073V14.4886C5.7847 14.5691 5.71767 14.6495 5.62383 14.6495H4.44408C4.36364 14.6495 4.2832 14.5825 4.2832 14.4886V1.39073Z" fill="currentColor" />
                    <path d="M7.25977 1.39073C7.25977 1.3103 7.3268 1.22986 7.42064 1.22986H8.60039C8.68083 1.22986 8.76127 1.29689 8.76127 1.39073V14.4886C8.76127 14.5691 8.69423 14.6495 8.60039 14.6495H7.42064C7.3402 14.6495 7.25977 14.5825 7.25977 14.4886V1.39073Z" fill="currentColor" />
                    <path d="M10.2354 1.39073C10.2354 1.3103 10.3024 1.22986 10.3962 1.22986H11.576C11.6564 1.22986 11.7369 1.29689 11.7369 1.39073V14.4886C11.7369 14.5691 11.6698 14.6495 11.576 14.6495H10.3962C10.3158 14.6495 10.2354 14.5825 10.2354 14.4886V1.39073Z" fill="currentColor" />
                    <path d="M13.2256 6.6057C13.2256 6.52526 13.2926 6.44482 13.3865 6.44482H14.5662C14.6466 6.44482 14.7271 6.51186 14.7271 6.6057V9.27354C14.7271 9.35398 14.6601 9.43442 14.5662 9.43442H13.3865C13.306 9.43442 13.2256 9.36739 13.2256 9.27354V6.6057Z" fill="currentColor" />
                </svg>
            </div>
            ClickHouse Supported
        </div>;
};

export const Image = ({img, alt, size}) => {
  return <Frame>
      <img src={img} alt={alt} />
    </Frame>;
};

With Grafana you can explore and share all of your data through dashboards.
Grafana requires a plugin to connect to ClickHouse, which is easily installed within their UI.

<div class="vimeo-container">
  <Frame>
    <iframe
      src="//www.youtube.com/embed/bRce9xWiqQM"
      frameborder="0"
      allow="autoplay;
fullscreen;
picture-in-picture"
      allowfullscreen
    />
  </Frame>
</div>

<h2 id="1-gather-your-connection-details">
  1. Gather your connection details
</h2>

To connect to ClickHouse with native TCP you need this information:

| Parameters                | Description                                                                                                   |
| ------------------------- | ------------------------------------------------------------------------------------------------------------- |
| `HOST` and `PORT`         | Typically, the port is 9440 when using TLS, or 9000 when not using TLS.                                       |
| `DATABASE NAME`           | Out of the box there is a database named `default`, use the name of the database that you want to connect to. |
| `USERNAME` and `PASSWORD` | Out of the box the username is `default`. Use the username appropriate for your use case.                     |

The details for your ClickHouse Cloud service are available in the ClickHouse Cloud console.
Select the service that you will connect to and click **Connect**:

<Image img="https://mintcdn.com/private-7c7dfe99-fix-nav-issues/1oh4rjwfuHRS2yL2/images/_snippets/cloud-connect-button.png?fit=max&auto=format&n=1oh4rjwfuHRS2yL2&q=85&s=81c1524ac8ac2dac27e1558f13fcfd29" size="md" alt="ClickHouse Cloud service connect button" border width="998" height="932" data-path="images/_snippets/cloud-connect-button.png" />

Choose **Native**, and the details are available in an example `clickhouse-client` command.

<Image img="https://mintcdn.com/private-7c7dfe99-fix-nav-issues/1oh4rjwfuHRS2yL2/images/_snippets/connection-details-native.png?fit=max&auto=format&n=1oh4rjwfuHRS2yL2&q=85&s=9ba181c45544519e5740b47a78269f38" size="md" alt="ClickHouse Cloud Native TCP connection details" border width="1290" height="1176" data-path="images/_snippets/connection-details-native.png" />

If you're using self-managed ClickHouse, the connection details are set by your ClickHouse administrator.

<h2 id="2-making-a-read-only-user">
  2. Making a read-only user
</h2>

When connecting ClickHouse to a data visualization tool like Grafana, it is recommended to make a read-only user to protect your data from unwanted modifications.

Grafana doesn't validate that queries are safe. Queries can contain any SQL statement, including `DELETE` and `INSERT`.

To configure a read-only user, follow these steps:

1. Create a `readonly` user profile following the [Creating Users and Roles in ClickHouse](/concepts/features/security/access-rights) guide.
2. Ensure the `readonly` user has enough permission to modify the `max_execution_time` setting required by the underlying [clickhouse-go client](https://github.com/ClickHouse/clickhouse-go).
3. If you're using a public ClickHouse instance, it isn't recommended to set `readonly=2` in the `readonly` profile. Instead, leave `readonly=1` and set the constraint type of `max_execution_time` to [changeable\_in\_readonly](/concepts/features/configuration/settings/constraints-on-settings) to allow modification of this setting.

<h2 id="3--install-the-clickhouse-plugin-for-grafana">
  3) Install the ClickHouse plugin for Grafana
</h2>

Before Grafana can connect to ClickHouse, you need to install the appropriate Grafana plugin. Assuming you're logged in to Grafana, follow these steps:

1. From the **Connections** page in the sidebar, select the **Add new connection** tab.

2. Search for **ClickHouse** and click on the signed plugin by Grafana Labs:

   <Image size="md" img="https://mintcdn.com/private-7c7dfe99-fix-nav-issues/ujc-kN615--sFi3M/images/integrations/data-visualization/grafana/search.png?fit=max&auto=format&n=ujc-kN615--sFi3M&q=85&s=4f657f864f3654fb426b5a7d3dae99ed" alt="Select the ClickHouse plugin on the connections page" border width="784" height="365" data-path="images/integrations/data-visualization/grafana/search.png" />

3. On the next screen, click the **Install** button:

   <Image size="md" img="https://mintcdn.com/private-7c7dfe99-fix-nav-issues/ujc-kN615--sFi3M/images/integrations/data-visualization/grafana/install.png?fit=max&auto=format&n=ujc-kN615--sFi3M&q=85&s=13ae948501525da3aec248ce79092ebe" alt="Install the ClickHouse plugin" border width="865" height="364" data-path="images/integrations/data-visualization/grafana/install.png" />

<h2 id="4-define-a-clickhouse-data-source">
  4) Define a ClickHouse data source
</h2>

1. Once the installation is complete, click the **Add new data source** button. (You can also add a data source from the **Data sources** tab on the **Connections** page.)

   <Image size="md" img="https://mintcdn.com/private-7c7dfe99-fix-nav-issues/4Hi2sd8mn4aAdMgN/images/integrations/data-visualization/grafana/add_new_ds.png?fit=max&auto=format&n=4Hi2sd8mn4aAdMgN&q=85&s=ec33215336fe20209426e206c3a99d93" alt="Create a ClickHouse data source" border width="886" height="383" data-path="images/integrations/data-visualization/grafana/add_new_ds.png" />

2. Either scroll down and find the **ClickHouse** data source type, or you can search for it in the search bar of the **Add data source** page. Select the **ClickHouse** data source and the following page will appear:

<Image size="md" img="https://mintcdn.com/private-7c7dfe99-fix-nav-issues/ujc-kN615--sFi3M/images/integrations/data-visualization/grafana/quick_config.png?fit=max&auto=format&n=ujc-kN615--sFi3M&q=85&s=1a1ef2e9ddc9f8e6102f38b0f5a3db6a" alt="Connection configuration page" border width="976" height="1050" data-path="images/integrations/data-visualization/grafana/quick_config.png" />

3. Enter your server settings and credentials. The key settings are:

* **Server host address:** the hostname of your ClickHouse service.
* **Server port:** the port for your ClickHouse service. Will be different depending on server configuration and protocol.
* **Protocol** the protocol used to connect to your ClickHouse service.
* **Secure connection** enable if your server requires a secure connection.
* **Username** and **Password**: enter your ClickHouse user credentials. If you haven't configured any users, try `default` for the username. It is recommended to [configure a read-only user](#2-making-a-read-only-user).

For more settings, check the [plugin configuration](/integrations/connectors/data-visualization/grafana/config) documentation.

4. Click the **Save & test** button to verify that Grafana can connect to your ClickHouse service. If successful, you will see a **Data source is working** message:

   <Image size="md" img="https://mintcdn.com/private-7c7dfe99-fix-nav-issues/ujc-kN615--sFi3M/images/integrations/data-visualization/grafana/valid_ds.png?fit=max&auto=format&n=ujc-kN615--sFi3M&q=85&s=af7b7b11dbeb790f8986b734f95e64ca" alt="Select Save & test" border width="975" height="213" data-path="images/integrations/data-visualization/grafana/valid_ds.png" />

<h2 id="5-next-steps">
  5) Next steps
</h2>

Your data source is now ready to use! Learn more about how to build queries with the [query builder](/integrations/connectors/data-visualization/grafana/query-builder).

For more details on configuration, check the [plugin configuration](/integrations/connectors/data-visualization/grafana/config) documentation.

If you're looking for more information that isn't included in these docs, check the [plugin repository on GitHub](https://github.com/grafana/clickhouse-datasource).

<h2 id="upgrading-plugin-versions">
  Upgrading plugin versions
</h2>

Starting with v4, configurations and queries are able to be upgraded as new versions are released.

Configurations and queries from v3 are migrated to v4 as they're opened. While the old configurations and dashboards will load in v4, the migration isn't persisted until they're saved again in the new version. If you notice any issues when opening an old configuration/query, discard your changes and [report the issue on GitHub](https://github.com/grafana/clickhouse-datasource/issues).

The plugin can't downgrade to previous versions if the configuration/query was created with a newer version.
