Skip to content

Commit 07fc7fd

Browse files
committed
add pg_stat_statements by default to NodeSet
1 parent 019f990 commit 07fc7fd

File tree

2 files changed

+16
-2
lines changed

2 files changed

+16
-2
lines changed

book/src/framework/observability/postgresql.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,10 @@ We run exporter for the first 5 nodes, that should be enough to debug performanc
99
## Data sources and raw queries
1010

1111
You can use `PostgreSQL X` datasources, first 5 nodes to select things for your [dashboards](http://localhost:3000/explore?panes=%7B%22qrr%22:%7B%22datasource%22:%22P4DD770FAD7295D26%22,%22queries%22:%5B%7B%22refId%22:%22A%22,%22datasource%22:%7B%22type%22:%22postgres%22,%22uid%22:%22P4DD770FAD7295D26%22%7D,%22format%22:%22table%22,%22rawSql%22:%22select%20%2A%20from%20sessions;%22,%22editorMode%22:%22code%22,%22sql%22:%7B%22columns%22:%5B%7B%22type%22:%22function%22,%22parameters%22:%5B%5D%7D%5D,%22groupBy%22:%5B%7B%22type%22:%22groupBy%22,%22property%22:%7B%22type%22:%22string%22%7D%7D%5D,%22limit%22:50%7D,%22rawQuery%22:true%7D%5D,%22range%22:%7B%22from%22:%22now-6h%22,%22to%22:%22now%22%7D%7D%7D&schemaVersion=1&orgId=1) or debug.
12+
13+
## Slow queries debug
14+
15+
Use `pg_stat_statements` extension, it is enabled for all databases in `NodeSet`
16+
```
17+
select * from pg_stat_statements;
18+
```

framework/components/postgres/postgres.go

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,11 @@ func NewPostgreSQL(in *Input) (*Output, error) {
5555

5656
var sqlCommands []string
5757
for i := 0; i <= in.Databases; i++ {
58-
sqlCommands = append(sqlCommands, fmt.Sprintf("CREATE DATABASE db_%d;", i))
58+
sqlCommands = append(sqlCommands,
59+
fmt.Sprintf("CREATE DATABASE db_%d;", i),
60+
fmt.Sprintf("\\c db_%d", i),
61+
"CREATE EXTENSION pg_stat_statements;",
62+
)
5963
}
6064
if in.JDDatabase {
6165
sqlCommands = append(sqlCommands, "CREATE DATABASE jd;")
@@ -89,7 +93,10 @@ func NewPostgreSQL(in *Input) (*Output, error) {
8993
"POSTGRES_DB": Database,
9094
},
9195
Cmd: []string{
92-
"postgres", "-c", fmt.Sprintf("port=%s", Port),
96+
"postgres", "-c",
97+
fmt.Sprintf("port=%s", Port),
98+
"-c", "shared_preload_libraries=pg_stat_statements",
99+
"-c", "pg_stat_statements.track=all",
93100
},
94101
Files: []testcontainers.ContainerFile{
95102
{

0 commit comments

Comments
 (0)