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

# Querying ClickHouse's system database

> Monitor ClickHouse Cloud by querying system tables directly

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

All ClickHouse instances come with a set of [system tables](/reference/system-tables/overview) contained in the `system` database that contain information about:

* Server states, processes, and environment.
* Server's internal processes.
* Options used when the ClickHouse binary was built.

Directly querying these tables is useful for monitoring ClickHouse deployments, especially for deep introspection and debugging.

<h2 id="using-cloud-console">
  Using the ClickHouse Cloud Console
</h2>

The ClickHouse Cloud console comes with a [SQL console](/products/cloud/features/sql-console-features/sql-console) and [dashboarding tools](/products/cloud/features/sql-console-features/dashboards) that can be used for querying system tables. For example, the query below reviews how many (and how often) new parts are created during the last two hours:

```sql theme={null}
SELECT
    count() AS new_parts,
    toStartOfMinute(event_time) AS modification_time_m,
    table,
    sum(rows) AS total_written_rows,
    formatReadableSize(sum(size_in_bytes)) AS total_bytes_on_disk
FROM clusterAllReplicas(default, system.part_log)
WHERE (event_type = 'NewPart') AND (event_time > (now() - toIntervalHour(2)))
GROUP BY
    modification_time_m,
    table
ORDER BY
    modification_time_m ASC,
    table DESC
```

<Tip>
  **More example queries**

  For additional monitoring queries, see the following resources:

  * [Useful queries for troubleshooting](/resources/support-center/knowledge-base/queries-sql/useful-queries-for-troubleshooting)
  * [Monitoring and troubleshooting insert queries](https://clickhouse.com/blog/monitoring-troubleshooting-insert-queries-clickhouse)
  * [Monitoring and troubleshooting select queries](https://clickhouse.com/blog/monitoring-troubleshooting-select-queries-clickhouse)

  You can also use these queries to [create a custom dashboard](https://clickhouse.com/blog/essential-monitoring-queries-creating-a-dashboard-in-clickHouse-cloud) in the Cloud Console.
</Tip>

<h2 id="built-in-advanced-observability-dashboard">
  Built-in advanced observability dashboard
</h2>

ClickHouse comes with a built-in advanced observability dashboard feature which can be accessed by `$HOST:$PORT/dashboard` (requires user and password) that shows Cloud Overview metrics contained in `system.dashboards`.

<Image img="https://mintcdn.com/private-7c7dfe99-mintlify-8a08bda2/Crkay9vSr-K_Gf1T/images/cloud/manage/monitoring/native_advanced_dashboard.png?fit=max&auto=format&n=Crkay9vSr-K_Gf1T&q=85&s=d880b16319a745fb575903dc9ea9beb0" size="lg" alt="Native advanced observability dashboard" border width="1600" height="870" data-path="images/cloud/manage/monitoring/native_advanced_dashboard.png" />

<Note>
  This dashboard requires direct authentication to the ClickHouse instance and is separate from the [Cloud Console Advanced Dashboard](/products/cloud/features/monitoring/cloud-console#advanced-dashboard), which is accessible through the Cloud Console UI without additional authentication.
</Note>

For more information on the available visualizations and how to use them for troubleshooting, see the [advanced dashboard documentation](/products/cloud/features/monitoring/advanced-dashboard).

<h2 id="querying-across-nodes">
  Querying across nodes and versions
</h2>

To comprehensively view the entire cluster, users can leverage the `clusterAllReplicas` function in combination with the `merge` function. The `clusterAllReplicas` function allows querying system tables across all replicas within the "default" cluster, consolidating node-specific data into a unified result. When combined with the `merge` function, this can be used to target all system data for a specific table in a cluster.

For example, to find the top 5 longest-running queries across all replicas in the last hour:

```sql theme={null}
SELECT
    type,
    event_time,
    query_duration_ms,
    query,
    read_rows,
    tables
FROM clusterAllReplicas(default, system.query_log)
WHERE event_time >= (now() - toIntervalMinute(60)) AND type = 'QueryFinish'
ORDER BY query_duration_ms DESC
LIMIT 5
FORMAT VERTICAL
```

This approach is particularly valuable for monitoring and debugging cluster-wide operations, ensuring users can effectively analyze the health and performance of their ClickHouse Cloud deployment.

For more details, see [querying across nodes](/reference/system-tables/overview#querying-across-nodes).

<h2 id="system-considerations">
  System considerations
</h2>

<Warning>
  Querying system tables directly adds query load to your production service, prevents ClickHouse Cloud instances from idling (which can impact costs), and couples monitoring availability to production system health. If the production system fails, monitoring may also be affected.
</Warning>

For real-time production monitoring with operational separation, consider using the [Prometheus-compatible metrics endpoint](/products/cloud/features/monitoring/prometheus) or the [Cloud Console dashboards](/products/cloud/features/monitoring/cloud-console), both of which use pre-scraped metrics and do not issue queries to the underlying service.

<h2 id="related">
  Related pages
</h2>

* [System tables reference](/reference/system-tables/overview) — Full reference for all available system tables
* [Cloud Console monitoring](/products/cloud/features/monitoring/cloud-console) — Zero-setup dashboards that don't impact service performance
* [Prometheus endpoint](/products/cloud/features/monitoring/prometheus) — Export metrics to external monitoring tools
* [Advanced dashboard](/products/cloud/features/monitoring/advanced-dashboard) — Detailed reference for dashboard visualizations
