Skip to content

Commit

Permalink
add support for Postgres 17+ (fixes #21)
Browse files Browse the repository at this point in the history
  • Loading branch information
def committed Dec 30, 2024
1 parent 9863128 commit 3ad158a
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions collector/pg_stat_statements.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@ package collector
import (
"database/sql"
"fmt"
"time"

"github.com/blang/semver"
"github.com/coroot/coroot-pg-agent/obfuscate"
"time"
)

type ssRow struct {
Expand Down Expand Up @@ -37,8 +38,10 @@ func (c *Collector) getStatStatements(version semver.Version, querySizeLimit int
switch {
case semver.MustParseRange(">=9.4.0 <13.0.0")(version):
query = `SELECT d.datname, r.rolname, LEFT(s.query, %d), s.queryid, s.calls, s.total_time, s.blk_read_time + s.blk_write_time`
case semver.MustParseRange(">=13.0.0")(version):
case semver.MustParseRange(">=13.0.0 <17.0.0")(version):
query = `SELECT d.datname, r.rolname, LEFT(s.query, %d), s.queryid, s.calls, s.total_plan_time + s.total_exec_time, s.blk_read_time + s.blk_write_time`
case semver.MustParseRange(">=17.0.0")(version):
query = `SELECT d.datname, r.rolname, LEFT(s.query, %d), s.queryid, s.calls, s.total_plan_time + s.total_exec_time, s.shared_blk_read_time + s.shared_blk_write_time + s.local_blk_read_time + s.local_blk_write_time + s.temp_blk_read_time + s.temp_blk_write_time`
default:
return nil, fmt.Errorf("postgres version %s is not supported", version)
}
Expand Down

0 comments on commit 3ad158a

Please sign in to comment.