Disaster Recovery for PostgreSQL on Kubernetes: Simplifying Business Continuity

Introduction: In the digital age, businesses cannot afford to overlook the importance of disaster recovery. With increasing reliance on data, system outages or data loss can have catastrophic consequences, leading to significant disruptions and financial losses. When it comes to running PostgreSQL on Kubernetes, implementing a robust disaster recovery strategy is crucial to ensure the availability and security of critical data. In this article, we will delve into the details of implementing disaster recovery using the Percona Operator for PostgreSQL version 2, providing businesses with the peace of mind that their data is protected and recoverable, regardless of the circumstances.

Overview of the Solution: The Percona Operator simplifies disaster recovery for PostgreSQL clusters running on Kubernetes, particularly in multi-cloud or hybrid-cloud deployments. It offers various options for standby configurations, including pgBackrest repo-based standby, streaming replication, or a combination of both. In this article, we will focus on the repo-based standby option, which is the simplest approach.

Key Steps:

  1. Two Kubernetes clusters: Set up two Kubernetes clusters, one designated as the “Main” site and the other as the “Disaster Recovery” (DR) site. These clusters can be in different regions, clouds, or a combination of on-premises and cloud environments.
  2. Components in each cluster: Each cluster should include the following components:
    • Percona Operator: Deploy the Percona Operator in each cluster to manage the PostgreSQL clusters.
    • PostgreSQL cluster: Set up the PostgreSQL cluster within each Kubernetes cluster.
    • pgBackrest: Configure pgBackrest in the Main site to stream backups and Write Ahead Logs (WALs) to the object storage.
    • pgBouncer: Implement pgBouncer, a connection pooler, to optimize database connections.
  3. Configuration of the Main site: Install and configure the Percona Operator in the Main site. Customize the Custom Resource manifest to specify the Object Storage for pgBackrest. Configure the backups.pgbackrest.repos section to define the necessary settings for the chosen object storage provider.
  4. Configuration of the DR site: Set up the DR site with similar components as the Main site, including the Percona Operator, PostgreSQL cluster, pgBackrest, and pgBouncer. Configure the standby.enabled option to true and specify the repoName where backups are stored.
  5. Failover: In the event of a failure at the Main site, you can promote the standby cluster to become the primary cluster. This allows writing to the cluster and ensures the continuous flow of Write Ahead Logs (WALs) to the pgBackrest repository. However, it is crucial to avoid a split-brain situation where two primary instances attempt to write to the same repository. To prevent this, ensure that the primary cluster is either deleted or shut down before promoting the standby cluster.
  6. Automation and Monitoring: Automated failover and monitoring play key roles in disaster recovery. Implement mechanisms to detect failures and trigger failover procedures. This can involve setting up a third site for monitoring both the Main and DR sites to ensure accurate detection of failures. Additionally, consider automating traffic switching from the Main site to the Standby site after promotion, using options such as a Global Load Balancer or multi-cluster services.


Implementing a robust disaster recovery strategy is essential for businesses running PostgreSQL on Kubernetes. The Percona Operator simplifies the process and enables multi-cloud or hybrid-cloud deployments, ensuring high availability and business continuity. By following best practices and leveraging the capabilities of Kubernetes and the Percona Operator, businesses can design an effective disaster recovery plan that protects their vital processes and applications. With disaster recovery in place, businesses can operate with confidence, knowing that their PostgreSQL clusters are resilient, secure, and capable

About Shiv Iyer 422 Articles
Open Source Database Systems Engineer with a deep understanding of Optimizer Internals, Performance Engineering, Scalability and Data SRE. Shiv currently is the Founder, Investor, Board Member and CEO of multiple Database Systems Infrastructure Operations companies in the Transaction Processing Computing and ColumnStores ecosystem. He is also a frequent speaker in open source software conferences globally.