2022-04-03 23:05:35 +00:00
# system.stack_trace {#system-tables_stack_trace}
2020-07-31 11:46:58 +00:00
Contains stack traces of all server threads. Allows developers to introspect the server state.
2022-01-08 12:21:39 +00:00
To analyze stack frames, use the `addressToLine` , `addressToLineWithInlines` , `addressToSymbol` and `demangle` [introspection functions ](../../sql-reference/functions/introspection.md ).
2020-07-31 11:46:58 +00:00
Columns:
2021-05-25 21:39:34 +00:00
- `thread_name` ([String](../../sql-reference/data-types/string.md)) — Thread name.
2020-07-31 11:46:58 +00:00
- `thread_id` ([UInt64](../../sql-reference/data-types/int-uint.md)) — Thread identifier.
- `query_id` ([String](../../sql-reference/data-types/string.md)) — Query identifier that can be used to get details about a query that was running from the [query_log ](../system-tables/query_log.md ) system table.
- `trace` ([Array(UInt64)](../../sql-reference/data-types/array.md)) — A [stack trace ](https://en.wikipedia.org/wiki/Stack_trace ) which represents a list of physical addresses where the called methods are stored.
**Example**
Enabling introspection functions:
``` sql
SET allow_introspection_functions = 1;
```
Getting symbols from ClickHouse object files:
``` sql
2021-05-25 21:39:34 +00:00
WITH arrayMap(x -> demangle(addressToSymbol(x)), trace) AS all SELECT thread_name, thread_id, query_id, arrayStringConcat(all, '\n') AS res FROM system.stack_trace LIMIT 1 \G;
2020-07-31 11:46:58 +00:00
```
``` text
Row 1:
──────
2021-05-25 21:39:34 +00:00
thread_name: clickhouse-serv
2021-05-27 17:01:56 +00:00
thread_id: 686
query_id: 1a11f70b-626d-47c1-b948-f9c7b206395d
res: sigqueue
DB::StorageSystemStackTrace::fillData(std::__1::vector< COW < DB::IColumn > ::mutable_ptr< DB::IColumn > , std::__1::allocator< COW < DB::IColumn > ::mutable_ptr< DB::IColumn > > >& , DB::Context const& , DB::SelectQueryInfo const& ) const
DB::IStorageSystemOneBlock< DB::StorageSystemStackTrace > ::read(std::__1::vector< std::__1::basic_string < char , std::__1::char_traits < char > , std::__1::allocator< char > >, std::__1::allocator< std::__1::basic_string < char , std::__1::char_traits < char > , std::__1::allocator< char > > > > const& , DB::SelectQueryInfo const& , DB::Context const& , DB::QueryProcessingStage::Enum, unsigned long, unsigned int)
DB::InterpreterSelectQuery::executeFetchColumns(DB::QueryProcessingStage::Enum, DB::QueryPipeline& , std::__1::shared_ptr< DB::PrewhereInfo > const& , std::__1::vector< std::__1::basic_string < char , std::__1::char_traits < char > , std::__1::allocator< char > >, std::__1::allocator< std::__1::basic_string < char , std::__1::char_traits < char > , std::__1::allocator< char > > > > const& )
DB::InterpreterSelectQuery::executeImpl(DB::QueryPipeline& , std::__1::shared_ptr< DB::IBlockInputStream > const& , std::__1::optional< DB::Pipe > )
DB::InterpreterSelectQuery::execute()
DB::InterpreterSelectWithUnionQuery::execute()
DB::executeQueryImpl(char const*, char const*, DB::Context& , bool, DB::QueryProcessingStage::Enum, bool, DB::ReadBuffer*)
DB::executeQuery(std::__1::basic_string< char , std::__1::char_traits < char > , std::__1::allocator< char > > const& , DB::Context& , bool, DB::QueryProcessingStage::Enum, bool)
DB::TCPHandler::runImpl()
DB::TCPHandler::run()
Poco::Net::TCPServerConnection::start()
Poco::Net::TCPServerDispatcher::run()
Poco::PooledThread::run()
Poco::ThreadImpl::runnableEntry(void*)
start_thread
__clone
2020-07-31 11:46:58 +00:00
```
Getting filenames and line numbers in ClickHouse source code:
``` sql
2021-05-25 21:39:34 +00:00
WITH arrayMap(x -> addressToLine(x), trace) AS all, arrayFilter(x -> x LIKE '%/dbms/%', all) AS dbms SELECT thread_name, thread_id, query_id, arrayStringConcat(notEmpty(dbms) ? dbms : all, '\n') AS res FROM system.stack_trace LIMIT 1 \G;
2020-07-31 11:46:58 +00:00
```
``` text
Row 1:
──────
2021-05-25 21:39:34 +00:00
thread_name: clickhouse-serv
2021-05-27 17:01:56 +00:00
thread_id: 686
query_id: cad353e7-1c29-4b2e-949f-93e597ab7a54
res: /lib/x86_64-linux-gnu/libc-2.27.so
/build/obj-x86_64-linux-gnu/../src/Storages/System/StorageSystemStackTrace.cpp:182
/build/obj-x86_64-linux-gnu/../contrib/libcxx/include/vector:656
/build/obj-x86_64-linux-gnu/../src/Interpreters/InterpreterSelectQuery.cpp:1338
/build/obj-x86_64-linux-gnu/../src/Interpreters/InterpreterSelectQuery.cpp:751
/build/obj-x86_64-linux-gnu/../contrib/libcxx/include/optional:224
/build/obj-x86_64-linux-gnu/../src/Interpreters/InterpreterSelectWithUnionQuery.cpp:192
/build/obj-x86_64-linux-gnu/../src/Interpreters/executeQuery.cpp:384
/build/obj-x86_64-linux-gnu/../src/Interpreters/executeQuery.cpp:643
/build/obj-x86_64-linux-gnu/../src/Server/TCPHandler.cpp:251
/build/obj-x86_64-linux-gnu/../src/Server/TCPHandler.cpp:1197
/build/obj-x86_64-linux-gnu/../contrib/poco/Net/src/TCPServerConnection.cpp:57
/build/obj-x86_64-linux-gnu/../contrib/libcxx/include/atomic:856
/build/obj-x86_64-linux-gnu/../contrib/poco/Foundation/include/Poco/Mutex_POSIX.h:59
/build/obj-x86_64-linux-gnu/../contrib/poco/Foundation/include/Poco/AutoPtr.h:223
/lib/x86_64-linux-gnu/libpthread-2.27.so
2020-07-31 11:46:58 +00:00
/lib/x86_64-linux-gnu/libc-2.27.so
```
**See Also**
- [Introspection Functions ](../../sql-reference/functions/introspection.md ) — Which introspection functions are available and how to use them.
- [system.trace_log ](../system-tables/trace_log.md ) — Contains stack traces collected by the sampling query profiler.
2020-09-08 15:55:00 +00:00
- [arrayMap ](../../sql-reference/functions/array-functions.md#array-map ) — Description and usage example of the `arrayMap` function.
- [arrayFilter ](../../sql-reference/functions/array-functions.md#array-filter ) — Description and usage example of the `arrayFilter` function.