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 日志中。在 日志浏览器 中,为了减少干扰,连接生命周期的消息默认可能是隐藏的。可以使用侧边栏的连接日志过滤器来显示或隐藏这些消息。
🌐 Connection events appear in Postgres logs. In the Logs Explorer, connection lifecycle messages may be hidden by default to reduce noise. Use the connection logs filter in the sidebar to show or hide them.
通过管理 API 管理连接日志 #
🌐 Manage connection logging via the Management API
你也可以使用 管理 API 来管理连接日志:
🌐 You can also manage connection logging using the Management API:
1# Get your access token from https://supabase.com/dashboard/account/tokens2export SUPABASE_ACCESS_TOKEN="your-access-token"3export PROJECT_REF="your-project-ref"45# Get current Postgres config6curl -X GET "https://api.supabase.com/v1/projects/$PROJECT_REF/config/database/postgres" \7 -H "Authorization: Bearer $SUPABASE_ACCESS_TOKEN"89# Enable connection logging10curl -X PUT "https://api.supabase.com/v1/projects/$PROJECT_REF/config/database/postgres" \11 -H "Authorization: Bearer $SUPABASE_ACCESS_TOKEN" \12 -H "Content-Type: application/json" \13 -d '{14 "log_connections": true15 }'1617# Disable connection logging18curl -X PUT "https://api.supabase.com/v1/projects/$PROJECT_REF/config/database/postgres" \19 -H "Authorization: Bearer $SUPABASE_ACCESS_TOKEN" \20 -H "Content-Type: application/json" \21 -d '{22 "log_connections": false23 }'要验证设置,请使用 SQL 编辑器:
🌐 To verify the setting, use the SQL Editor:
1show log_connections;