system.stack_trace 시스템 테이블

system.stack_trace 시스템 테이블

system.stack_trace 는 모든 서버 스레드의 스택 트레이스를 담고 있어요. 개발자가 서버 상태를 내부 조사(introspection)할 수 있게 해줘요.

출처: 문서

본문

ClickHouse Cloud에서의 조회 — 이 시스템 테이블의 데이터는 ClickHouse Cloud에서 각 노드에 로컬로 저장돼요. 따라서 모든 데이터의 완전한 뷰를 얻으려면 clusterAllReplicas 함수가 필요해요. 자세한 내용은 여기 를 참고하세요.

Description

모든 서버 스레드의 스택 트레이스를 포함해요. 개발자가 서버 상태를 내부 조사할 수 있게 해줘요. 스택 프레임을 분석하려면 addressToLine, addressToLineWithInlines, addressToSymbol 및 demangle introspection 함수 를 사용해요.

Columns

  • thread_name (String) — 스레드의 이름이에요.

  • thread_id (UInt64) — 스레드 식별자예요.

  • query_id (String) — 이 스레드가 속한 쿼리의 ID예요.

  • trace (Array(UInt64)) — 이 스레드의 스택트레이스예요. FreeBSD를 제외한 ELF 플랫폼에서, 메인 ClickHouse 바이너리 내부의 주소는 물리적 파일 오프셋으로 저장되고, 다른 주소는 ClickHouse 서버 프로세스 내부의 가상 메모리 주소로 저장돼요.

  • untracked_memory (Int64) — 아직 상위 MemoryTracker 로 전파되지 않은 메모리 할당의 스레드별 카운터예요. 마지막 flush 이후 해제된 것보다 더 많이 해제된 경우 음수일 수 있어요.

Example

Introspection 함수 활성화:

SET allow_introspection_functions = 1;

ClickHouse 오브젝트 파일에서 심볼 얻기:

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;
Row 1:
──────
thread_name: QueryPipelineEx
thread_id:   743490
query_id:    dc55a564-febb-4e37-95bb-090ef182c6f1
res:         memcpy
large_ralloc
arena_ralloc
do_rallocx
Allocator::realloc(void*, unsigned long, unsigned long, unsigned long)
HashTable, HashTableNoState, PairNoInit>, HashCRC32, HashTableGrowerWithPrecalculation, Allocator>::resize(unsigned long, unsigned long)
void DB::Aggregator::executeImplBatch, HashTableNoState, PairNoInit>, HashCRC32, HashTableGrowerWithPrecalculation, Allocator>, true, false>>(DB::AggregationMethodOneNumber, HashTableNoState, PairNoInit>, HashCRC32, HashTableGrowerWithPrecalculation, Allocator>, true, false>&, DB::AggregationMethodOneNumber, HashTableNoState, PairNoInit>, HashCRC32, HashTableGrowerWithPrecalculation, Allocator>, true, false>::State&, DB::Arena*, unsigned long, unsigned long, DB::Aggregator::AggregateFunctionInstruction*, bool, char*) const
DB::Aggregator::executeImpl(DB::AggregatedDataVariants&, unsigned long, unsigned long, std::__1::vector>&, DB::Aggregator::AggregateFunctionInstruction*, bool, bool, char*) const
DB::Aggregator::executeOnBlock(std::__1::vector::immutable_ptr, std::__1::allocator::immutable_ptr>>, unsigned long, unsigned long, DB::AggregatedDataVariants&, std::__1::vector>&, std::__1::vector>, std::__1::allocator>>>&, bool&) const
DB::AggregatingTransform::work()
DB::ExecutionThreadContext::executeTask()
DB::PipelineExecutor::executeStepImpl(unsigned long, std::__1::atomic*)
void std::__1::__function::__policy_invoker::__call_impl>(std::__1::__function::__policy_storage const*)
ThreadPoolImpl>::worker(std::__1::__list_iterator, void*>)
void std::__1::__function::__policy_invoker::__call_impl::ThreadFromGlobalPoolImpl>::scheduleImpl(std::__1::function, Priority, std::__1::optional, bool)::'lambda0'()>(void&&)::'lambda'(), void ()>>(std::__1::__function::__policy_storage const*)
void* std::__1::__thread_proxy[abi:v15000]>, void ThreadPoolImpl::scheduleImpl(std::__1::function, Priority, std::__1::optional, bool)::'lambda0'()>>(void*)

ClickHouse 소스 코드에서 파일명과 줄 번호 얻기:

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;
Row 1:
──────
thread_name: clickhouse-serv

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
/lib/x86_64-linux-gnu/libc-2.27.so

See Also

  • Introspection Functions — 어떤 introspection 함수를 사용할 수 있고 어떻게 사용하는지.

  • system.trace_log — 샘플링 쿼리 프로파일러와 trace_type 열에 이름이 있는 다른 소스에 의해 수집된 스택 트레이스를 포함해요.

  • arrayMap — arrayMap 함수의 설명과 사용 예시.

  • arrayFilter — arrayFilter 함수의 설명과 사용 예시.