Documentation

Retrieve system information for a query

Learn how to retrieve system information for a query in InfluxDB Cloud Dedicated.

In addition to the SQL standard information_schema, InfluxDB Cloud Dedicated contains system tables that provide access to InfluxDB-specific information. The information in each system table is scoped to the namespace you’re querying; you can only retrieve system information for that particular instance.

To get information about queries you’ve run on the current instance, use SQL to query the system.queries table, which contains information from the Querier instance currently handling queries. If you enabled trace logging for the query, the trace-id appears in the system.queries.trace_id column for the query.

The system.queries table is an InfluxDB v3 debug feature. To enable the feature and query system.queries, include an "iox-debug" header set to "true" and use SQL to query the table.

The following sample code shows how to use the Python client library to do the following:

  1. Enable tracing for a query.
  2. Retrieve the trace ID record from system.queries.
from influxdb_client_3 import InfluxDBClient3
import secrets
import pandas

def get_query_information():
  print('# Get query information')

  client = InfluxDBClient3(token = f"
DATABASE_TOKEN
"
,
host = f"cluster-id.influxdb.io", database = f"
DATABASE_NAME
"
)
random_bytes = secrets.token_bytes(16) trace_id = random_bytes.hex() trace_value = (f"{trace_id}:1112223334445:0:1").encode('utf-8') sql = "SELECT * FROM home WHERE time >= now() - INTERVAL '30 days'" try: client.query(sql, headers=[(b'influx-trace-id', trace_value)]) client.close() except Exception as e: print("Query error: ", e) client = InfluxDBClient3(token = f"
DATABASE_TOKEN
"
,
host = f"cluster-id.influxdb.io", database = f"
DATABASE_NAME
"
)
import time df = pandas.DataFrame() for i in range(0, 5): time.sleep(1) # Use SQL # To query the system.queries table for your trace ID, pass the following: # - the iox-debug: true request header # - an SQL query for the trace_id column reader = client.query(f'''SELECT compute_duration, query_type, query_text, success, trace_id FROM system.queries WHERE issue_time >= now() - INTERVAL '1 day' AND trace_id = '{trace_id}' ORDER BY issue_time DESC ''', headers=[(b"iox-debug", b"true")], mode="reader") df = reader.read_all().to_pandas() if df.shape[0]: break assert df.shape == (1, 5), f"Expect a row for the query trace ID." print(df) get_query_information()

The output is similar to the following:

compute_duration query_type                        query_text  success  trace_id
          0 days        sql  SELECT compute_duration, quer...     True  67338...

Was this page helpful?

Thank you for your feedback!


Introducing InfluxDB Clustered

A highly available InfluxDB 3.0 cluster on your own infrastructure.

InfluxDB Clustered is a highly available InfluxDB 3.0 cluster built for high write and query workloads on your own infrastructure.

InfluxDB Clustered is currently in limited availability and is only available to a limited group of InfluxData customers. If interested in being part of the limited access group, please contact the InfluxData Sales team.

Learn more
Contact InfluxData Sales

The future of Flux

Flux is going into maintenance mode. You can continue using it as you currently are without any changes to your code.

Flux is going into maintenance mode and will not be supported in InfluxDB 3.0. This was a decision based on the broad demand for SQL and the continued growth and adoption of InfluxQL. We are continuing to support Flux for users in 1.x and 2.x so you can continue using it with no changes to your code. If you are interested in transitioning to InfluxDB 3.0 and want to future-proof your code, we suggest using InfluxQL.

For information about the future of Flux, see the following: