Skip to content
Platform

Postgres 连接日志

为了安全监控和合规审计,Postgres 可以将连接生命周期事件记录到你项目的 Postgres 日志,包括诸如 connection receivedconnection authenticatedconnection 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

连接日志支持某些合规计划所需的审计和监控控制:

🌐 Connection logging supports audit and monitoring controls required by some compliance programs:

禁用连接日志不会影响其他 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.

通过管理 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/tokens
2
export SUPABASE_ACCESS_TOKEN="your-access-token"
3
export PROJECT_REF="your-project-ref"
4
5
# Get current Postgres config
6
curl -X GET "https://api.supabase.com/v1/projects/$PROJECT_REF/config/database/postgres" \
7
-H "Authorization: Bearer $SUPABASE_ACCESS_TOKEN"
8
9
# Enable connection logging
10
curl -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": true
15
}'
16
17
# Disable connection logging
18
curl -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": false
23
}'

要验证设置,请使用 SQL 编辑器:

🌐 To verify the setting, use the SQL Editor:

1
show log_connections;