Skip to content
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

Update pg_stat_progress_vacuum field names for Postgres 17 #527

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
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
26 changes: 23 additions & 3 deletions input/postgres/vacuum_progress.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,12 @@
"github.com/pganalyze/collector/util"
)

const vacuumProgressSQLmaxDeadTuplesField = `v.max_dead_tuples`
const vacuumProgressSQLpg17maxDeadTuplesField = `v.max_dead_tuple_bytes`

const vacuumProgressSQLdeadTuplesField = `v.num_dead_tuples`
const vacuumProgressSQLpg17deadTuplesField = `v.dead_tuple_bytes`

const vacuumProgressSQLDefault string = `
WITH activity AS (
SELECT pg_catalog.to_char(pid, 'FM0000000') AS padded_pid,
Expand Down Expand Up @@ -40,8 +46,8 @@
COALESCE(v.heap_blks_scanned, 0) AS heap_blks_scanned,
COALESCE(v.heap_blks_vacuumed, 0) AS heap_blks_vacuumed,
COALESCE(v.index_vacuum_count, 0) AS index_vacuum_count,
COALESCE(v.max_dead_tuples, 0) AS max_dead_tuples,
COALESCE(v.num_dead_tuples, 0) AS num_dead_tuples
COALESCE(%s, 0) AS max_dead_tuples,
COALESCE(%s, 0) AS num_dead_tuples
FROM %s v
JOIN activity a USING (pid)
LEFT JOIN pg_catalog.pg_class c ON (c.oid = v.relid)
Expand All @@ -59,13 +65,27 @@
activitySourceTable = "pg_catalog.pg_stat_activity"
}

var maxDeadTuplesField string
if postgresVersion.Numeric >= state.PostgresVersion17 {

Check failure on line 69 in input/postgres/vacuum_progress.go

View workflow job for this annotation

GitHub Actions / build

undefined: state.PostgresVersion17
maxDeadTuplesField = vacuumProgressSQLpg17maxDeadTuplesField
} else {
maxDeadTuplesField = vacuumProgressSQLmaxDeadTuplesField
}

var deadTuplesField string
if postgresVersion.Numeric >= state.PostgresVersion17 {

Check failure on line 76 in input/postgres/vacuum_progress.go

View workflow job for this annotation

GitHub Actions / build

undefined: state.PostgresVersion17
deadTuplesField = vacuumProgressSQLpg17deadTuplesField
} else {
deadTuplesField = vacuumProgressSQLdeadTuplesField
}

var vacuumSourceTable string
if StatsHelperExists(ctx, db, "get_stat_progress_vacuum") {
vacuumSourceTable = "pganalyze.get_stat_progress_vacuum()"
} else {
vacuumSourceTable = "pg_catalog.pg_stat_progress_vacuum"
}
sql = fmt.Sprintf(vacuumProgressSQLDefault, activitySourceTable, vacuumSourceTable)
sql = fmt.Sprintf(vacuumProgressSQLDefault, activitySourceTable, maxDeadTuplesField, deadTuplesField, vacuumSourceTable)

stmt, err := db.PrepareContext(ctx, QueryMarkerSQL+sql)
if err != nil {
Expand Down
Loading