Skip to content
Observability

配置日志

本指南解释了如何记录默认情况下不会记录的事件。日志更改会影响将来的事件;它们无法恢复过去的活动。保持调查范围有限,因为记录的声明和消息可能包含敏感内容。

🌐 This guide explains how to record events that are not logged by default. Logging changes affect future events; they cannot recover past activity. Keep the scope limited to the investigation, because recorded statements and messages can contain sensitive values.

Postgres 连接 #

🌐 Postgres connections

要记录连接和认证事件,请参阅 Postgres 连接日志。在更改之前请记下当前设置。

🌐 To record connection and authentication events, follow Postgres connection logging. Note the current setting before changing it.

启用日志记录后,打开一个新的数据库连接,并在 Logs 中找到对应事件,日志类型 设置为 Postgres 并启用 连接日志。调查完成后恢复之前的设置,除非需要继续记录日志。

🌐 After enabling logging, open a new database connection and find its event in Logs with Log Type set to Postgres and Connection logs enabled. Restore the previous setting when the investigation is complete, unless continued logging is required.

Postgres 语句 #

🌐 Postgres statements

  1. 启用 pgAudit。
  2. 在 pgAudit 配置 中选择语句类别以及会话或角色范围。先记录之前的设置。通过 PostgREST 的 API 流量使用 authenticator 角色。
  3. 在配置的范围内运行一个授权操作,然后在 日志 中找到其审计事件,日志类型 设置为 Postgres。
  4. 完成后恢复之前的日志配置。

会话设置只适用于那个数据库连接。Studio 查询不会保持持久会话。要进行持久记录,请按照 pgAudit 指南中的角色范围说明操作。

🌐 Session settings apply only to that database connection. Studio queries do not maintain a persistent session. For persistent logging, follow the role-scoped instructions in the pgAudit guide.

来自数据库函数的消息 #

🌐 Messages from database functions

一条 RAISE 消息是否会出现在 Postgres 日志中取决于 log_min_messages。从数据库连接读取当前值:

🌐 Whether a RAISE message reaches Postgres logs depends on log_min_messages. Read the current value from a database connection:

show log_min_messages;

请等待几分钟让消息显示。更改阈值前先查看 Postgres 消息级别;它们的顺序与客户端消息级别不同。

🌐 Allow a few minutes for messages to appear. See Postgres message levels before changing the threshold; their ordering differs from client message levels.

实时连接 #

🌐 Realtime connections

实时默认不会记录新的 WebSocket 连接或通道加入。为正在调查的客户端启用连接日志记录:

🌐 Realtime does not log new WebSocket connections or channel joins by default. Enable connection logging for the client under investigation:

import { } from '@supabase/supabase-js'
const = ('https://your-project.supabase.co', 'sb_publishable_...', {
: { : { : 'info' } },
})

重新连接那个客户端并加入一个通道,然后在 日志 中检查 实时 事件。删除 log_level: 'info' 并重新创建客户端以恢复默认行为。

🌐 Reconnect that client and join a channel, then inspect Realtime events in Logs. Remove log_level: 'info' and recreate the client to restore the default behavior.

有关截断和捕获限制,请参阅 日志来源和字段。

🌐 For truncation and capture constraints, see Log sources and fields.