Postgres 连接日志
为了安全监控和合规审计,Postgres 可以将连接生命周期事件记录到你项目的 Postgres 日志,包括诸如 connection received、connection authenticated 和 connection authorized 的事件。
🌐 For security monitoring and compliance audits, Postgres can log connection lifecycle events to your project's Postgres logs, including events such as connection received, connection authenticated, and connection authorized.
默认行为 #
🌐 Default behavior
默认情况下,Supabase 会把新项目的 log_connections 设为关闭,你必须先手动开启。这个行为符合常见的托管 Postgres 默认设置,并且可以减少高频连接事件生成的日志量。
🌐 By default, Supabase sets log_connections to off for new projects and you must enable it first. This behavior matches common managed Postgres defaults and reduces log volume from high-frequency connection events.
现有项目可能会根据计划和合规配置保留不同的设置:
🌐 Existing projects may retain different settings depending on plan and compliance configuration:
- 团队、企业和 HIPAA 组织 — 通常会启用连接日志记录以支持审计要求。
- HIPAA 项目 — 当项目被标记为高合规性时,Supabase 可以启用连接日志记录。若之后禁用连接日志,安全顾问 会发出警告。
合规注意事项 #
🌐 Compliance considerations
如果你需要 SOC 2 或其他合规项目的连接审计证据,你必须明确启用它。
🌐 If you need connection audit evidence for SOC 2 or other compliance programs, you must enable it explicitly.
连接日志支持某些合规计划所需的审计和监控控制:
🌐 Connection logging supports audit and monitoring controls required by some compliance programs:
- HIPAA — 高合规性的项目应保持连接日志开启。参考医疗数据共享责任模型和HIPAA 合规指南。
- SOC 2 — 需要获取连接审计证据的用户应该启用日志记录,并根据自己的策略保留日志。请参阅SOC 2 合规指南。
禁用连接日志不会影响其他 Supabase 日志(例如,平台审计日志、身份验证审计日志 或 pgAudit)。
🌐 Disabling connection logging does not affect other Supabase logging (for example, Platform Audit Logs, Auth Audit Logs, or pgAudit).
通过仪表板管理连接日志 #
🌐 Manage connection logging via the dashboard
你可以在仪表板的 数据库设置 部分通过 记录连接 选项来配置连接日志。
🌐 You can configure connection logging from the Log connections setting in the Database Settings section of the Dashboard.
确保你对该项目拥有所有者或管理员权限。
🌐 Ensure that you have Owner or Admin permissions for the project.
连接事件会出现在 Postgres 日志 中。当选择 Postgres 日志类型时,它们会默认包含。清除 Postgres 下的 连接日志 可隐藏它们。
🌐 Connection events appear in Postgres logs. They are included by default when the Postgres log type is selected. Clear Connection logs under Postgres to hide them.
通过管理 API 管理连接日志 #
🌐 Manage connection logging via the Management API
你也可以使用 管理 API 来管理连接日志:
🌐 You can also manage connection logging using the Management API:
# Get your access token from https://supabase.nodejs.cn/dashboard/account/tokensexport SUPABASE_ACCESS_TOKEN="your-access-token"export PROJECT_REF="your-project-ref"# Get current Postgres configcurl -X GET "https://api.supabase.com/v1/projects/$PROJECT_REF/config/database/postgres" \ -H "Authorization: Bearer $SUPABASE_ACCESS_TOKEN"# Enable connection loggingcurl -X PUT "https://api.supabase.com/v1/projects/$PROJECT_REF/config/database/postgres" \ -H "Authorization: Bearer $SUPABASE_ACCESS_TOKEN" \ -H "Content-Type: application/json" \ -d '{ "log_connections": true }'# Disable connection loggingcurl -X PUT "https://api.supabase.com/v1/projects/$PROJECT_REF/config/database/postgres" \ -H "Authorization: Bearer $SUPABASE_ACCESS_TOKEN" \ -H "Content-Type: application/json" \ -d '{ "log_connections": false }'要验证设置,请使用 SQL 编辑器:
🌐 To verify the setting, use the SQL Editor:
show log_connections;