Skip to content

Commit 7637732

Browse files
committed
Postgres 17 support 3/n
1 parent 7fbca64 commit 7637732

File tree

2 files changed

+41
-0
lines changed

2 files changed

+41
-0
lines changed

collector/collect.go

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -511,6 +511,10 @@ func (c *collector) collectCluster(o CollectConfig) {
511511
c.getProgressCopy()
512512
}
513513

514+
if c.version >= pgv17 {
515+
c.getCheckpointer()
516+
}
517+
514518
if !arrayHas(o.Omit, "log") && c.local {
515519
c.getLogInfo()
516520
}
@@ -2930,6 +2934,26 @@ func (c *collector) getProgressCreateIndex() {
29302934
c.result.CreateIndexProgress = out
29312935
}
29322936

2937+
func (c *collector) getCheckpointer() {
2938+
ctx, cancel := context.WithTimeout(context.Background(), c.timeout)
2939+
defer cancel()
2940+
2941+
q := `SELECT num_timed, num_requested, restartpoints_timed,
2942+
restartpoints_req, restartpoints_done, write_time, sync_time,
2943+
buffers_written, COALESCE(EXTRACT(EPOCH FROM stats_reset)::bigint, 0)
2944+
FROM pg_stat_checkpointer`
2945+
2946+
var ckp pgmetrics.Checkpointer
2947+
err := c.db.QueryRowContext(ctx, q).Scan(&ckp.NumTimed, &ckp.NumRequested,
2948+
&ckp.RestartpointsTimed, &ckp.RestartpointsRequested, &ckp.RestartpointsDone,
2949+
&ckp.WriteTime, &ckp.SyncTime, &ckp.BuffersWritten, &ckp.StatsReset)
2950+
if err != nil {
2951+
log.Fatalf("pg_stat_checkpointer query failed: %v", err)
2952+
}
2953+
2954+
c.result.Checkpointer = &ckp
2955+
}
2956+
29332957
//------------------------------------------------------------------------------
29342958
// PgBouncer
29352959

model.go

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,9 @@ type Model struct {
186186

187187
// raw log entries during specified time span
188188
LogEntries []LogEntry `json:"log_entries,omitempty"`
189+
190+
// contents of pg_stat_checkpointer, pg >= v17
191+
Checkpointer *Checkpointer `json:"checkpointer,omitempty"`
189192
}
190193

191194
// DatabaseByOID iterates over the databases in the model and returns the reference
@@ -1104,3 +1107,17 @@ type LogEntryExtra struct {
11041107
Level string `json:"level,omitempty"`
11051108
Line string `json:"line,omitempty"`
11061109
}
1110+
1111+
// Checkpointer contains the data from the only row of pg_stat_checkpointer.
1112+
// Present only in pg >= v17. Added in schema 1.17.
1113+
type Checkpointer struct {
1114+
NumTimed int64 `json:"num_timed"`
1115+
NumRequested int64 `json:"num_requested"`
1116+
RestartpointsTimed int64 `json:"restartpoints_timed"`
1117+
RestartpointsRequested int64 `json:"restartpoints_req"`
1118+
RestartpointsDone int64 `json:"restartpoints_done"`
1119+
WriteTime float64 `json:"write_time"`
1120+
SyncTime float64 `json:"sync_time"`
1121+
BuffersWritten int64 `json:"buffers_written"`
1122+
StatsReset int64 `json:"stats_reset"`
1123+
}

0 commit comments

Comments
 (0)