This post was originally published in 2023 and was updated in 2025.

PostgreSQL is a natural fit for modern cloud-native environments, but running it on Kubernetes can be more complicated than it looks. From provisioning to backups, there’s a lot to get right before you can start building on top of it. That’s where the Percona Operator for PostgreSQL comes in. It removes much of the manual work by automating deployment and cluster management, making it easier to get a production-ready database up and running.

A common need, especially in CI/CD pipelines, is to bootstrap clusters with data so applications can run right away. In this post, we’ll look at how to use the Percona Operator’s bootstrap features to:

  • Start a cluster with an init SQL script
  • Bootstrap a cluster from an existing cluster or backup

Getting started

You’ll need the Percona Operator for PostgreSQL deployed. Follow our installation instructions using whichever method you prefer.

You can find all examples from this post in this GitHub repository. A single command to deploy the operator would be:

Init SQL script

Init SQL lets you create a database cluster with some initial data. Everything is created with the postgres admin user. The process works like this:

  1. Create the ConfigMap resource with the SQL script. 
  2. Reference it in the PerconaPGCluster Custom Resource. 
  3. The Operator applies the SQL during cluster creation. 

This is often paired with user creation.

Example ConfigMap from 01-demo-init.yaml:

The init.sql script:

  • Connects to the demo-db database 
  • Creates schema media for user myuser 
  • Creates two tables—BLOG and AUTHORS—in the schema 

User and database creation in 02-deploy-cr.yaml:

Reference the ConfigMap in the custom resource:

Applying the manifest would do the trick:

Troubleshooting

To verify if init SQL was executed or check errors, look at the Operator’s logs. Search for init SQL. For example, the following tells me that I had a syntax error in my SQL script for demo-cluster:

Bootstrap from cluster or backup

ConfigMaps can’t store more than 1 MB of data, so init SQL is best for small bootstraps. For larger datasets, you can bootstrap from:

  • An existing cluster in Kubernetes 
  • A backup

From the cluster

You’ll need a running cluster and a pgBackRest repo configured.

03-deploy-cr2.yaml provisions demo-cluster-2. The spec.databaseInitSQL section is removed, but spec.users remains. Add the dataSource section:

The new cluster will be created once the manifest is applied:

demo-cluster-2  will have the same data as demo-cluster. Keep in mind that even if data is the same, the user passwords would be different by default. You can change this; please see users documentation.

From the backup

If the original cluster isn’t running—or is in a different Kubernetes environment—you can bootstrap from backups stored in object storage. Please use our documentation to configure backups.

Example 04-deploy-cr.yaml config for Google Cloud Storage (GCS):

Once you have backups stored in the object storage, you can delete the cluster and reference it in the manifest anytime for bootstrapping. For example, in 05-deploy-cr3.yaml, dataSource section looks like this:

The fields have the same structure and reference the same Secret resource where GCS configuration is stored.

Troubleshooting

When bootstrapping from pgBackRest, the Operator creates a restore pod. If it fails:

Check for missing files, misconfigured stanzas, or object storage issues.

Conclusion

Bootstrapping PostgreSQL clusters with the Percona Operator saves significant time, whether you’re initializing with SQL, cloning from an existing cluster, or restoring from backups. It also fits neatly into CI/CD pipelines, letting teams automate provisioning, updates, and rollbacks with fewer risks and less downtime.

If you want to go further, we’ve put together a resource that shows how Percona makes PostgreSQL on Kubernetes easier. It covers high availability, observability, automation, and more, so you can run PostgreSQL at scale with confidence.

 

Discover how Percona simplifies PostgreSQL on Kubernetes

Subscribe
Notify of
guest

0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments