|
| 1 | +--- |
| 2 | +icon: material/arrow-expand-all |
| 3 | +--- |
| 4 | + |
| 5 | +# Autoscaling |
| 6 | + |
| 7 | +Autoscaling automatically adjusts PgDog settings when the number of processes (e.g. pods in Kubernetes) in the same deployment changes. This simplifies configuration: you no longer need to perform manual calculations to resize connection pools. |
| 8 | + |
| 9 | +## Configuration |
| 10 | + |
| 11 | +Autoscaling is **disabled** by default. To enable it, add the following settings to the [control plane](../installation.md) Helm [chart](https://github.com/pgdogdev/helm-ee): |
| 12 | + |
| 13 | +```yaml title="values.yaml" |
| 14 | +control: |
| 15 | + config: |
| 16 | + autoscaling: |
| 17 | + pool_size: true |
| 18 | +``` |
| 19 | +
|
| 20 | +## How it works |
| 21 | +
|
| 22 | +When a PgDog process connects to the [control plane](../../control_plane/index.md), the control plane provides it with the total number of processes that are part of the same deployment. PgDog then automatically adjusts its configuration by dividing all pool-related configuration values by that number, for example: |
| 23 | +
|
| 24 | +=== "Configuration" |
| 25 | + ```toml title="pgdog.toml" |
| 26 | + [general] |
| 27 | + default_pool_size = 200 |
| 28 | + |
| 29 | + [[databases]] |
| 30 | + name = "prod" |
| 31 | + host = "10.0.0.1" |
| 32 | + min_pool_size = 50 |
| 33 | + ``` |
| 34 | + |
| 35 | + ```toml title="users.toml" |
| 36 | + [[users]] |
| 37 | + name = "postgres" |
| 38 | + database = "prod" |
| 39 | + pool_size = 100 |
| 40 | + ``` |
| 41 | + |
| 42 | +=== "2 processes" |
| 43 | + ```toml title="pgdog.toml" |
| 44 | + [general] |
| 45 | + default_pool_size = 100 |
| 46 | +
|
| 47 | + [[databases]] |
| 48 | + name = "prod" |
| 49 | + host = "10.0.0.1" |
| 50 | + min_pool_size = 25 |
| 51 | + ``` |
| 52 | + |
| 53 | + ```toml title="users.toml" |
| 54 | + [[users]] |
| 55 | + name = "postgres" |
| 56 | + database = "prod" |
| 57 | + pool_size = 50 |
| 58 | + ``` |
| 59 | + |
| 60 | +=== "4 processes" |
| 61 | + ```toml title="pgdog.toml" |
| 62 | + [general] |
| 63 | + default_pool_size = 50 |
| 64 | +
|
| 65 | + [[databases]] |
| 66 | + name = "prod" |
| 67 | + host = "10.0.0.1" |
| 68 | + min_pool_size = 12 |
| 69 | + ``` |
| 70 | + |
| 71 | + ```toml title="users.toml" |
| 72 | + [[users]] |
| 73 | + name = "postgres" |
| 74 | + database = "prod" |
| 75 | + pool_size = 25 |
| 76 | + ``` |
| 77 | + |
| 78 | +=== "8 processes" |
| 79 | + ```toml title="pgdog.toml" |
| 80 | + [general] |
| 81 | + default_pool_size = 25 |
| 82 | +
|
| 83 | + [[databases]] |
| 84 | + name = "prod" |
| 85 | + host = "10.0.0.1" |
| 86 | + min_pool_size = 6 |
| 87 | + ``` |
| 88 | + |
| 89 | + ```toml title="users.toml" |
| 90 | + [[users]] |
| 91 | + name = "postgres" |
| 92 | + database = "prod" |
| 93 | + pool_size = 12 |
| 94 | + ``` |
| 95 | + |
| 96 | +### Supported settings |
| 97 | + |
| 98 | +The following configuration options are supported for pool size autoscaling: |
| 99 | + |
| 100 | +| Section | Configuration | |
| 101 | +|-|-| |
| 102 | +| [`[general]`](../../../configuration/pgdog.toml/general.md) | [`default_pool_size`](../../../configuration/pgdog.toml/general.md#default_pool_size) (alias: `max_pool_size`) | |
| 103 | +| [`[general]`](../../../configuration/pgdog.toml/general.md) | [`min_pool_size`](../../../configuration/pgdog.toml/general.md#min_pool_size) | |
| 104 | +| [`[[databases]]`](../../../configuration/pgdog.toml/databases.md) | [`pool_size`](../../../configuration/pgdog.toml/databases.md#pool_size) | |
| 105 | +| [`[[databases]]`](../../../configuration/pgdog.toml/databases.md) | [`min_pool_size`](../../../configuration/pgdog.toml/databases.md#min_pool_size) | |
| 106 | +| [`[[users]]`](../../../configuration/users.toml/users.md) | [`pool_size`](../../../configuration/users.toml/users.md#pool_size) | |
| 107 | +| [`[[users]]`](../../../configuration/users.toml/users.md) | [`min_pool_size`](../../../configuration/users.toml/users.md#min_pool_size) | |
| 108 | + |
| 109 | +## Orchestrator integration |
| 110 | + |
| 111 | +Autoscaling actions are performed entirely using the internal PgDog <-> control plane protocol and, therefore, will work with all orchestrators, including Kubernetes, ECS, and manual deployments. |
| 112 | + |
| 113 | +### Kubernetes |
| 114 | + |
| 115 | +If using autoscaling and deploying PgDog with our [Helm chart](../../../installation.md), make sure to set the pool-related settings to reflect the _total_ number of connections. For example, if deploying 3 replicas and the total pool size across the 3 pods is 600 connections, set it accordingly in `values.yaml`: |
| 116 | + |
| 117 | +```yaml title="values.yaml" |
| 118 | +defaultPoolSize: 600 |
| 119 | +replicas: 3 |
| 120 | +
|
| 121 | +users: |
| 122 | + - name: "postgres" |
| 123 | + database: "prod" |
| 124 | + minPoolSize: 300 # 50% of the pool |
| 125 | +``` |
| 126 | + |
| 127 | +When PgDog pods are started, they will connect to the control plane and automatically adjust the pool settings to reflect the total number of pods in the deployment: |
| 128 | + |
| 129 | +| Configuration | Value | Autoscaled value | |
| 130 | +|-|-|-| |
| 131 | +| `defaultPoolSize` | `600` | `200` | |
| 132 | +| `minPoolSize` | `300` | `100` | |
| 133 | + |
| 134 | +!!! note "Automatic adjustment" |
| 135 | + The configuration adjustment happens inside the PgDog process. The control plane does not |
| 136 | + mutate the `ConfigMap` resource, so GitOps tools like ArgoCD will not detect this drift |
| 137 | + and continue to operate normally. |
0 commit comments