@@ -97,30 +97,26 @@ func FetchSyncMetrics(ctx context.Context, config *global.Config, socketPath str
97
97
return & sync , fmt .Errorf ("failed to read Postgres version %w" , err )
98
98
}
99
99
100
- var replicationLag string
101
-
102
100
var query = lag9xQuery
103
101
104
102
if pgVersion >= pgVersion10 {
105
103
query = lagQuery
106
104
}
107
105
108
- replicationLag , err = lag (ctx , conn , query )
106
+ replicationLag , err : = lag (ctx , conn , query )
109
107
if err != nil {
110
108
log .Warn ("Failed to fetch replication lag" , err )
111
109
} else {
112
110
sync .ReplicationLag = replicationLag
113
111
}
114
112
115
- var replayedLsn , lastReplayedLsnAt string
116
-
117
113
query = lastReplayedLsn9xQuery
118
114
119
115
if pgVersion >= pgVersion10 {
120
116
query = lastReplayedLsnQuery
121
117
}
122
118
123
- lastReplayedLsnAt , replayedLsn , err = lastReplayedLsn (ctx , conn , query )
119
+ lastReplayedLsnAt , replayedLsn , err : = lastReplayedLsn (ctx , conn , query )
124
120
if err != nil {
125
121
log .Warn ("Failed to fetch last replayed lsn" , err )
126
122
} else {
@@ -166,16 +162,16 @@ func version(ctx context.Context, conn *pgx.Conn) (int, error) {
166
162
return pgVersion , nil
167
163
}
168
164
169
- func lag (ctx context.Context , conn * pgx.Conn , query string ) (string , error ) {
170
- var lagSec sql. NullString
165
+ func lag (ctx context.Context , conn * pgx.Conn , query string ) (int , error ) {
166
+ var lagSec int
171
167
172
168
row := conn .QueryRow (ctx , query )
173
169
174
170
if err := row .Scan (& lagSec ); err != nil {
175
- return "" , fmt .Errorf ("failed to read replication lag: %w" , err )
171
+ return 0 , fmt .Errorf ("failed to read replication lag: %w" , err )
176
172
}
177
173
178
- return lagSec . String , nil
174
+ return lagSec , nil
179
175
}
180
176
181
177
func lastReplayedLsn (ctx context.Context , conn * pgx.Conn , query string ) (string , string , error ) {
0 commit comments