Configuring a High Availability PostgreSQL Cluster
TOC
Overview
This guide explains how to configure a highly available PostgreSQL cluster on Kubernetes, using Patroni for automated failover and cluster management, with support for synchronous replication, connection pooling, monitoring and more.
Prerequisites
- PostgreSQL Operator must be installed
- A storage class supporting dynamic provisioning must be configured
- Permissions to create CRD resources must be granted
- Ensure the Kubernetes cluster has sufficient resources (at least 3 available nodes)
- Backup storage must be configured (S3 or compatible storage)
Procedure
1. Create a High Availability Cluster
2. Verify Cluster Status
Example Output:
3. Configure Connection Pooler (Optional)
4. Configure Monitoring (Optional)
Key Parameters
Cluster Configuration
Patroni Configuration
Backup Configuration
Result Validation
- Verify cluster status is Running
- Confirm all Pods are running normally
- Check Patroni status:
- Test failover:
Observe new leader election process
- Verify synchronous replication status:
Best Practices
- For production environments, use SSD storage with appropriate IOPS configuration
- Configure resource limits with 20-30% buffer
- Regularly test failover and recovery procedures
- Configure monitoring alerts for:
- Primary-replica lag
- Connection counts
- Disk usage
- CPU/memory usage
- Enable scheduled backups and test restore procedures
- When using synchronous replication, configure at least 2 synchronous replicas
- Perform regular performance tuning and parameter optimization