获取PostgreSQL慢日志列表
更新时间:2025-05-08
接口描述
获取PostgreSQL数据库指定时间范围内的慢日志列表,包含执行时间、查询语句、数据库名称等详细信息。
权限说明
鉴权认证机制的详细内容请参见鉴权认证。
请求结构
Plain
1GET /api/v{version}/diagnosis/postgresql/slowlog/list?product=string
2&appId=string
3&nodeId=string
4&start=string
5&end=string
6&dbNames=dbNames
7&clientIps=clientIps
8&fingerprintMd5=fingerprintMd5
9&page=int
10&pageSize=int HTTP/1.1
11Host: dbsc.bj.baidubce.com
12Authorization: authorization string
请求头域
除公共头域外,无其它特殊头域。
请求参数
参数名称 | 类型 | 必选 | 参数位置 | 描述 |
---|---|---|---|---|
version | string | 是 | Path参数 | API版本号 |
appId | string | 是 | Query参数 | 实例ID,例如:rdsmte2lk8ap0sl |
nodeId | string | 是 | Query参数 | 节点ID |
start | string | 是 | Query参数 | 查询开始时间,UTC格式,例如:2023-06-01T00:00:00Z |
end | string | 是 | Query参数 | 查询结束时间,UTC格式,例如:2023-06-02T00:00:00Z |
page | int | 否 | Query参数 | 分页页码,默认值为1 |
pageSize | int | 否 | Query参数 | 每页记录数,默认值为20 |
dbNames | []string | 否 | Query参数 | 数据库名称列表 |
clientIPs | []string | 否 | Query参数 | 客户端IP列表 |
users | []string | 否 | Query参数 | 用户名列表 |
orderBy | string | 否 | Query参数 | 排序字段,默认为start。参考PGSlowLogInfo中结构体字段 |
order | string | 否 | Query参数 | 排序方向,可选值为asc和desc,默认为desc |
响应头域
无。
响应参数
参数名称 | 类型 | 描述 |
---|---|---|
totalCount | int64 | 总记录数 |
logs | []PGSlowLogInfo | 慢日志信息列表 |
PGSlowLogInfo结构
字段名 | 类型 | 说明 |
---|---|---|
product | string | 产品类型 |
appID | string | 实例ID |
appName | string | 实例名称 |
appShortID | string | 实例短ID |
clusterID | string | 集群ID |
nodeID | string | 节点ID |
uuid | string | 慢日志记录唯一标识 |
pid | int64 | 进程ID |
clientIP | string | 客户端IP |
currentDB | string | 数据库名称 |
currentUser | string | 用户名 |
duration | int64 | 执行时间(毫秒) |
start | time.Time | 开始时间 |
end | time.Time | 结束时间 |
statement | string | SQL语句 |
fingerprint | string | SQL指纹 |
fingerprintMD5 | string | SQL指纹的MD5值 |
请求示例
Plain
1GET /api/v1/diagnosis/postgresql/slowlog/list?product=rds&appId=rdsmte2lk8ap0sl&nodeId=i-node1&start=2023-06-01T00:00:00Z&end=2023-06-02T00:00:00Z&page=1&pageSize=10 HTTP/1.1
2Host: dbsc.bj.baidu.com
3Content-Type: application/json
4Authorization: bce-auth-v1/f81d3b34e48048fbb2634dc7882d7e21/2023-07-11T11:17:29Z/3600/host/74c506f68c65e26c633bfa104c863fffac5190fdec1ec24b7c03eb5d67d2e1de
响应示例
JSON
1{
2 "totalCount": 100,
3 "logs": [
4 {
5 "product": "rds",
6 "appID": "rdsmte2lk8ap0sl",
7 "appName": "测试PostgreSQL实例",
8 "appShortID": "mte2lk8a",
9 "clusterID": "c-abcdef",
10 "nodeID": "i-node1",
11 "uuid": "550e8400-e29b-41d4-a716-446655440000",
12 "pid": 12345,
13 "clientIP": "10.10.10.10",
14 "currentDB": "test_db",
15 "currentUser": "postgres",
16 "duration": 1500,
17 "start": "2023-06-01T10:30:00Z",
18 "end": "2023-06-01T10:30:01.5Z",
19 "statement": "SELECT * FROM large_table WHERE id > 1000 ORDER BY created_at DESC",
20 "fingerprint": "SELECT * FROM large_table WHERE id > ? ORDER BY created_at DESC",
21 "fingerprintMD5": "a1b2c3d4e5f6g7h8i9j0"
22 },
23 {
24 "product": "rds",
25 "appID": "rdsmte2lk8ap0sl",
26 "appName": "测试PostgreSQL实例",
27 "appShortID": "mte2lk8a",
28 "clusterID": "c-abcdef",
29 "nodeID": "i-node1",
30 "uuid": "550e8400-e29b-41d4-a716-446655440001",
31 "pid": 12346,
32 "clientIP": "10.10.10.20",
33 "currentDB": "test_db",
34 "currentUser": "postgres",
35 "duration": 3200,
36 "start": "2023-06-01T11:15:00Z",
37 "end": "2023-06-01T11:15:03.2Z",
38 "statement": "SELECT t1.*, t2.name FROM table1 t1 JOIN table2 t2 ON t1.id = t2.id WHERE t1.status = 'active'",
39 "fingerprint": "SELECT t1.*, t2.name FROM table1 t1 JOIN table2 t2 ON t1.id = t2.id WHERE t1.status = ?",
40 "fingerprintMD5": "b2c3d4e5f6g7h8i9j0k1"
41 }
42 ]
43}