Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
113 changes: 113 additions & 0 deletions docs/enterprise_edition/autodiscovery.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
---
icon: material/database-eye
---

# Automatic database discovery

When deployed in front of AWS Aurora databases, PgDog can automatically detect the cluster instances and configure them in `pgdog.toml`. This is useful when Aurora uses replica autoscaling, which can add or remove instances at any time.

## How it works

This feature is **disabled** by default. To enable it, add at least one Aurora host to `pgdog.toml` and enable autodiscovery:

=== "pgdog.toml"
```toml
[[databases]]
name = "postgres"
host = "any-instance.account-id.region.rds.amazonaws.com"

[autodiscovery]
enabled = true
```
=== "Helm chart"
```yaml
databases:
- name: "postgres"
host: "any-instance.account-id.region.rds.amazonaws.com"
autodiscovery:
enabled: true
```

When enabled, PgDog connects to the first available host for each database in the configuration and runs the [`aurora_replica_status()`](https://docs.aws.amazon.com/AmazonRDS/latest/AuroraUserGuide/aurora_replica_status.html) function to get the list of instances in the cluster.

PgDog then replaces all entries in `pgdog.toml` with the discovered hosts and reloads its configuration automatically.

### Autoscaling events

To keep the list of databases in sync with Aurora autoscaling events, PgDog periodically queries the first available host in its config and runs the replica discovery function again.

If the list of databases has changed, PgDog updates its config and reloads it. The interval for this check is configurable:

=== "pgdog.toml"
```toml
[autodiscovery]
enabled = true
check_interval = 5_000
```

=== "Helm chart"
```yaml
autodiscovery:
enabled: true
checkInterval: 5000
```

### Filtering databases

When enabled, autodiscovery runs for all databases in `pgdog.toml` by default. If some of your databases are not running on Aurora, or you want autodiscovery on some databases but not others, you can configure which ones it applies to:

=== "pgdog.toml"
```toml
[[databases]]
name = "postgres"
host = "any-instance.account-id.region.rds.amazonaws.com"

[[databases]]
name = "staging"
host = "not-aurora.account-id.region.rds.amazonaws.com"

[autodiscovery]
enabled = true

[[autodiscovery.databases]]
name = "postgres"
```
=== "Helm chart"
```yaml
databases:
- name: "postgres"
host: "any-instance.account-id.region.rds.amazonaws.com"
- name: "staging"
host: "not-aurora.account-id.region.rds.amazonaws.com"
autodiscovery:
enabled: true
databases:
- name: "postgres"
```

In this example, only the `postgres` database will have autodiscovery enabled.

!!! note "Configuring databases"
If you specify the `[[autodiscovery.databases]]` config, any database _not_ listed there will
not have autodiscovery enabled.

### Replicas only

If you're not using the read/write separation (single endpoint) feature of the [load balancer](../features/load-balancer/index.md#single-endpoint), you may want to configure read and write connection pools separately.

To exclude the writer instance from host discovery for a read-only connection pool, set `replicas_only` in the autodiscovery database settings:

=== "pgdog.toml"
```toml
[[autodiscovery.databases]]
name = "prod_readonly"
replicas_only = true
```

=== "Helm chart"
```yaml
autodiscovery:
databases:
- name: "postgres"
replicasOnly: true
```
6 changes: 6 additions & 0 deletions docs/features/transaction-mode.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ Transaction mode is **enabled** by default. This is controllable via configurati
[general]
pooler_mode = "transaction"
```
<br>
```yaml title="Helm chart"
poolerMode: transaction
```
Expand All @@ -37,6 +38,7 @@ Transaction mode is **enabled** by default. This is controllable via configurati
host = "127.0.0.1"
pooler_mode = "transaction"
```
<br>
```yaml title="Helm chart"
databases:
- name: prod
Expand All @@ -50,6 +52,7 @@ Transaction mode is **enabled** by default. This is controllable via configurati
database = "prod"
pooler_mode = "transaction"
```
<br>
```yaml title="Helm chart"
users:
- name: alice
Expand Down Expand Up @@ -145,6 +148,7 @@ To use statement mode, you can configure it globally or per user/database, for e
[general]
pooler_mode = "statement"
```
<br>
```yaml title="Helm chart"
poolerMode: statement
```
Expand All @@ -155,6 +159,7 @@ To use statement mode, you can configure it globally or per user/database, for e
host = "127.0.0.1"
pooler_mode = "statement"
```
<br>
```yaml title="Helm chart"
databases:
- name: prod
Expand All @@ -168,6 +173,7 @@ To use statement mode, you can configure it globally or per user/database, for e
database = "prod"
pooler_mode = "statement"
```
<br>
```yaml title="Helm chart"
users:
- name: alice
Expand Down
Binary file added docs/images/logo-blue-64x64.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Loading