Skip to content

Commit 5afab5a

Browse files
authored
feat: document query plans (#81)
1 parent 9496f9a commit 5afab5a

3 files changed

Lines changed: 85 additions & 7 deletions

File tree

docs/enterprise_edition/index.md

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ The following features are available exclusively in the Enterprise edition:
1616
|-|-|
1717
| [Control plane](control_plane/index.md) (beta) | Manage multiple PgDog nodes and deployments. |
1818
| Queries | Monitor queries running through PgDog in real-time. |
19-
| Plans | Request and track Postgres query plans for slow queries. |
19+
| [Plans](plans.md) | Request and track Postgres query plans for slow queries. |
2020
| Metrics | Second-precision PgDog and resource usage metrics. |
2121
| [Quality of Service](qos.md) (alpha) | Track and block bad queries automatically. |
2222

@@ -69,12 +69,7 @@ image:
6969
7070
#### Control plane
7171
72-
The [control plane](control_plane/index.md) comes with its own [Helm chart](control_plane/installation.md). The chart has a few cluster dependencies, which you can check using our installation script:
73-
74-
```bash
75-
curl -fsSL \
76-
https://raw.githubusercontent.com/pgdogdev/helm-ee/main/install.sh | bash
77-
```
72+
The [control plane](control_plane/index.md) comes with its own [Helm chart](control_plane/installation.md).
7873
7974
### From source
8075

docs/enterprise_edition/plans.md

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
---
2+
icon: material/file-tree
3+
---
4+
5+
# Query plans
6+
7+
Slow queries are difficult to debug in production. Postgres can generate a query plan for a specific statement, but the exact parameters that caused a bad plan are often unavailable.
8+
9+
PgDog can automatically request and store query plans for slow queries as it serves them. Because plans are fetched in real time, they are more likely to capture the bad execution plan before Postgres autovacuum changes the underlying statistics.
10+
11+
## How it works
12+
13+
Query plan collection is disabled by default and can be enabled in `pgdog.toml`:
14+
15+
=== "pgdog.toml"
16+
```toml
17+
[query_stats]
18+
enabled = true
19+
query_plan_threshold = 100 # Queries slower than 100ms will be planned.
20+
```
21+
=== "Helm chart"
22+
```yaml
23+
queryStats:
24+
enabled: true
25+
queryPlanThreshold: 100
26+
```
27+
28+
The plans are stored in memory and deduplicated by _normalized_ SQL of the query. This means that queries with different parameters will be tied to the same query plan, making sure PgDog doesn't plan the same query multiple times.
29+
30+
### Configuration
31+
32+
The query plan cache is configurable:
33+
34+
| Argument | Description | Example |
35+
|-|-|-|
36+
| `query_plan_threshold` | Minimum query runtime that triggers a query plan (in ms). | `100` |
37+
| `query_plans_sample_rate` | Percentage of all queries executed through PgDog that will be planned, irrespective of their runtime (between 0.0 and 1.0). | `0.5` |
38+
| `query_plans_cache` | Maximum number of entries in the in-memory plan cache. | `500` |
39+
| `query_plan_max_age` | Query plans older than this are considered stale and will be replanned if the query is executed again (in ms). | `15_000` |
40+
41+
##### Example
42+
43+
=== "pgdog.toml"
44+
```toml
45+
[query_stats]
46+
enabled = true
47+
query_plan_threshold = 100
48+
query_plans_sample_rate = 0.5
49+
query_plans_cache = 1_000
50+
query_plan_max_age = 15_000
51+
```
52+
=== "Helm chart"
53+
```yaml
54+
queryStats:
55+
enabled: true
56+
queryPlanThreshold: 100
57+
queryPlansSampleRate: 0.5
58+
queryPlansCache: 1000
59+
queryPlanMaxAge: 15000
60+
```
61+
62+
### Admin database
63+
64+
The query plans are viewable by querying the [admin database](../administration/index.md) with the `SHOW QUERY_PLANS` command:
65+
66+
=== "Command"
67+
```
68+
SHOW QUERY_PLANS;
69+
```
70+
=== "Output"
71+
```
72+
query | plan | database | user | age | reason
73+
----------------------+------------------------------------------+----------+-------+-------+-----------
74+
select pg_sleep($1); | Result (cost=0.00..0.01 rows=1 width=4) | pgdog | pgdog | 48810 | threshold
75+
```
76+
77+
### Control plane
78+
79+
The query plans are joined with live queries and are sent to the [control plane](control_plane/index.md). They are viewable in the control plane UI and are updated in real time:
80+
81+
<center>
82+
<img src="/images/ee/plans.png" width="100%" alt="Control plane">
83+
</center>

docs/images/ee/plans.png

171 KB
Loading

0 commit comments

Comments
 (0)