Skip to content

Commit 8588d88

Browse files
committed
add pg_stat_statements by default to NodeSet
1 parent 019f990 commit 8588d88

File tree

3 files changed

+19
-30
lines changed

3 files changed

+19
-30
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/jd/jd.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,6 @@ func defaultJDDB() *postgres.Input {
5656
Port: 14000,
5757
Name: "jd-db",
5858
VolumeName: "jd",
59-
JDDatabase: true,
6059
}
6160
}
6261

framework/components/postgres/postgres.go

Lines changed: 12 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -29,17 +29,14 @@ type Input struct {
2929
Name string `toml:"name"`
3030
VolumeName string `toml:"volume_name"`
3131
Databases int `toml:"databases"`
32-
JDDatabase bool `toml:"jd_database"`
3332
PullImage bool `toml:"pull_image"`
3433
Out *Output `toml:"out"`
3534
}
3635

3736
type Output struct {
38-
Url string `toml:"url"`
39-
ContainerName string `toml:"container_name"`
40-
DockerInternalURL string `toml:"docker_internal_url"`
41-
JDUrl string `toml:"jd_url"`
42-
JDDockerInternalURL string `toml:"jd_docker_internal_url"`
37+
Url string `toml:"url"`
38+
ContainerName string `toml:"container_name"`
39+
DockerInternalURL string `toml:"docker_internal_url"`
4340
}
4441

4542
func NewPostgreSQL(in *Input) (*Output, error) {
@@ -55,10 +52,11 @@ func NewPostgreSQL(in *Input) (*Output, error) {
5552

5653
var sqlCommands []string
5754
for i := 0; i <= in.Databases; i++ {
58-
sqlCommands = append(sqlCommands, fmt.Sprintf("CREATE DATABASE db_%d;", i))
59-
}
60-
if in.JDDatabase {
61-
sqlCommands = append(sqlCommands, "CREATE DATABASE jd;")
55+
sqlCommands = append(sqlCommands,
56+
fmt.Sprintf("CREATE DATABASE db_%d;", i),
57+
fmt.Sprintf("\\c db_%d", i),
58+
"CREATE EXTENSION pg_stat_statements;",
59+
)
6260
}
6361
sqlCommands = append(sqlCommands, "ALTER USER chainlink WITH SUPERUSER;")
6462
initSQL := strings.Join(sqlCommands, "\n")
@@ -89,7 +87,10 @@ func NewPostgreSQL(in *Input) (*Output, error) {
8987
"POSTGRES_DB": Database,
9088
},
9189
Cmd: []string{
92-
"postgres", "-c", fmt.Sprintf("port=%s", Port),
90+
"postgres", "-c",
91+
fmt.Sprintf("port=%s", Port),
92+
"-c", "shared_preload_libraries=pg_stat_statements",
93+
"-c", "pg_stat_statements.track=all",
9394
},
9495
Files: []testcontainers.ContainerFile{
9596
{
@@ -158,23 +159,5 @@ func NewPostgreSQL(in *Input) (*Output, error) {
158159
Database,
159160
),
160161
}
161-
if in.JDDatabase {
162-
o.JDDockerInternalURL = fmt.Sprintf(
163-
"postgresql://%s:%s@%s:%s/%s?sslmode=disable",
164-
User,
165-
Password,
166-
containerName,
167-
Port,
168-
"jd",
169-
)
170-
o.JDUrl = fmt.Sprintf(
171-
"postgresql://%s:%s@%s:%d/%s?sslmode=disable",
172-
User,
173-
Password,
174-
host,
175-
portToExpose,
176-
"jd",
177-
)
178-
}
179162
return o, nil
180163
}

0 commit comments

Comments
 (0)