Skip to content

Commit 31ed6b4

Browse files
committed
Added pg_qualstats extension
Signed-off-by: Kristiansen, Erling Gustav Moland <Erling.Kristiansen@skatteetaten.no>
1 parent 0505da2 commit 31ed6b4

File tree

3 files changed

+160
-0
lines changed

3 files changed

+160
-0
lines changed

pg-qualstats/Dockerfile

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# SPDX-FileCopyrightText: Copyright © contributors to CloudNativePG, established as CloudNativePG a Series of LF Projects, LLC.
2+
# SPDX-License-Identifier: Apache-2.0
3+
4+
ARG BASE=ghcr.io/cloudnative-pg/postgresql:18-minimal-trixie
5+
FROM $BASE AS builder
6+
7+
ARG PG_MAJOR
8+
ARG EXT_VERSION
9+
10+
USER 0
11+
12+
# Install extension via `apt-get`
13+
RUN apt-get update && apt-get install -y --no-install-recommends \
14+
"postgresql-${PG_MAJOR}-pg-qualstats=${EXT_VERSION}"
15+
16+
FROM scratch
17+
ARG PG_MAJOR
18+
19+
# Licenses
20+
COPY --from=builder /usr/share/doc/postgresql-${PG_MAJOR}-pg-qualstats/copyright /licenses/postgresql-${PG_MAJOR}-pg-qualstats/
21+
22+
# Libraries
23+
COPY --from=builder /usr/lib/postgresql/${PG_MAJOR}/lib/pg_qualstats* /lib/
24+
COPY --from=builder /usr/lib/postgresql/${PG_MAJOR}/lib/bitcode/ /lib/bitcode/
25+
26+
# Share
27+
COPY --from=builder /usr/share/postgresql/${PG_MAJOR}/extension/pg_qualstats* /share/extension/
28+
29+
USER 65532:65532

pg-qualstats/README.md

Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
# pg_qualstats
2+
<!--
3+
SPDX-FileCopyrightText: Copyright © contributors to CloudNativePG, established as CloudNativePG a Series of LF Projects, LLC.
4+
SPDX-License-Identifier: Apache-2.0
5+
-->
6+
7+
[pg_qualstats](https://github.com/powa-team/pg_qualstats) is a PostgreSQL
8+
extension that collects statistics about predicates (quals) found in
9+
`WHERE` clauses and `JOIN` conditions. It can be used to identify missing
10+
indexes and understand query workload patterns. For more information, see the
11+
[official documentation](https://powa.readthedocs.io/en/latest/components/pg_qualstats.html).
12+
13+
## Usage
14+
15+
The `pg_qualstats` extension must be loaded via `shared_preload_libraries`
16+
to hook into the query executor and collect predicate statistics.
17+
18+
### 1. Add the pg_qualstats extension image to your Cluster
19+
20+
Define the `pg-qualstats` extension under the `postgresql.extensions` section
21+
of your `Cluster` resource. For example:
22+
23+
```yaml
24+
apiVersion: postgresql.cnpg.io/v1
25+
kind: Cluster
26+
metadata:
27+
name: cluster-pg-qualstats
28+
spec:
29+
imageName: ghcr.io/cloudnative-pg/postgresql:18-minimal-trixie
30+
instances: 1
31+
32+
storage:
33+
size: 1Gi
34+
35+
postgresql:
36+
shared_preload_libraries:
37+
- pg_qualstats
38+
extensions:
39+
- name: pg-qualstats
40+
image:
41+
# renovate: suite=trixie-pgdg depName=postgresql-18-pg-qualstats
42+
reference: ghcr.io/cloudnative-pg/pg-qualstats:2.1.3-18-trixie
43+
```
44+
45+
### 2. Enable the extension in a database
46+
47+
You can install `pg_qualstats` in a specific database by creating or updating a
48+
`Database` resource. For example, to enable it in the `app` database:
49+
50+
```yaml
51+
apiVersion: postgresql.cnpg.io/v1
52+
kind: Database
53+
metadata:
54+
name: cluster-pg-qualstats-app
55+
spec:
56+
name: app
57+
owner: app
58+
cluster:
59+
name: cluster-pg-qualstats
60+
extensions:
61+
- name: pg_qualstats
62+
# renovate: suite=trixie-pgdg depName=postgresql-18-pg-qualstats
63+
version: '2.1.3'
64+
```
65+
66+
### 3. Verify installation
67+
68+
Once the database is ready, connect to it with `psql` and run:
69+
70+
```sql
71+
\dx
72+
```
73+
74+
You should see `pg_qualstats` listed among the installed extensions.
75+
76+
## Contributors
77+
78+
This extension is maintained by:
79+
80+
- Erling Kristiansen (@egkristi)
81+
82+
The maintainers are responsible for:
83+
84+
- Monitoring upstream releases and security vulnerabilities.
85+
- Ensuring compatibility with supported PostgreSQL versions.
86+
- Reviewing and merging contributions specific to this extension's container
87+
image and lifecycle.
88+
89+
---
90+
91+
## Licenses and Copyright
92+
93+
This container image contains software that may be licensed under various
94+
open-source licenses.
95+
96+
All relevant license and copyright information for the `pg_qualstats` extension
97+
and its dependencies are bundled within the image at:
98+
99+
```text
100+
/licenses/
101+
```
102+
103+
By using this image, you agree to comply with the terms of the licenses
104+
contained therein.

pg-qualstats/metadata.hcl

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# SPDX-FileCopyrightText: Copyright © contributors to CloudNativePG, established as CloudNativePG a Series of LF Projects, LLC.
2+
# SPDX-License-Identifier: Apache-2.0
3+
metadata = {
4+
name = "pg-qualstats"
5+
sql_name = "pg_qualstats"
6+
image_name = "pg-qualstats"
7+
licenses = ["PostgreSQL"]
8+
shared_preload_libraries = ["pg_qualstats"]
9+
extension_control_path = []
10+
dynamic_library_path = []
11+
ld_library_path = []
12+
bin_path = []
13+
auto_update_os_libs = false
14+
required_extensions = []
15+
create_extension = true
16+
17+
versions = {
18+
bookworm = {
19+
// renovate: suite=bookworm-pgdg depName=postgresql-18-pg-qualstats
20+
"18" = "2.1.3-1.pgdg12+1"
21+
}
22+
trixie = {
23+
// renovate: suite=trixie-pgdg depName=postgresql-18-pg-qualstats
24+
"18" = "2.1.3-1.pgdg13+1"
25+
}
26+
}
27+
}

0 commit comments

Comments
 (0)