Skip to content

Commit

Permalink
Add pg_stat_statements WAL usage: implement in 'profile'.
Browse files Browse the repository at this point in the history
  • Loading branch information
lesovsky committed Mar 6, 2021
1 parent d413cef commit 38d36c4
Show file tree
Hide file tree
Showing 8 changed files with 12,629 additions and 1 deletion.
2 changes: 2 additions & 0 deletions cmd/report/report.go
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,8 @@ func selectReport(opts options) string {
return "statements_temp"
case "l":
return "statements_local"
case "w":
return "statements_wal"
}
case opts.showProgress != "":
switch opts.showProgress {
Expand Down
1 change: 1 addition & 0 deletions cmd/report/report_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ func Test_selectReport(t *testing.T) {
{opts: options{showStatements: "i"}, want: "statements_io"},
{opts: options{showStatements: "t"}, want: "statements_temp"},
{opts: options{showStatements: "l"}, want: "statements_local"},
{opts: options{showStatements: "w"}, want: "statements_wal"},
{opts: options{showProgress: "v"}, want: "progress_vacuum"},
{opts: options{showProgress: "c"}, want: "progress_cluster"},
{opts: options{showProgress: "i"}, want: "progress_index"},
Expand Down
19 changes: 19 additions & 0 deletions report/describe.go
Original file line number Diff line number Diff line change
Expand Up @@ -387,6 +387,25 @@ Details: https://www.postgresql.org/docs/current/pgstatstatements.html
* - extended value, based on origin and calculated using additional functions.
Details: https://www.postgresql.org/docs/current/pgstatstatements.html
`

// pgStatStatementsWalDescription is the detailed description of pg_stat_statements section about WAL usage
pgStatStatementsWalDescription = `Statements WAL usage statistics based on pg_stat_statements:
column origin description
- user rolname Name of of user who executed the statement
- database datname Name of database in which the statement was executed
- t_wal wal_bytes Total amount of WAL bytes generated by the statement, in kB
- wal wal_bytes Total amount of WAL bytes generated by the statement, in kB/s
- wal_records wal_records Total number of WAL records generated by the statement, in records/s
- wal_fpi wal_fpi Total number of WAL full page images generated by the statement, in fpi/s
- calls calls Number of times query executed, calls/s
- queryid* rolname,datname,query Fake queryid based on username, datname and text of the statement
- query query Text of a representative statement
* - extended value, based on origin and calculated using additional functions.
Details: https://www.postgresql.org/docs/current/pgstatstatements.html
`
)
1 change: 1 addition & 0 deletions report/report.go
Original file line number Diff line number Diff line change
Expand Up @@ -412,6 +412,7 @@ func describeReport(w io.Writer, report string) error {
"statements_io": pgStatStatementsIODescription,
"statements_local": pgStatStatementsTempDescription,
"statements_temp": pgStatStatementsLocalDescription,
"statements_wal": pgStatStatementsWalDescription,
}

if description, ok := m[report]; ok {
Expand Down
5 changes: 5 additions & 0 deletions report/report_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,11 @@ func Test_app_doReport(t *testing.T) {
config: Config{ReportType: "statements_temp", TruncLimit: 32, Rate: time.Second},
wantFile: "testdata/report_statements_temp.golden",
},
{
start: "2021-01-23 15:31:00", end: "2021-01-23 15:32:00",
config: Config{ReportType: "statements_wal", TruncLimit: 32, Rate: time.Second},
wantFile: "testdata/report_statements_wal.golden",
},
{
start: "2021-01-23 15:31:00", end: "2021-01-23 15:32:00",
config: Config{ReportType: "progress_vacuum", TruncLimit: 32, Rate: time.Second},
Expand Down
Binary file modified report/testdata/pgcenter.stat.golden.tar
Binary file not shown.
12,600 changes: 12,600 additions & 0 deletions report/testdata/report_statements_wal.golden

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion top/menu_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ func Test_selectMenuStyle(t *testing.T) {
want int
}{
{menu: menuNone, want: 0},
{menu: menuPgss, want: 5},
{menu: menuPgss, want: 6},
{menu: menuProgress, want: 5},
{menu: menuConf, want: 4},
}
Expand Down

0 comments on commit 38d36c4

Please sign in to comment.