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 )を使用して、 TIMESTAMP フィールドのイベントテーブルと record_type = 'LOG'``を持つ記録の 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:
timestamp |
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]は、セッションで実行された最初のコマンドの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);クエリのキャンセルとして、pid1592908を持つセッションによって実行された。pid
1592908によるコマンド14のログ記録により、2つのログ行として[14-1]と[14-2]が追加された。pid
1593992を持つセッションによって実行された10番目のコマンドの単一のログ行は、pid1592908のコマンド14の2行の間で終了した。pid
1592908を持つセッションによって実行された次のコマンドはshow log_min_duration_statementクエリで、1つのログ行[15-1]のみを必要とした。
Tip
Postgresログ行形式は log_line_prefix サーバー設定によって決まります。デフォルトはSnowflake Postgresインスタンスの'[%p][%b][%v][%x] %q[user=%u,db=%d,app=%a] [%h]'です。