content/influxdb3/clustered/admin/query-system-data.md
{{< product-name >}} stores data related to queries, tables, partitions, and compaction in system tables within your cluster. System tables contain time series data used by and generated from the {{< product-name >}} internal monitoring system. You can query the cluster system tables for information about your cluster.
[!Warning]
May impact cluster performance
Querying InfluxDB 3 system tables may impact write and query performance of your {{< product-name omit=" Clustered" >}} cluster. Use filters to optimize queries to reduce impact to your cluster.
<!--------------- UPDATE THE DATE BELOW AS EXAMPLES ARE UPDATED --------------->System tables are subject to change
System tables are not part of InfluxDB's stable API and may change with new releases. The provided schema information and query examples are valid as of September 18, 2024. If you detect a schema change or a non-functioning query example, please submit an issue.
<!--------------- UPDATE THE DATE ABOVE AS EXAMPLES ARE UPDATED --------------->
[!Note] Querying system tables with
influxctlrequiresinfluxctlv2.8.0 or newer.
Use the influxctl query command
and SQL to query system tables.
Provide the following:
Enable system tables with the --enable-system-tables command flag.
Database token: A database token
with read permissions on the specified database. Uses the token setting from
the influxctl connection profile
or the --token command flag.
Database name: The name of the database to query information about.
Uses the database setting from the
influxctl connection profile
or the --database command flag.
SQL query: The SQL query to execute.
Pass the query in one of the following ways:
-) to read the query from stdin{{% code-placeholders "DATABASE_(TOKEN|NAME)|SQL_QUERY" %}}
{{< code-tabs-wrapper >}} {{% code-tabs %}} string file stdin {{% /code-tabs %}} {{% code-tab-content %}}
influxctl query \
--enable-system-tables \
--database DATABASE_NAME \
--token DATABASE_TOKEN \
"SQL_QUERY"
{{% /code-tab-content %}} {{% code-tab-content %}}
influxctl query \
--enable-system-tables \
--database DATABASE_NAME \
--token DATABASE_TOKEN \
/path/to/query.sql
{{% /code-tab-content %}} {{% code-tab-content %}}
cat ./query.sql | influxctl query \
--enable-system-tables \
--database DATABASE_NAME \
--token DATABASE_TOKEN \
-
{{% /code-tab-content %}} {{< /code-tabs-wrapper >}}
{{% /code-placeholders %}}
Replace the following:
DATABASE_TOKEN{{% /code-placeholder-key %}}:
A database token with read access to the specified databaseDATABASE_NAME{{% /code-placeholder-key %}}:
The name of the database to query information about.SQL_QUERY{{% /code-placeholder-key %}}:
The SQL query to execute. For examples, see
System query examples.When prompted, enter y to acknowledge the potential impact querying system
tables may have on your cluster.
Querying InfluxDB 3 system tables may impact the performance of your {{< product-name omit=" Clustered" >}} cluster. As you write data to a cluster, the number of partitions and Parquet files can increase to a point that impacts system table performance. Queries that took milliseconds with fewer files and partitions might take 10 seconds or longer as files and partitions increase.
Use the following filters to optimize your system table queries and reduce the impact on your cluster's performance.
In your queries, replace the following:
TABLE_NAME{{% /code-placeholder-key %}}: the table to retrieve partitions forPARTITION_ID{{% /code-placeholder-key %}}: a partition ID (int64)PARTITION_KEY{{% /code-placeholder-key %}}: a partition key
derived from the table's partition template.
The default format is %Y-%m-%d (for example, 2024-01-01).When querying the system.tables, system.partitions, or system.compactor tables, use the
WHERE clause to filter by table_name .
{{% code-placeholders "TABLE_NAME" %}}
SELECT * FROM system.partitions WHERE table_name = 'TABLE_NAME'
{{% /code-placeholders%}}
When querying the system.partitions or system.compactor tables, use the WHERE clause to
filter by partition_key.
{{% code-placeholders "PARTITION_KEY" %}}
SELECT * FROM system.partitions WHERE partition_key = 'PARTITION_KEY'
{{% /code-placeholders %}}
To further improve performance, use AND to pair partition_key with table_name--for example:
{{% code-placeholders "TABLE_NAME|PARTITION_KEY" %}}
SELECT *
FROM system.partitions
WHERE
table_name = 'TABLE_NAME'
AND partition_key = 'PARTITION_KEY';
{{% /code-placeholders %}}
{{% code-placeholders "TABLE_NAME|PARTITION_KEY" %}}
SELECT *
FROM system.compactor
WHERE
table_name = 'TABLE_NAME'
AND partition_key = 'PARTITION_KEY';
{{% /code-placeholders %}}
When querying the system.partitions or system.compactor table, use the WHERE clause to
filter by partition_id .
{{% code-placeholders "PARTITION_ID" %}}
SELECT * FROM system.partitions WHERE partition_id = PARTITION_ID
{{% /code-placeholders %}}
For the most optimized approach, use AND to pair partition_id with table_name--for example:
{{% code-placeholders "TABLE_NAME|PARTITION_ID" %}}
SELECT *
FROM system.partitions
WHERE
table_name = 'TABLE_NAME'
AND partition_id = PARTITION_ID;
{{% /code-placeholders %}}
Although you don't need to pair partition_id with table_name (because a partition ID is unique within a cluster),
it's the most optimized approach, especially when you have many tables in a database.
To retrieve a partition ID, query system.partitions for a table_name and partition_key pair--for example:
{{% code-placeholders "TABLE_NAME|PARTITION_KEY" %}}
SELECT
table_name,
partition_key,
partition_id
FROM system.partitions
WHERE
table_name = 'TABLE_NAME'
AND partition_key = 'PARTITION_KEY';
{{% /code-placeholders %}}
The result contains the partition_id:
| table_name | partition_key | partition_id |
|---|---|---|
| weather | 43 | 2020-05-27 | 1362 |
Use the AND, OR, or IN keywords to combine filters in your query.
Use OR or IN conditions when filtering for different values in the same column--for example:
WHERE partition_id = 1 OR partition_id = 2
Use IN to make multiple OR conditions more readable--for example:
WHERE table_name IN ('foo', 'bar', 'baz')
Avoid mixing different columns in OR conditions, as this won't improve performance--for example:
WHERE table_name = 'foo' OR partition_id = 2 -- This will not improve performance
[!Warning] System tables are subject to change.
Data in system.tables, system.partitions, and system.compactor includes
data for all InfluxDB Queriers in your cluster.
The data comes from the catalog, and because all the queriers share one catalog,
the results from these three tables derive from the same source data,
regardless of which querier you connect to.
However, the system.queries table is different--data is local to each Querier.
system.queries contains a non-persisted log of queries run against the current
querier to which your query is routed.
The query log is specific to the current Querier and isn't shared across
queriers in your cluster.
Logs are scoped to the specified database.
The system.queries table stores log entries for queries executed for the provided namespace (database) on the node that is currently handling queries.
system.queries reflects a process-local, in-memory, namespace-scoped query log.
While this table may be useful for debugging and monitoring queries, keep the following in mind:
system.queries are transient and volatile
system.queries records during pod restarts.system.queries can return different results
depending on the pod the request was routed to.{{< expand-wrapper >}}
{{% expand "View system.queries schema" %}}
The system.queries table contains the following columns:
sql, flightsql, or influxql) of the query{{% /expand %}} {{< /expand-wrapper >}}
[!Note] When listing measurements (tables) available within a namespace, some clients and query tools may include the
queriestable in the list of namespace tables.
The system.tables table contains information about tables in the specified database.
{{< expand-wrapper >}}
{{% expand "View system.tables schema" %}}
The system.tables table contains the following columns:
{{% /expand %}} {{< /expand-wrapper >}}
The system.partitions table contains information about partitions associated
with the specified database.
{{< expand-wrapper >}}
{{% expand "View system.partitions schema" %}}
The system.partitions table contains the following columns:
{{% /expand %}} {{< /expand-wrapper >}}
The system.compactor table contains information about compacted partition Parquet
files associated with the specified database.
{{< expand-wrapper >}}
{{% expand "View system.compactor schema" %}}
The system.compactor table contains the following columns:
{{% /expand %}} {{< /expand-wrapper >}}
[!Warning]
May impact cluster performance
Querying InfluxDB 3 system tables may impact write and query performance of your {{< product-name omit=" Clustered" >}} cluster.
The examples in this section include
WHEREfilters to optimize queries and reduce impact to your cluster.
In the examples below, replace {{% code-placeholder-key %}}TABLE_NAME{{% /code-placeholder-key %}}
with the name of the table you want to query information about.
{{% code-placeholders "TABLE_NAME" %}}
SELECT * FROM system.queries
The following returns query logs for queries with an end-to-end duration greater than 50 milliseconds.
SELECT *
FROM
system.queries
WHERE
end2end_duration::BIGINT > (50 * 1000000)
{{< code-tabs >}} {{% tabs %}} SQL Python {{% /tabs %}} {{% code-tab-content %}}
<!-----------------------------------BEGIN SQL------------------------------>SELECT *
FROM system.queries
WHERE issue_time >= now() - INTERVAL '1 day'
AND query_text LIKE '%select * from home%'
{{% /code-tab-content %}} {{% code-tab-content %}}
<!-----------------------------------BEGIN PYTHON------------------------------>from influxdb_client_3 import InfluxDBClient3
client = InfluxDBClient3(token = DATABASE_TOKEN,
host = HOSTNAME,
org = '',
database=DATABASE_NAME)
client.query('select * from home')
reader = client.query('''
SELECT *
FROM system.queries
WHERE issue_time >= now() - INTERVAL '1 day'
AND query_text LIKE '%select * from home%'
''',
language='sql',
headers=[(b"iox-debug", b"true")],
mode="reader")
{{% /code-tab-content %}} {{< /code-tabs >}}
SELECT *
FROM
system.tables
WHERE
table_name = 'TABLE_NAME'
SELECT *
FROM
system.partitions
WHERE
table_name = 'TABLE_NAME'
SELECT
table_name,
COUNT(*) AS partition_count
FROM
system.partitions
WHERE
table_name IN ('foo', 'bar', 'baz')
GROUP BY
table_name
SELECT
COUNT(*) AS partition_count
FROM
system.partitions
WHERE
table_name = 'TABLE_NAME'
SELECT
SUM(total_size_mb) AS total_size_mb
FROM
system.partitions
WHERE
table_name = 'TABLE_NAME'
SELECT
table_name,
SUM(total_size_mb) AS total_size_mb
FROM
system.partitions
WHERE
table_name IN ('foo', 'bar', 'baz')
GROUP BY
table_name
SELECT
table_name,
SUM(total_l0_bytes) + SUM(total_l1_bytes) + SUM(total_l2_bytes) AS total_bytes
FROM
system.compactor
WHERE
table_name IN ('foo', 'bar', 'baz')
GROUP BY
table_name
SELECT
SUM(total_l0_bytes) + SUM(total_l1_bytes) + SUM(total_l2_bytes) AS total_bytes
FROM
system.compactor
WHERE
table_name = 'TABLE_NAME'
SELECT
table_name,
SUM(total_l0_files) AS total_l0_files,
SUM(total_l1_files) AS total_l1_files,
SUM(total_l2_files) AS total_l2_files,
SUM(total_l0_bytes) AS total_l0_bytes,
SUM(total_l1_bytes) AS total_l1_bytes,
SUM(total_l2_bytes) AS total_l2_bytes
FROM
system.compactor
WHERE
table_name IN ('foo', 'bar', 'baz')
GROUP BY
table_name
SELECT
SUM(total_l0_files) AS total_l0_files,
SUM(total_l1_files) AS total_l1_files,
SUM(total_l2_files) AS total_l2_files,
SUM(total_l0_bytes) AS total_l0_bytes,
SUM(total_l1_bytes) AS total_l1_bytes,
SUM(total_l2_bytes) AS total_l2_bytes
FROM
system.compactor
WHERE
table_name = 'TABLE_NAME'
{{% /code-placeholders %}}