system.stack_trace

Contains stack traces of all server threads. Allows developers to introspect the server state.

To analyze stack frames, use the addressToLine, addressToSymbol and demangle introspection functions.

Columns:

  • thread_name (String) — Thread name.
  • thread_id (UInt64) — Thread identifier.
  • query_id (String) — Query identifier that can be used to get details about a query that was running from the query_log system table.
  • trace (Array(UInt64)) — A stack trace which represents a list of physical addresses where the called methods are stored.

Example

Enabling introspection functions:

  1. SET allow_introspection_functions = 1;

Getting symbols from ClickHouse object files:

  1. 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;
  1. Row 1:
  2. ──────
  3. thread_name: clickhouse-serv
  4. thread_id: 686
  5. query_id: 1a11f70b-626d-47c1-b948-f9c7b206395d
  6. res: sigqueue
  7. 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
  8. 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)
  9. 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&)
  10. DB::InterpreterSelectQuery::executeImpl(DB::QueryPipeline&, std::__1::shared_ptr<DB::IBlockInputStream> const&, std::__1::optional<DB::Pipe>)
  11. DB::InterpreterSelectQuery::execute()
  12. DB::InterpreterSelectWithUnionQuery::execute()
  13. DB::executeQueryImpl(char const*, char const*, DB::Context&, bool, DB::QueryProcessingStage::Enum, bool, DB::ReadBuffer*)
  14. DB::executeQuery(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, DB::Context&, bool, DB::QueryProcessingStage::Enum, bool)
  15. DB::TCPHandler::runImpl()
  16. DB::TCPHandler::run()
  17. Poco::Net::TCPServerConnection::start()
  18. Poco::Net::TCPServerDispatcher::run()
  19. Poco::PooledThread::run()
  20. Poco::ThreadImpl::runnableEntry(void*)
  21. start_thread
  22. __clone

Getting filenames and line numbers in ClickHouse source code:

  1. 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;
  1. Row 1:
  2. ──────
  3. thread_name: clickhouse-serv
  4. thread_id: 686
  5. query_id: cad353e7-1c29-4b2e-949f-93e597ab7a54
  6. res: /lib/x86_64-linux-gnu/libc-2.27.so
  7. /build/obj-x86_64-linux-gnu/../src/Storages/System/StorageSystemStackTrace.cpp:182
  8. /build/obj-x86_64-linux-gnu/../contrib/libcxx/include/vector:656
  9. /build/obj-x86_64-linux-gnu/../src/Interpreters/InterpreterSelectQuery.cpp:1338
  10. /build/obj-x86_64-linux-gnu/../src/Interpreters/InterpreterSelectQuery.cpp:751
  11. /build/obj-x86_64-linux-gnu/../contrib/libcxx/include/optional:224
  12. /build/obj-x86_64-linux-gnu/../src/Interpreters/InterpreterSelectWithUnionQuery.cpp:192
  13. /build/obj-x86_64-linux-gnu/../src/Interpreters/executeQuery.cpp:384
  14. /build/obj-x86_64-linux-gnu/../src/Interpreters/executeQuery.cpp:643
  15. /build/obj-x86_64-linux-gnu/../src/Server/TCPHandler.cpp:251
  16. /build/obj-x86_64-linux-gnu/../src/Server/TCPHandler.cpp:1197
  17. /build/obj-x86_64-linux-gnu/../contrib/poco/Net/src/TCPServerConnection.cpp:57
  18. /build/obj-x86_64-linux-gnu/../contrib/libcxx/include/atomic:856
  19. /build/obj-x86_64-linux-gnu/../contrib/poco/Foundation/include/Poco/Mutex_POSIX.h:59
  20. /build/obj-x86_64-linux-gnu/../contrib/poco/Foundation/include/Poco/AutoPtr.h:223
  21. /lib/x86_64-linux-gnu/libpthread-2.27.so
  22. /lib/x86_64-linux-gnu/libc-2.27.so

See Also

  • Introspection Functions — Which introspection functions are available and how to use them.
  • system.trace_log — Contains stack traces collected by the sampling query profiler.
  • arrayMap — Description and usage example of the arrayMap function.
  • arrayFilter — Description and usage example of the arrayFilter function.