Skip to content

Fix pg13 with pg_stat_statements #544

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 3 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 35 additions & 2 deletions cmd/postgres_exporter/postgres_exporter.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ import (
"database/sql"
"errors"
"fmt"
"gopkg.in/alecthomas/kingpin.v2"
"gopkg.in/yaml.v2"
"io/ioutil"
"math"
"net/http"
Expand All @@ -40,8 +42,6 @@ import (
"github.com/prometheus/common/version"
"github.com/prometheus/exporter-toolkit/web"
webflag "github.com/prometheus/exporter-toolkit/web/kingpinflag"
"gopkg.in/alecthomas/kingpin.v2"
"gopkg.in/yaml.v2"
)

var (
Expand Down Expand Up @@ -491,6 +491,39 @@ var queryOverrides = map[string][]OverrideQuery{
`,
},
},
"pg_stat_statements": {
{
semver.MustParseRange(">=13.0.0"),
`
SELECT t2.rolname,
t3.datname,
queryid,
calls,
total_exec_time / 1000 as total_time_seconds,
min_exec_time / 1000 as min_time_seconds,
max_exec_time / 1000 as max_time_seconds,
mean_exec_time / 1000 as mean_time_seconds,
stddev_exec_time / 1000 as stddev_time_seconds,
rows,
shared_blks_hit,
shared_blks_read,
shared_blks_dirtied,
shared_blks_written,
local_blks_hit,
local_blks_read,
local_blks_dirtied,
local_blks_written,
temp_blks_read,
temp_blks_written,
blk_read_time / 1000 as blk_read_time_seconds,
blk_write_time / 1000 as blk_write_time_seconds
FROM pg_stat_statements t1
JOIN pg_roles t2 ON (t1.userid = t2.oid)
JOIN pg_database t3 ON (t1.dbid = t3.oid)
WHERE t2.rolname != 'rdsadmin'
`,
},
},
}

// Convert the query override file to the version-specific query override file
Expand Down