세션 / 쿼리 추적(trace / profiling 활성화)
Oracle
-- For a specific session (10046 event tracing):
BEGIN
DBMS_MONITOR.SESSION_TRACE_ENABLE(session_id => 123, serial_num => 4567, waits => TRUE, binds => TRUE);
END;
/
-- To disable: DBMS_MONITOR.SESSION_TRACE_DISABLE(123, 4567);DBMS_MONITOR.SESSION_TRACE_ENABLE은 세션에 대한 10046 trace 파일을 생성한다. 작업이 끝나면 반드시 비활성화한다(trace는 오버헤드와 디스크 사용을 늘린다).
PostgreSQL
LOAD 'auto_explain';
SET auto_explain.log_min_duration = 0;
SET auto_explain.log_analyze = true;
-- Simple alternative: SET log_min_duration_statement = 0;auto_explain은 쿼리 실행 계획을, log_min_duration_statement는 느린/전체 쿼리를 로그 파일에 기록한다. 값이 0이면 모든 쿼리를 기록하므로 로그 양에 주의한다.
MySQL
-- performance_schema approach (recommended):
UPDATE performance_schema.setup_consumers SET ENABLED='YES' WHERE NAME LIKE 'events_statements%';
-- Legacy/simple method (being deprecated):
SET profiling = 1;
-- run the query, then:
SHOW PROFILES;쿼리 추적은 performance_schema events_statements로 수행한다. SET profiling 방식은 오래되었지만(deprecated) 세션 단위로 빠르게 측정할 수 있다.
SQL Server
CREATE EVENT SESSION [trace_slow] ON SERVER
ADD EVENT sqlserver.sql_statement_completed(
WHERE duration > 1000000)
ADD TARGET package0.event_file(SET filename=N'trace_slow.xel');
GO
ALTER EVENT SESSION [trace_slow] ON SERVER STATE = START;Extended Events(XEvents)는 최신 추적 방식이다. 세션을 생성해 START로 시작하고, 작업이 끝나면 STOP/DROP으로 중지한다.
MongoDB
db.setProfilingLevel(2)
// 1 = slow operations only (slowms threshold), 0 = off
// Results: db.system.profile.find().sort({ ts: -1 }).limit(10)setProfilingLevel(2)는 모든 작업을 system.profile 컬렉션에 기록한다. 레벨 2는 오버헤드가 있으므로 운영 환경에서는 1(느린 작업만)이 권장된다.
Redis
MONITOR
# Streams all commands arriving at the server in real time. Exit: Ctrl-CMONITOR는 모든 명령을 실시간으로 보여 주지만 성능이 크게 떨어진다. 운영 환경에서는 짧게, 신중하게 사용한다. 대안: SLOWLOG GET.
Elasticsearch
GET my-index/_search
{
"profile": true,
"query": { "match": { "title": "elastic" } }
}
// Persistent slow query tracing: the index.search.slowlog.threshold.query.warn setting"profile": true는 단일 검색의 query/aggregation 소요 시간 분석을 보여 준다. 지속적인 모니터링에는 slowlog 임계값을 설정한다.