Skip to content

Commit eb29b3e

Browse files
committed
Add pg_stat_statements
1 parent 3c56d04 commit eb29b3e

5 files changed

Lines changed: 56 additions & 0 deletions

File tree

charts/cluster/templates/_bootstrap.tpl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ bootstrap:
2020
{{- else if eq .Values.type "timescaledb" }}
2121
- CREATE EXTENSION IF NOT EXISTS timescaledb;
2222
{{- end }}
23+
- CREATE EXTENSION IF NOT EXISTS pg_stat_statements;
2324
{{- with .Values.cluster.initdb }}
2425
{{- range .postInitApplicationSQL }}
2526
{{- printf "- %s" . | nindent 6 }}

charts/cluster/templates/cluster.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ spec:
7373
{{- if eq .Values.type "timescaledb" }}
7474
- timescaledb
7575
{{- end }}
76+
- pg_stat_statements
7677
{{- with .Values.cluster.postgresql.shared_preload_libraries }}
7778
{{- toYaml . | nindent 6 }}
7879
{{- end }}
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
{{- if .Values.cluster.monitoring.instrumentation.pgStatStatements }}
2+
apiVersion: v1
3+
kind: ConfigMap
4+
metadata:
5+
name: {{ include "cluster.fullname" . }}-monitoring-pg-stat-statements
6+
namespace: {{ include "cluster.namespace" . }}
7+
labels:
8+
cnpg.io/reload: ""
9+
{{- include "cluster.labels" . | nindent 4 }}
10+
data:
11+
custom-queries: |
12+
pg_stat_statements:
13+
query: |
14+
SELECT d.datname
15+
, sum(s.calls) AS calls
16+
, sum(s.total_exec_time) / 1000 AS total_exec_time_seconds
17+
, sum(s.rows) AS rows
18+
, sum(s.shared_blks_hit) AS shared_blks_hit
19+
, sum(s.shared_blks_read) AS shared_blks_read
20+
, sum(s.blk_read_time) / 1000 AS blk_read_time_seconds
21+
, sum(s.blk_write_time) / 1000 AS blk_write_time_seconds
22+
FROM pg_stat_statements s
23+
JOIN pg_database d ON s.dbid = d.oid
24+
GROUP BY d.datname;
25+
target_databases: ["*"]
26+
predicate_query: "SELECT 1 FROM pg_extension WHERE extname = 'pg_stat_statements';"
27+
metrics:
28+
- datname:
29+
description: Name of the database
30+
usage: LABEL
31+
- calls:
32+
description: Total number of query executions
33+
usage: COUNTER
34+
- total_exec_time_seconds:
35+
description: Total execution time in seconds
36+
usage: COUNTER
37+
- rows:
38+
description: Total number of rows returned or affected
39+
usage: COUNTER
40+
- shared_blks_hit:
41+
description: Total number of shared block cache hits
42+
usage: COUNTER
43+
- shared_blks_read:
44+
description: Total number of shared blocks read from disk
45+
usage: COUNTER
46+
- blk_read_time_seconds:
47+
description: Total block read time in seconds
48+
usage: COUNTER
49+
- blk_write_time_seconds:
50+
description: Total block write time in seconds
51+
usage: COUNTER
52+
{{- end }}

charts/cluster/test/postgresql-cluster-configuration/01-non_default_configuration_cluster-assert.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ spec:
2929
pg_ident:
3030
- mymap /^(.*)@mydomain\.com$ \1
3131
shared_preload_libraries:
32+
- pg_stat_statements
3233
- pgaudit
3334
synchronous:
3435
method: any

charts/cluster/test/postgresql-cluster-configuration/01-non_default_configuration_cluster.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,7 @@ cluster:
104104
pg_ident:
105105
- mymap /^(.*)@mydomain\.com$ \1
106106
shared_preload_libraries:
107+
- pg_stat_statements
107108
- pgaudit
108109
synchronous:
109110
method: any

0 commit comments

Comments
 (0)