5.6 KiB
title, source_type, url, archive_url, status, confidence, tags, related_branches, related_projects, created, last_reviewed
| title | source_type | url | archive_url | status | confidence | tags | related_branches | related_projects | created | last_reviewed | |||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| official-doc / Hibernate Slow Query Log — LOG_QUERIES_SLOWER_THAN_MS (Hibernate ORM 5.4.5+) | official-doc | https://vladmihalcea.com/hibernate-slow-query-log/ | raw | high |
|
|
2026-06-09 | 2026-06-09 |
Hibernate Slow Query Log — LOG_QUERIES_SLOWER_THAN_MS
Layer:
raw/— 외부 자료(공식 문서)의 원문 발췌·출처 기록.
Parent / 활용 branch
| Branch | 이 자료가 정당화하는 결정 |
|---|---|
| raw/branch-notes/feature-database-connection-pool-contract | Hibernate 슬로우 쿼리 로그 방식의 파라미터 노출 위험 및 임계값 설정 메커니즘 근거 |
출처 / Source
- 원본 URL: https://vladmihalcea.com/hibernate-slow-query-log/
- 보조 URL: https://thorben-janssen.com/hibernate-slow-query-log/
- 저자 / 조직: Vlad Mihalcea (Hibernate 공식 커미터), Thorben Janssen (JPA expert)
- 마지막 확인일: 2026-06-09
왜 저장했는지 / Why archived
feature-database-connection-pool-contract 브랜치에서 슬로우 쿼리 탐지 방식을 결정할 때, Hibernate 내장 슬로우 쿼리 로그의 파라미터 노출 여부와 설정 메커니즘을 검토하기 위해 보관. 프로젝트 하드 룰("SQL/파라미터 로그 금지")과의 충돌 여부 판단에 사용.
핵심 인용 / Key quotes (verbatim)
"After you define the threshold for slow queries, Hibernate will write a log message for each query that takes longer than the specified threshold at the INFO level to the category org.hibernate.SQL_SLOW."
"SlowQuery: 32 milliseconds. SQL: 'PgPreparedStatement [ select p.id as id1_0_, p.created_by as created_2_0_, p.created_on as created_3_0_, p.title as title4_0_ from post p where lower(p.title) like '%java%book%review%' order by p.created_on desc limit 100 offset 1000 ]'"
"Hibernate applies the slow query threshold to the pure execution time of the query. This doesn't include any of Hibernate's preparation or result processing steps and is lower than the time reported in Hibernate's statistics."
"spring.jpa.properties.hibernate.session.events.log.LOG_QUERIES_SLOWER_THAN_MS=20"
Claims Extracted / 추출된 주장
| Claim ID | Claim (이 자료가 직접 말하는 것) | Evidence quote | Strength | Applies to | Does not prove |
|---|---|---|---|---|---|
| C1 | Hibernate 슬로우 쿼리 로그는 기본적으로 실제 파라미터 값이 치환된 SQL(materialized SQL)을 출력한다 | "like '%java%book%review%'" — 바인드 변수가 실제 값으로 치환된 SQL이 출력된 로그 예시 | official-vendor-doc |
Hibernate 5.4.5+ / Spring Boot 2.2+ | 플레이스홀더(?)만 출력한다는 주장을 반증; JDBC 드라이버 구현에 따라 다를 수 있음 |
| C2 | 측정 대상은 순수 JDBC 실행 시간만이며 ResultSet 처리·Hibernate 전후처리 시간은 제외된다 | "This doesn't include any of Hibernate's preparation or result processing steps" | official-vendor-doc |
Hibernate 5.4.5+ | 커넥션 풀 획득 지연이나 네트워크 RTT 가 포함된다는 주장을 반증함 |
| C3 | Spring Boot에서 설정 프로퍼티는 spring.jpa.properties.hibernate.session.events.log.LOG_QUERIES_SLOWER_THAN_MS 이다 |
"spring.jpa.properties.hibernate.session.events.log.LOG_QUERIES_SLOWER_THAN_MS=20" | official-vendor-doc |
Spring Boot + Spring Data JPA 환경 | HikariCP 단독으로 슬로우 쿼리를 탐지할 수 있다는 주장 반증 |
| C4 | 로그 카테고리는 org.hibernate.SQL_SLOW이고 INFO 레벨 이상으로 설정해야 출력된다 |
"Hibernate will write a log message ... at the INFO level to the category org.hibernate.SQL_SLOW" | official-vendor-doc |
Hibernate 5.4.5+ | 별도 로그 카테고리 설정 없이 자동 출력된다는 주장 반증 |
| C5 | 로그 출력은 per-statement 단위이며, 임계값을 초과한 각 쿼리마다 별도 로그 라인이 생성된다 | "Hibernate will write a log message for each query that takes longer than the specified threshold" | official-vendor-doc |
Hibernate 5.4.5+ | — |
Usage Boundaries / 적용 경계
- 이 자료가 직접 증명하는 것:
C1: Hibernate 슬로우 쿼리 로그가 PgPreparedStatement 예시에서 실제 값을 출력함C2,C3,C4,C5: 설정 방법, 측정 범위, 로그 레벨
- 이 자료가 증명하지 않는 것:
- 모든 JDBC 드라이버 구현에서 동일하게 materialized SQL이 출력된다는 보장 (PostgreSQL JDBC 드라이버 예시이므로 MySQL 등에서 다를 수 있음)
- 파라미터 값이 반드시 노출된다는 절대적 주장 (Hibernate 내부 동작 변경 가능)
- 프로덕션 환경에서의 성능 오버헤드 수치
- 내 프로젝트에 적용하려면 추가 확인이 필요한 것:
- ca-tmpl 실제 MySQL JDBC 드라이버 환경에서도 동일하게 파라미터 값이 출력되는지 로컬 테스트 필요
- Hibernate 6.x (Spring Boot 3.x) 에서 동일 동작 여부 확인
메모 / Notes
- C1 의 파라미터 노출은 프로젝트의 "SQL/파라미터 로그 금지" 하드 룰과 직접 충돌 — prod 환경 사용 여부 결정 시 핵심 판단 근거
org.hibernate.type.descriptor.sql을 TRACE로 설정하면 바인드 파라미터가 별도 출력됨 (이것은 slows query log가 아닌 별도 기능)- Hibernate 6.x 에서 축약 프로퍼티
hibernate.log_slow_query도 지원 (vladmihalcea.com 기재)
Related / 관련
- raw/official-docs/at-transactional-spring-official
- 이 자료를 인용한 wiki 요약: (미생성)