Skip to content

Commit c6a1d3c

Browse files
committed
Include PID in replication_outgoing entries
1 parent 4dc3102 commit c6a1d3c

2 files changed

Lines changed: 10 additions & 5 deletions

File tree

collector/collect.go

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -555,7 +555,8 @@ func (c *collector) getReplicationv10() {
555555
COALESCE(EXTRACT(EPOCH FROM flush_lag)::bigint, 0),
556556
COALESCE(EXTRACT(EPOCH FROM replay_lag)::bigint, 0),
557557
COALESCE(sync_priority, -1),
558-
COALESCE(sync_state, '')
558+
COALESCE(sync_state, ''),
559+
pid
559560
FROM pg_stat_replication
560561
ORDER BY pid ASC`
561562
rows, err := c.db.QueryContext(ctx, q)
@@ -571,7 +572,7 @@ func (c *collector) getReplicationv10() {
571572
if err := rows.Scan(&r.RoleName, &r.ApplicationName, &r.ClientAddr,
572573
&r.BackendStart, &backendXmin, &r.State, &r.SentLSN, &r.WriteLSN,
573574
&r.FlushLSN, &r.ReplayLSN, &r.WriteLag, &r.FlushLag, &r.ReplayLag,
574-
&r.SyncPriority, &r.SyncState); err != nil {
575+
&r.SyncPriority, &r.SyncState, &r.PID); err != nil {
575576
log.Fatalf("pg_stat_replication query failed: %v", err)
576577
}
577578
r.BackendXmin = int(backendXmin.Int64)
@@ -595,7 +596,8 @@ func (c *collector) getReplicationv9() {
595596
COALESCE(flush_location::text, ''),
596597
COALESCE(replay_location::text, ''),
597598
COALESCE(sync_priority, -1),
598-
COALESCE(sync_state, '')
599+
COALESCE(sync_state, ''),
600+
pid
599601
FROM pg_stat_replication
600602
ORDER BY pid ASC`
601603
if c.version < 90400 { // backend_xmin is only in v9.4+
@@ -613,7 +615,7 @@ func (c *collector) getReplicationv9() {
613615
var backendXmin sql.NullInt64
614616
if err := rows.Scan(&r.RoleName, &r.ApplicationName, &r.ClientAddr,
615617
&r.BackendStart, &backendXmin, &r.State, &r.SentLSN, &r.WriteLSN,
616-
&r.FlushLSN, &r.ReplayLSN, &r.SyncPriority, &r.SyncState); err != nil {
618+
&r.FlushLSN, &r.ReplayLSN, &r.SyncPriority, &r.SyncState, &r.PID); err != nil {
617619
log.Fatalf("pg_stat_replication query failed: %v", err)
618620
}
619621
r.BackendXmin = int(backendXmin.Int64)

model.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,13 @@ package pgmetrics
1818

1919
// ModelSchemaVersion is the schema version of the "Model" data structure
2020
// defined below. It is in the "semver" notation. Version history:
21+
// 1.5 - add PID to replication_outgoing entries
2122
// 1.4 - pgbouncer information
2223
// 1.3 - locks information
2324
// 1.2 - more table and index attributes
2425
// 1.1 - added NotificationQueueUsage and Statements
2526
// 1.0 - initial release
26-
const ModelSchemaVersion = "1.4"
27+
const ModelSchemaVersion = "1.5"
2728

2829
// Model contains the entire information collected by a single run of
2930
// pgmetrics. It can be converted to and from json without loss of
@@ -432,6 +433,8 @@ type ReplicationOut struct {
432433
ReplayLag int `json:"replay_lag"` // only in 10.x
433434
SyncPriority int `json:"sync_priority"`
434435
SyncState string `json:"sync_state"`
436+
// following fields present only in schema 1.5 and later
437+
PID int `json:"pid,omitempty"`
435438
}
436439

437440
type ReplicationIn struct {

0 commit comments

Comments
 (0)