Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 5fb6810

Browse files
committed
feat: Add WAL metrics for Postgres 13+ (#194)
1 parent 43ab0d1 commit 5fb6810

File tree

3 files changed

+20
-1
lines changed

3 files changed

+20
-1
lines changed

‎pkg/bot/command/explain.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,11 @@ const (
3333
queryExplain = "EXPLAIN (FORMAT TEXT) "
3434
queryExplainAnalyze = "EXPLAIN (ANALYZE, COSTS, VERBOSE, BUFFERS, FORMAT JSON %s) "
3535
settingsExplain = ", SETTINGS TRUE"
36+
walExplain = ", WAL"
3637

3738
postgresNumDiv = 10000 // Divider to get version from server_version_num.
3839
pgVersion12 = 12 // Explain Settings are available starting with Postgres 12.
40+
pgVersion13 = 13 // Explain WAL are available starting with Postgres 13.
3941

4042
// locksTitle shows locks for a single query analyzed with EXPLAIN.
4143
// locksTitle = "*Query heavy locks:*\n".
@@ -176,6 +178,10 @@ func analyzePrefix(dbVersionNum int) string {
176178
settingsValue = settingsExplain
177179
}
178180

181+
if (dbVersionNum / postgresNumDiv) >= pgVersion13 {
182+
settingsValue += walExplain
183+
}
184+
179185
return fmt.Sprintf(queryExplainAnalyze, settingsValue)
180186
}
181187

‎pkg/bot/command/explain_test.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,13 @@ func TestAnalyzePrefix(t *testing.T) {
2323
input: 120000,
2424
expectedOutput: "EXPLAIN (ANALYZE, COSTS, VERBOSE, BUFFERS, FORMAT JSON , SETTINGS TRUE) ",
2525
},
26+
{
27+
input: 130000,
28+
expectedOutput: "EXPLAIN (ANALYZE, COSTS, VERBOSE, BUFFERS, FORMAT JSON , SETTINGS TRUE, WAL) ",
29+
},
2630
{
2731
input: 160000,
28-
expectedOutput: "EXPLAIN (ANALYZE, COSTS, VERBOSE, BUFFERS, FORMAT JSON , SETTINGS TRUE) ",
32+
expectedOutput: "EXPLAIN (ANALYZE, COSTS, VERBOSE, BUFFERS, FORMAT JSON , SETTINGS TRUE, WAL) ",
2933
},
3034
}
3135

‎pkg/pgexplain/pgexplain.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,11 @@ type Plan struct {
113113
StartupCost float64 `json:"Startup Cost"`
114114
TotalCost float64 `json:"Total Cost"`
115115

116+
// WAL.
117+
WALRecords uint64 `json:"WAL Records,omitempty"`
118+
WALFPI uint64 `json:"WAL FPI,omitempty"`
119+
WALBytes uint64 `json:"WAL Bytes,omitempty"`
120+
116121
// General.
117122
Alias string `json:"Alias"`
118123
CteName string `json:"CTE Name"`
@@ -606,6 +611,10 @@ func writePlanTextNodeDetails(outputFn func(string, ...interface{}) (int, error)
606611
outputFn("Buffers: %s", buffers)
607612
}
608613

614+
if plan.WALRecords != 0 || plan.WALFPI != 0 || plan.WALBytes != 0 {
615+
_, _ = outputFn(fmt.Sprintf("WAL: records=%d fpi=%d bytes=%d", plan.WALRecords, plan.WALFPI, plan.WALBytes))
616+
}
617+
609618
ioTiming := ""
610619
if plan.IOReadTime != nil {
611620
ioTiming += fmt.Sprintf(" read=%.3f", *plan.IOReadTime)

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /