New to KubeDB? Please start here.

Don’t know how to take continuous backup? Check tutorial on Continuous Archiving.

PostgreSQL Initialization

KubeDB supports PostgreSQL database initialization. When you create a new Postgres object, you can provide existing WAL files to restore from by “replaying” the log entries.

Before You Begin

At first, you need to have a Kubernetes cluster, and the kubectl command-line tool must be configured to communicate with your cluster. If you do not already have a cluster, you can create one by using minikube.

Now, install KubeDB cli on your workstation and KubeDB operator in your cluster following the steps here.

To keep things isolated, this tutorial uses a separate namespace called demo throughout this tutorial.

$ kubectl create ns demo
namespace "demo" created

$ kubectl get ns demo
demo    Active  5s

Note: Yaml files used in this tutorial are stored in docs/examples/postgres folder in github repository kubedb/cli.

Create PostgreSQL with WAL Source

You can create a new database from archived WAL files using wal-g .

Specify storage backend in the spec.init.postgresWAL field of a new Postgres object.

See the example Postgres object below

kind: Postgres
  name: replay-postgres
  namespace: demo
  version: 9.6
  replicas: 2
    secretName: wal-postgres-auth
    storageClassName: "standard"
    - ReadWriteOnce
        storage: 50Mi
      storageSecretName: s3-secret
        bucket: kubedb
      storageSecretName: s3-secret
        bucket: kubedb
        prefix: 'kubedb/demo/wal-postgres/archive'


  • spec.init.postgresWAL specifies storage information that will be used by wal-g
    • storageSecretName points to the Secret containing the credentials for cloud storage destination.
    • s3.bucket points to the bucket name used to store continuous archiving data.
    • s3.prefix points to the path where archived WAL data is stored.

wal-g receives archived WAL data from a folder called /kubedb/{namespace}/{postgres-name}/archive/.

Here, {namespace} & {postgres-name} indicates Postgres object whose WAL archived data will be replayed.

Note: Postgres replay-postgres must have same postgres superuser password as Postgres wal-postgres.

Now create this Postgres

$ kubedb create -f
validating ""
postgres "replay-postgres" created

This will create a new database with existing basebackup and will restore from archived wal files.

When this database is ready, wal-g takes a basebackup and uploads it to cloud storage defined by storage backend in spec.archiver.

Cleaning up

To cleanup the Kubernetes resources created by this tutorial, run:

$ kubedb delete pg,drmn,snap -n demo --all --force
$ kubectl delete ns demo

Next Steps