Skip to content

Commit 87c00b5

Browse files
authored
Update troubleshooting.md
fixed description
1 parent 93334bb commit 87c00b5

File tree

1 file changed

+27
-9
lines changed

1 file changed

+27
-9
lines changed

content/en/altinity-kb-queries-and-syntax/troubleshooting.md

Lines changed: 27 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,19 @@ description: >
77

88
Tips for ClickHouse® troubleshooting
99

10-
## Log of query execution
10+
### Query Execution Logging
1111

12-
Controlled by session level setting `send_logs_level`
12+
When troubleshooting query execution in ClickHouse, one of the most useful tools is logging the query execution details. This can be controlled using the session-level setting `send_logs_level`. Here are the different log levels you can use:
1313
Possible values: `'trace', 'debug', 'information', 'warning', 'error', 'fatal', 'none'`
14-
Can be used with [clickhouse-client](https://docs.altinity.com/altinitycloud/altinity-cloud-connections/clickhouseclient/) in both interactive and non-interactive mode.
14+
15+
This can be used with [clickhouse-client](https://docs.altinity.com/altinitycloud/altinity-cloud-connections/clickhouseclient/) in both interactive and non-interactive mode.
16+
17+
The logs provide detailed information about query execution, making it easier to identify issues or bottlenecks. You can use the following command to run a query with logging enabled:
1518

1619
```bash
1720
$ clickhouse-client -mn --send_logs_level='trace' --query "SELECT sum(number) FROM numbers(1000)"
21+
22+
-- output --
1823
[LAPTOP] 2021.04.29 00:05:31.425842 [ 25316 ] {14b0646d-8a6e-4b2f-9b13-52a218cf43ba} <Debug> executeQuery: (from 127.0.0.1:42590, using production parser) SELECT sum(number) FROM numbers(1000)
1924
[LAPTOP] 2021.04.29 00:05:31.426281 [ 25316 ] {14b0646d-8a6e-4b2f-9b13-52a218cf43ba} <Trace> ContextAccess (default): Access granted: CREATE TEMPORARY TABLE ON *.*
2025
[LAPTOP] 2021.04.29 00:05:31.426648 [ 25316 ] {14b0646d-8a6e-4b2f-9b13-52a218cf43ba} <Trace> InterpreterSelectQuery: FetchColumns -> Complete
@@ -25,10 +30,18 @@ $ clickhouse-client -mn --send_logs_level='trace' --query "SELECT sum(number) FR
2530
[LAPTOP] 2021.04.29 00:05:31.427875 [ 25316 ] {14b0646d-8a6e-4b2f-9b13-52a218cf43ba} <Information> executeQuery: Read 1000 rows, 7.81 KiB in 0.0019463 sec., 513795 rows/sec., 3.92 MiB/sec.
2631
[LAPTOP] 2021.04.29 00:05:31.427898 [ 25316 ] {14b0646d-8a6e-4b2f-9b13-52a218cf43ba} <Debug> MemoryTracker: Peak memory usage (for query): 0.00 B.
2732
499500
33+
```
2834

35+
You can also redirect the logs to a file for further analysis:
36+
```bash
2937
$ clickhouse-client -mn --send_logs_level='trace' --query "SELECT sum(number) FROM numbers(1000)" 2> ./query.log
3038
```
3139

40+
### Analyzing Logs in System Tables
41+
If you need to analyze the logs after executing a query, you can query the system tables to retrieve the execution details.
42+
43+
Query Log: You can fetch query logs from the `system.query_log` table:
44+
3245
```sql
3346
LAPTOP.localdomain :) SET send_logs_level='trace';
3447

@@ -63,9 +76,12 @@ Query id: d3db767b-34e9-4252-9f90-348cf958f822
6376
1 rows in set. Elapsed: 0.007 sec. Processed 1.00 thousand rows, 8.00 KB (136.43 thousand rows/s., 1.09 MB/s.)
6477
```
6578

66-
## system tables
79+
## Analyzing Logs in System Tables
80+
6781

6882
```sql
83+
# Query Log: You can fetch query logs from the system.query_log table:
84+
6985
SELECT sum(number)
7086
FROM numbers(1000);
7187

@@ -81,13 +97,15 @@ SELECT *
8197
FROM system.query_log
8298
WHERE (event_date = today()) AND (query_id = '34c61093-3303-47d0-860b-0d644fa7264b');
8399

84-
If query_thread_log enabled (SET log_query_threads = 1)
100+
# Query Thread Log: If thread-level logging is enabled (log_query_threads = 1), retrieve logs using:
101+
# To capture detailed thread-level logs, enable log_query_threads: (SET log_query_threads = 1;)
85102

86103
SELECT *
87104
FROM system.query_thread_log
88105
WHERE (event_date = today()) AND (query_id = '34c61093-3303-47d0-860b-0d644fa7264b');
89106

90-
If opentelemetry_span_log enabled (SET opentelemetry_start_trace_probability = 1, opentelemetry_trace_processors = 1)
107+
# OpenTelemetry Span Log: For detailed tracing with OpenTelemetry, if enabled (opentelemetry_start_trace_probability = 1), use:
108+
# To enable OpenTelemetry tracing for queries, set: (SET opentelemetry_start_trace_probability = 1, opentelemetry_trace_processors = 1)
91109

92110
SELECT *
93111
FROM system.opentelemetry_span_log
@@ -100,10 +118,9 @@ WHERE (trace_id, finish_date) IN (
100118
);
101119
```
102120

121+
### Visualizing Query Performance with Flamegraphs
103122

104-
105-
## Flamegraph
106-
123+
ClickHouse supports exporting query performance data in a format compatible with speedscope.app. This can help you visualize performance bottlenecks within queries. Example query to generate a flamegraph:
107124
[https://www.speedscope.app/](https://www.speedscope.app/)
108125

109126
```sql
@@ -147,3 +164,4 @@ SETTINGS allow_introspection_functions = 1, output_format_json_named_tuples_as_o
147164
FORMAT JSONEachRow
148165
SETTINGS output_format_json_named_tuples_as_objects = 1
149166
```
167+
By enabling detailed logging and tracing, you can effectively diagnose issues and optimize query performance in ClickHouse.

0 commit comments

Comments
 (0)