Snowflake Postgres 로깅¶
Postgres 로그 데이터 검색하기¶
All Postgres servers on Snowflake Postgres instances log locally to syslog. The log data is collected from there and sent to your account’s active event table.
지정된 인스턴스에 대한 Postgres 로그를 보려면 인스턴스 호스트 이름의 첫 부분(즉, 인스턴스 ID 또는 cluster_id)을 사용하여 ``record_type = ‘LOG’``인 레코드의 TIMESTAMP 필드 및 VALUE 필드의 MESSAGE 부분에 대한 이벤트 테이블을 쿼리합니다. 예를 들어, ID가 ``oyrpb2cwtvbu5al5vtbyrsnkgy``인 인스턴스에 대한 마지막 10분의 로그 항목을 가져옵니다.
SELECT TIMESTAMP, VALUE:MESSAGE as log_line
FROM SNOWFLAKE.TELEMETRY.EVENTS
WHERE resource_attributes['snowflake.o11y.logtype'] = 'postgres-otelcol-vm-agent'
AND resource_attributes['instance.id'] = 'oyrpb2cwtvbu5al5vtbyrsnkgy'
AND record_type = 'LOG'
AND TIMESTAMP > CURRENT_TIMESTAMP() - INTERVAL '10 MINUTES'
LIMIT 100;
참고
위의 쿼리는 계정 기본 이벤트 테이블인 SNOWFLAKE.TELEMETRY.EVENTS를 사용합니다. 사용자 지정 이벤트 테이블을 설정한 경우 쿼리를 적절하게 조정해야 합니다.
Each row of the output will contain a single log-line entry that was logged by the Postgres server on the given Snowflake Postgres instance with the timestamp when it was originally logged. Note that it can take up to a few minutes between the time Postgres makes a log entry and it is available in the event table.
Postgres 로그 줄 인터리빙 이해하기¶
Note that Postgres uses multi-line logging and since multiple Postgres server processes will be making log entries concurrently, full log entries from different Postgres server processes will often be interleaved. For example, let’s consider these log line entries:
타임스탬프 |
log_line |
2025-12-09 23:16:38.760 |
“[14-1] [1592908][client backend][27/2][0] [user=snowflake_admin,db=postgres,app=psql] [34.214.158.144] ERROR: canceling statement due to user request” |
2025-12-09 23:16:38.760 |
“[10-1] [1593992][not initialized][][0] [user=[unknown],db=[unknown],app=[unknown]] [34.214.158.144] LOG: connection received: host=34.214.158.144 port=46114” |
2025-12-09 23:16:38.760 |
“[14-2] [1592908][client backend][27/2][0] [user=snowflake_admin,db=postgres,app=psql] [34.214.158.144] STATEMENT: select pg_sleep(10);” |
2025-12-09 23:16:43.007 |
“[15-1] [1592908][client backend][27/3][0] [user=snowflake_admin,db=postgres,app=psql] [34.214.158.144] LOG: AUDIT: SESSION,2,1,MISC,SHOW,,,show log_min_duration_statement,<not logged>” |
각 로그 줄 항목에서:
괄호로 묶인 첫 번째 값은 명령을 실행한 세션의 명령 번호와 하이픈으로 구분된 해당 명령의 로그 줄입니다. 예를 들어, [1-1] 및 [1-2]는 세션에서 실행된 첫 번째 명령의 두 로그 줄입니다.
The second bracketed value is the process ID (pid) for the session that logged the line. Postgres uses a process-based (vs. thread-based) concurrency model so each session is run on its own server process.
이 예제에서는 다음을 확인할 수 있습니다.
명령 14는
select pg_sleep(10);쿼리의 취소로 pid가 ``1592908``인 세션에서 실행되었습니다.pid ``1592908``에 의한 명령 14의 로깅은 [14-1] 및 [14-2]의 두 로그 줄을 추가했습니다.
pid가 ``1593992``인 세션에서 실행하는 10번째 명령의 단일 로그 줄이 pid ``1592908``에 대한 명령 14의 두 줄 사이에 있었습니다.
pid가
1592908``인 세션에서 실행하는 다음 명령은 ``show log_min_duration_statement쿼리였으며 하나의 로그 줄 [15-1]만 필요했습니다.
팁
Postgres 로그 줄 형식은 `log_line_prefix<https://www.postgresql.org/docs/current/runtime-config-logging.html#GUC-LOG-LINE-PREFIX>`_ 서버 설정에 따라 결정되며, Snowflake Postgres 인스턴스에서 기본값은 ‘[%p][%b][%v][%x] %q[user=%u,db=%d,app=%a] [%h]’입니다.