-
Notifications
You must be signed in to change notification settings - Fork 25
feat: PG reads failover to the primary #1162
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
wojcik-dorota
merged 14 commits into
main
from
BF-3737-docs-redirect-reads-to-the-primary-if-secondary-down
Dec 2, 2025
Merged
Changes from 5 commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
9123290
reads failover to primary
wojcik-dorota 9469c38
updates
wojcik-dorota 6d4e96f
ready
wojcik-dorota cfc3711
feedback
wojcik-dorota e36b8c0
Apply suggestions from code review
wojcik-dorota d9c9a14
Apply suggestions from code review
wojcik-dorota df08856
Update pg-reads-failover-to-primary.md
wojcik-dorota 01b718d
Update docs/products/postgresql/howto/pg-reads-failover-to-primary.md
wojcik-dorota eb7395e
Remove unused ConsoleIcon import from documentation
wojcik-dorota 0685ac8
Update docs/products/postgresql/howto/pg-reads-failover-to-primary.md
wojcik-dorota 29eae3f
Update pg-reads-failover-to-primary.md
wojcik-dorota 0c9d056
Update docs/products/postgresql/howto/pg-reads-failover-to-primary.md
wojcik-dorota f793df7
Revise failover warning in PostgreSQL docs
wojcik-dorota 173a180
Update docs/products/postgresql/howto/pg-reads-failover-to-primary.md
wojcik-dorota File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
226 changes: 226 additions & 0 deletions
226
docs/products/postgresql/howto/pg-reads-failover-to-primary.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,226 @@ | ||
| --- | ||
| title: Aiven for PostgreSQL® reads failover to the primary | ||
| sidebar_label: Reads failover to primary | ||
| limited: true | ||
| --- | ||
|
|
||
| import Tabs from '@theme/Tabs'; | ||
| import TabItem from '@theme/TabItem'; | ||
| import ConsoleIcon from "@site/src/components/ConsoleIcons"; | ||
| import ConsoleLabel from "@site/src/components/ConsoleIcons"; | ||
|
|
||
| Enable automatic failover for your Aiven for PostgreSQL® read workloads to ensure uninterrupted access when standby nodes are unavailable. | ||
|
|
||
| When you route read-only queries to standby nodes, a standby failure can make your replica | ||
| URI temporarily unreachable until a new standby is provisioned and catches up. Reads | ||
| failover to the primary automatically and temporarily redirects read-only traffic to the | ||
| healthy primary node when all standbys are unavailable, helping you avoid downtime. | ||
|
|
||
| ## Benefits | ||
|
|
||
| - Improves availability for read workloads during standby outages. | ||
| - Reduces operational effort; no app-side routing changes required. | ||
| - Uses a single, stable connection endpoint for read traffic. | ||
|
|
||
| ## How it works | ||
|
|
||
| - This feature doesn't create additional replicas; it redirects read traffic when | ||
| replicas are unavailable. When enabled, your service exposes a dedicated HA replica | ||
| DNS endpoint for read-only traffic. | ||
| - Under normal conditions, this endpoint resolves to standby nodes. | ||
| - If all standbys become unavailable, the endpoint automatically switches to the primary. | ||
| - When standbys recover, the endpoint switches back to replicas. | ||
|
|
||
| ## Enable the feature | ||
|
|
||
| You can manage reads failover to the primary from the Aiven Console, CLI, API, or using | ||
| Aiven Provider for Terraform. | ||
|
|
||
| ### Prerequisites | ||
|
|
||
| - Aiven for PostgreSQL service on a [Business or Premium plan](https://aiven.io/pricing?product=pg) (see how to [change your plan](/docs/platform/howto/scale-services)) | ||
| - Tool for managing the feature: | ||
| - [Aiven Console](https://console.aiven.io/) | ||
| - [Aiven CLI](/docs/tools/cli) | ||
| - [Aiven API](/docs/tools/api) | ||
| - [Aiven Provider for Terraform](/docs/tools/terraform) | ||
| - [Aiven Operator for Kubernetes®](/docs/tools/kubernetes) | ||
| - During a failover to primary, read-only traffic is served by the primary. Ensure your | ||
| application can tolerate reads from the primary if it assumes read-after-write or | ||
| specific consistency behavior. | ||
wojcik-dorota marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| ### Use your preferred tool | ||
|
|
||
| <Tabs groupId="group1"> | ||
| <TabItem value="gui" label="Console" default> | ||
|
|
||
| 1. In the [Aiven Console](https://console.aiven.io/), open your Aiven for PostgreSQL® | ||
| service. | ||
| 1. Go to service <ConsoleLabel name="service settings"/> > **Advanced configuration**. | ||
| 1. Click **Configure** > **Add configuration option**. | ||
| 1. Use the search bar to find `enable_ha_replica_dns`, and set it to **Enabled**. | ||
| 1. Click **Save configuration**. | ||
|
|
||
| </TabItem> | ||
| <TabItem value="cli" label="CLI"> | ||
|
|
||
| Run | ||
|
|
||
| ```bash | ||
| aiven service update SERVICE_NAME -c enable_ha_replica_dns=true | ||
| ``` | ||
|
|
||
| </TabItem> | ||
| <TabItem value="api" label="API"> | ||
|
|
||
| Call the | ||
| [ServiceUpdate endpoint](https://api.aiven.io/doc/#tag/Service/operation/ServiceUpdate) | ||
| to set the `enable_ha_replica_dns` configuration to `true`: | ||
|
|
||
| ```bash {8} | ||
| curl --request PUT \ | ||
| --url https://api.aiven.io/v1/project/PROJECT_NAME/service/SERVICE_NAME \ | ||
| --header 'Authorization: Bearer BEARER_TOKEN' \ | ||
| --header 'content-type: application json' \ | ||
wojcik-dorota marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
wojcik-dorota marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| --data | ||
| '{ | ||
| "user_config": { | ||
| "enable_ha_replica_dns": true | ||
| } | ||
| }' | ||
| ``` | ||
|
|
||
| </TabItem> | ||
| <TabItem value="tf" label="Terraform"> | ||
|
|
||
| Add or update your Terraform resource for the Aiven for PostgreSQL service: | ||
|
|
||
| ```hcl {8} | ||
| resource "aiven_pg" "example" { | ||
| project = "PROJECT_NAME" | ||
| cloud_name = "CLOUD_REGION" | ||
| plan = "PLAN_NAME" | ||
| service_name = "SERVICE_NAME" | ||
|
|
||
| user_config = { | ||
| enable_ha_replica_dns = true | ||
| # ...other config options | ||
| } | ||
| } | ||
| ``` | ||
|
|
||
| </TabItem> | ||
| <TabItem value="k8s" label="Kubernetes"> | ||
|
|
||
| Add or update your Aiven Service custom resource manifest: | ||
|
|
||
| ```yaml {10} | ||
| apiVersion: aiven.io/v1alpha1 | ||
| kind: PostgreSQL | ||
| metadata: | ||
| name: SERVICE_NAME | ||
| spec: | ||
| project: PROJECT_NAME | ||
| cloudName: CLOUD_REGION | ||
| plan: PLAN_NAME | ||
| userConfig: | ||
| enable_ha_replica_dns: true | ||
| # ...other config options | ||
| ``` | ||
|
|
||
| </TabItem> | ||
| </Tabs> | ||
|
|
||
| ## Use the HA-replica-DNS endpoint | ||
|
|
||
| 1. After enabling, retrieve the replica connection URI from the console, CLI, or API. | ||
| This URI will automatically redirect to the primary when replicas are unavailable and | ||
| switch back once replicas are healthy. | ||
| 1. Point your read-only clients to this URI to benefit from automatic failover without | ||
| changing application logic. | ||
|
|
||
| Existing connections to replicas may fail during an outage. New connections using the HA replica DNS continue to succeed. | ||
wojcik-dorota marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
wojcik-dorota marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| ## Disable the feature | ||
|
|
||
| You can disable reads failover to the primary at any time. | ||
|
|
||
| <Tabs groupId="group1"> | ||
| <TabItem value="gui" label="Console" default> | ||
|
|
||
| 1. In the [Aiven Console](https://console.aiven.io/), open your Aiven for PostgreSQL® | ||
| service. | ||
| 1. Go to service <ConsoleLabel name="service settings"/> > **Advanced configuration**. | ||
| 1. Click **Configure** > **Add configuration option**. | ||
| 1. Use the search bar to find `enable_ha_replica_dns`, and set it to **Disabled**. | ||
| 1. Click **Save configuration**. | ||
|
|
||
| </TabItem> | ||
| <TabItem value="cli" label="CLI"> | ||
|
|
||
| Run | ||
|
|
||
| ```bash | ||
| aiven service update SERVICE_NAME -c enable_ha_replica_dns=false | ||
| ``` | ||
|
|
||
| </TabItem> | ||
| <TabItem value="api" label="API"> | ||
|
|
||
| Call the | ||
| [ServiceUpdate endpoint](https://api.aiven.io/doc/#tag/Service/operation/ServiceUpdate) | ||
| to set the `enable_ha_replica_dns` configuration to `false`: | ||
|
|
||
| ```bash {8} | ||
| curl --request PUT \ | ||
| --url https://api.aiven.io/v1/project/PROJECT_NAME/service/SERVICE_NAME \ | ||
| --header 'Authorization: Bearer BEARER_TOKEN' \ | ||
| --header 'content-type: application json' \ | ||
| --data | ||
| '{ | ||
| "user_config": { | ||
| "enable_ha_replica_dns": false | ||
| } | ||
| }' | ||
| ``` | ||
|
|
||
| </TabItem> | ||
| <TabItem value="tf" label="Terraform"> | ||
|
|
||
| Add or update your Terraform resource for the Aiven for PostgreSQL service: | ||
|
|
||
| ```hcl {8} | ||
| resource "aiven_pg" "example" { | ||
| project = "PROJECT_NAME" | ||
| cloud_name = "CLOUD_REGION" | ||
| plan = "PLAN_NAME" | ||
| service_name = "SERVICE_NAME" | ||
|
|
||
| user_config = { | ||
| enable_ha_replica_dns = false | ||
| # ...other config options | ||
| } | ||
| } | ||
| ``` | ||
|
|
||
| </TabItem> | ||
| <TabItem value="k8s" label="Kubernetes"> | ||
|
|
||
| Add or update your Aiven Service custom resource manifest: | ||
|
|
||
| ```yaml {10} | ||
| apiVersion: aiven.io/v1alpha1 | ||
| kind: PostgreSQL | ||
| metadata: | ||
| name: SERVICE_NAME | ||
| spec: | ||
| project: PROJECT_NAME | ||
| cloudName: CLOUD_REGION | ||
| plan: PLAN_NAME | ||
| userConfig: | ||
| enable_ha_replica_dns: false | ||
| # ...other config options | ||
| ``` | ||
|
|
||
| </TabItem> | ||
| </Tabs> | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.