Skip to content

Commit e68644e

Browse files
committed
Rework pg_stat_statements fetching to separate text vs stats
Since we now load one or the other (instead of both) we can invent special purpose methods for each, avoiding a bunch of showtext checks and making the logic easier to follow. In passing, remove a nonsensical check for sql.ErrNoRows on the result of db.PrepareContext. This only occurs when using QueryRow in Go, not when querying for multiple rows.
1 parent 11a8420 commit e68644e

File tree

3 files changed

+183
-143
lines changed

3 files changed

+183
-143
lines changed

input/full.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ func CollectFull(ctx context.Context, server *state.Server, connection *sql.DB,
6969
logger.PrintError("Error setting query text timeout: %s", err)
7070
return
7171
}
72-
ts.Statements, ts.StatementTexts, _, err = postgres.GetStatements(ctx, c, connection, true)
72+
ts.Statements, ts.StatementTexts, err = postgres.GetStatementTexts(ctx, c, connection)
7373
if err != nil {
7474
// Despite query performance data being an essential part of pganalyze, there are
7575
// situations where it may not be available (or it timed out), so treat it as a
@@ -119,7 +119,7 @@ func CollectFull(ctx context.Context, server *state.Server, connection *sql.DB,
119119
logger.PrintInfo("Successfully called pg_stat_statements_reset() for all queries, next reset in %d hours", config.Features.StatementResetFrequency/scheduler.FullSnapshotsPerHour)
120120

121121
// Make sure the next high frequency run has an empty reference point
122-
_, _, resetStatementStats, err := postgres.GetStatements(ctx, c, connection, false)
122+
resetStatementStats, err := postgres.GetStatementStats(ctx, c, connection)
123123
if err != nil {
124124
logger.PrintError("Error collecting pg_stat_statements after reset: %s", err)
125125
err = nil

input/full_1min.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ func CollectAndDiff1minStats(ctx context.Context, c *postgres.Collection, connec
1717
newState := prevState
1818
newState.LastStatementStatsAt = time.Now()
1919

20-
_, _, newState.StatementStats, err = postgres.GetStatements(ctx, c, connection, false)
20+
newState.StatementStats, err = postgres.GetStatementStats(ctx, c, connection)
2121
if err != nil {
2222
return newState, errors.Wrap(err, "error collecting pg_stat_statements")
2323
}

0 commit comments

Comments
 (0)