SYSTEM HISTORY是企业版功能。 如需获取许可证,请联系 Databend 支持团队。
系统历史表
Databend 的系统历史表通过自动追踪数据库活动,为合规审计、安全监控和性能分析提供数据治理 (Data Governance) 能力。
可用表
表 | 用途 | 主要用例 |
---|---|---|
query_history | 完整的 SQL 执行审计追踪 | 性能分析、合规追踪、使用监控 |
access_history | 数据访问与修改日志 | 数据血缘、合规报告、变更管理 |
login_history | 用户认证追踪 | 安全审计、失败登录监控、访问模式分析 |
profile_history | 详细查询执行画像 | 性能优化、资源规划、瓶颈识别 |
log_history | 原始系统日志与事件 | 系统故障排查、错误分析、运维监控 |
权限
访问限制:
- 仅允许
SELECT
和DROP
操作 - 禁止所有用户执行
ALTER
操作 - 所有权不可转移
所需权限: 查询系统历史表需具备以下任一权限:
GRANT SELECT ON *.*
(全局访问)GRANT SELECT ON system_history.*
(数据库级访问)GRANT SELECT ON system_history.table_name
(表级访问)
示例:
-- 为合规团队创建审计角色
CREATE ROLE audit_team;
GRANT SELECT ON system_history.* TO ROLE audit_team;
CREATE USER compliance_officer IDENTIFIED BY 'secure_password' WITH DEFAULT_ROLE='audit_team';
GRANT ROLE audit_team TO USER compliance_officer;
配置
Databend Cloud
✅ 自动启用 — 所有系统历史表开箱即用,无需额外配置。
自建 Databend
📝 需手动配置 — 点击展开配置详情
最小配置
启用系统历史表须在 databend-query.toml
中配置全部 5 张表:
[log.history]
on = true
# 必须配置全部 5 张表才能启用历史日志
# retention 为可选项(默认 168 小时 = 7 天)
[[log.history.tables]]
table_name = "query_history"
retention = 168 # 可选:7 天(默认)
[[log.history.tables]]
table_name = "login_history"
retention = 168 # 可选:7 天(默认)
[[log.history.tables]]
table_name = "access_history"
retention = 168 # 可选:7 天(默认)
[[log.history.tables]]
table_name = "profile_history"
retention = 168 # 可选:7 天(默认)
[[log.history.tables]]
table_name = "log_history"
retention = 168 # 可选:7 天(默认)
自定义存储(可选)
默认情况下,历史表使用主数据库存储。如需独立 S3 存储:
[log.history]
on = true
storage_on = true
[log.history.storage]
type = "s3"
[log.history.storage.s3]
bucket = "your-history-bucket"
root = "history_tables"
endpoint_url = "https://s3.amazonaws.com"
access_key_id = "your-access-key"
secret_access_key = "your-secret-key"
[[log.history.tables]]
table_name = "query_history"
[[log.history.tables]]
table_name = "profile_history"
[[log.history.tables]]
table_name = "login_history"
[[log.history.tables]]
table_name = "access_history"
⚠️ 注意: 修改存储配置后,现有历史表将被删除并重新创建。
完整配置选项请参考 查询配置:[log.history] 部分。