Files
llm-wiki/raw/official-docs/postgresql-slow-query-log-official.md
T

96 lines
6.9 KiB
Markdown

---
title: official-doc / PostgreSQL log_min_duration_statement — Runtime Configuration for Logging
source_type: official-doc
url: https://www.postgresql.org/docs/current/runtime-config-logging.html
archive_url:
status: raw
confidence: high
tags: [backend, db, postgresql, observability, slow-query, dba]
related_branches: [feature-database-connection-pool-contract]
related_projects: []
created: 2026-06-09
last_reviewed: 2026-06-09
---
# PostgreSQL log_min_duration_statement — Runtime Configuration for Logging
> Layer: `raw/` — 외부 자료(공식 문서)의 원문 발췌·출처 기록.
## Parent / 활용 branch
| Branch | 이 자료가 정당화하는 결정 |
|---|---|
| [[raw/branch-notes/feature-database-connection-pool-contract]] | DB 사이드 슬로우 쿼리 탐지 방식(DB 레이어)의 파라미터 노출 여부와 설정 메커니즘 근거 |
## 출처 / Source
- 원본 URL: https://www.postgresql.org/docs/current/runtime-config-logging.html
- 저자 / 조직: PostgreSQL Global Development Group (공식 문서)
- 마지막 확인일: 2026-06-09
## 왜 저장했는지 / Why archived
`feature-database-connection-pool-contract` 브랜치에서 DB 사이드 슬로우 쿼리 탐지 대안으로 PostgreSQL `log_min_duration_statement` 를 검토. 핵심 질문: (1) 파라미터 값(바인드 변수)이 PostgreSQL 서버 로그에 출력되는가, (2) 이를 제어할 수 있는가, (3) 앱 사이드 vs DB 사이드 소유권 트레이드오프.
## 핵심 인용 / Key quotes (verbatim)
> "log_min_duration_statement (integer) — Logs the duration of each completed statement if it ran for at least the specified amount of time. For example, setting this to 250ms will cause all SQL statements that run 250ms or longer to be logged. Enabling this option can be helpful in tracking down unoptimized queries in your applications. Only superusers and users with the appropriate SET privilege can change this setting."
— PostgreSQL docs, runtime-config-logging.html
> "For clients using extended query protocol, durations of the Parse, Bind, and Execute steps are logged independently."
— PostgreSQL docs, runtime-config-logging.html
> "values of the Bind parameters are included (with any embedded single-quote marks doubled)"
— PostgreSQL docs (log_statement 섹션, extended query protocol 에서 Bind 파라미터 포함 명시)
> "log_parameter_max_length: Trims bind parameter values to specified bytes in non-error logs (default: -1 = full)"
— PostgreSQL docs, runtime-config-logging.html
> "Logged statements might reveal sensitive data and even contain plaintext passwords."
— PostgreSQL docs (보안 경고)
> "log_min_duration_sample (integer) — ... logs the same information as log_min_duration_statement but only for a subset ... Sample rate controlled by log_statement_sample_rate (floating point: 0.0 to 1.0)"
— PostgreSQL docs (샘플링 기반 슬로우 쿼리 로깅)
## Claims Extracted / 추출된 주장
| Claim ID | Claim (이 자료가 직접 말하는 것) | Evidence quote | Strength | Applies to | Does not prove |
|---|---|---|---|---|---|
| C1 | PostgreSQL `log_min_duration_statement` 는 지정 임계값(ms) 이상 소요된 완료된 쿼리의 실행 시간을 로그에 기록한다 | "Logs the duration of each completed statement if it ran for at least the specified amount of time" | `official-standard` | PostgreSQL 12+ (extended query protocol 사용 환경) | MySQL 등 다른 DB에서도 동일하게 동작한다는 주장 반증 |
| C2 | Extended query protocol 사용 시 바인드 파라미터 값이 PostgreSQL 서버 로그에 포함된다 | "values of the Bind parameters are included (with any embedded single-quote marks doubled)" | `official-standard` | PostgreSQL + JDBC extended query protocol 환경 | 앱 로그에 파라미터가 노출된다는 주장 반증 (DB 서버 로그에만 기록) |
| C3 | `log_parameter_max_length` 로 서버 로그에 기록되는 파라미터 값의 길이를 제한할 수 있다 (기본값 -1 = 전체) | "log_parameter_max_length: Trims bind parameter values to specified bytes in non-error logs (default: -1 = full)" | `official-standard` | PostgreSQL 13+ | 파라미터 값 자체를 마스킹/제거한다는 주장 반증 (길이 제한만 가능) |
| C4 | PostgreSQL 공식 문서는 슬로우 쿼리 로그가 민감한 데이터와 평문 패스워드를 포함할 수 있다고 경고한다 | "Logged statements might reveal sensitive data and even contain plaintext passwords." | `official-standard` | PostgreSQL 모든 버전 | DB 로그가 앱 로그보다 안전하다는 주장 반증 (DBA 접근 권한 격리가 전제되어야 함) |
| C5 | `log_min_duration_sample` + `log_statement_sample_rate` 로 고트래픽 환경에서 샘플링 기반 슬로우 쿼리 탐지가 가능하다 | "logs the same information as log_min_duration_statement but only for a subset" | `official-standard` | PostgreSQL 13+ 고트래픽 환경 | — |
| C6 | `log_min_duration_statement` 설정은 postgresql.conf 또는 서버 커맨드라인에서만 가능하며, superuser 또는 SET 권한이 있는 사용자만 변경 가능하다 | "Only superusers and users with the appropriate SET privilege can change this setting" | `official-standard` | PostgreSQL 모든 버전 | 앱 코드에서 동적으로 임계값을 변경할 수 있다는 주장 반증 |
## Usage Boundaries / 적용 경계
- 이 자료가 직접 증명하는 것:
- `C1~C6`: PostgreSQL DB 사이드 슬로우 쿼리 로그의 동작, 파라미터 포함 여부, 제어 방법
- 이 자료가 증명하지 않는 것:
- 앱 사이드 탐지 방식 (Hibernate, datasource-proxy 등)이 DB 사이드보다 열등하다는 주장
- DB 사이드 탐지가 앱 사이드 파라미터 노출 문제를 해결한다는 주장 (DB 서버 로그에는 파라미터 노출, DBA 접근 통제 필요)
- MySQL `slow_query_log` 의 동작 방식 (별도 문서 필요)
- 내 프로젝트에 적용하려면 추가 확인이 필요한 것:
- 프로젝트가 PostgreSQL 을 사용하는지 MySQL 을 사용하는지 확인
- DBA 팀의 PostgreSQL 서버 로그 접근 권한 정책 확인
- JDBC URL 에 `prepareThreshold=0` 설정 시 extended query protocol 비활성화 여부 확인 (파라미터 노출 패턴 변경)
## 메모 / Notes
- PostgreSQL 서버 로그는 앱 로그와 분리된 스토리지에 기록되므로, DB 인프라팀(DBA)의 접근 권한 통제로 파라미터 노출 범위를 앱 개발팀과 격리 가능
- 단 "파라미터가 DB 로그에 기록되지 않음" 과 "파라미터가 노출되지 않음" 은 다른 개념 — DBA 팀이 동일 보안 요구사항을 만족해야 함
- `auto_explain` 모듈로 슬로우 쿼리의 실행 계획(EXPLAIN)도 자동 기록 가능
## Related / 관련
- [[raw/official-docs/hibernate-slow-query-log-official]]
- [[raw/official-docs/datasource-proxy-slow-query-official]]
- 이 자료를 인용한 wiki 요약: (미생성)