-
Notifications
You must be signed in to change notification settings - Fork 1
/
statio_indexes.go
56 lines (48 loc) · 1.67 KB
/
statio_indexes.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
package pgstats
import (
"github.com/vynaloze/pgstats/nullable"
)
// PgStatIoAllIndexesView represents content of pg_statio_all_indexes view
type PgStatIoAllIndexesView []PgStatIoIndexesRow
// PgStatIoSystemIndexesView represents content of pg_statio_system_indexes view
type PgStatIoSystemIndexesView []PgStatIoIndexesRow
// PgStatIoUserIndexesView represents content of pg_statio_user_indexes view
type PgStatIoUserIndexesView []PgStatIoIndexesRow
// PgStatIoIndexesRow represents schema of pg_statio_*_indexes views
type PgStatIoIndexesRow struct {
// OID of the table for this index
Relid int64 `json:"relid"`
// OID of this index
Indexrelid int64 `json:"indexrelid"`
// Name of the schema this index is in
Schemaname string `json:"schemaname"`
// Name of the table for this index
Relname string `json:"relname"`
// Name of this index
Indexrelname string `json:"indexrelname"`
// Number of disk blocks read from this index
IdxBlksRead nullable.Int64 `json:"idx_blks_read"`
// Number of buffer hits in this index
IdxBlksHit nullable.Int64 `json:"idx_blks_hit"`
}
func (s *PgStats) fetchIoIndexes(view string) ([]PgStatIoIndexesRow, error) {
db := s.conn.db
query := "select relid,indexrelid,schemaname,relname,indexrelname," +
"idx_blks_read,idx_blks_hit from " + view
rows, err := db.Query(query)
if err != nil {
return nil, err
}
defer rows.Close()
data := make([]PgStatIoIndexesRow, 0)
for rows.Next() {
row := new(PgStatIoIndexesRow)
err := rows.Scan(&row.Relid, &row.Indexrelid, &row.Schemaname, &row.Relname, &row.Indexrelname,
&row.IdxBlksRead, &row.IdxBlksHit)
if err != nil {
return nil, err
}
data = append(data, *row)
}
return data, rows.Err()
}