Skip to content
Docs

This guide restores a PostgreSQLInstance from an RDS snapshot. You point the instance at the snapshot with spec.snapshotIdentifier, and the platform replaces the RDS instance with a new one created from that snapshot.

There are two ways to restore:

  • Option A keeps the Kubernetes objects and only replaces the RDS instance. Users, databases and their Secrets stay as they are.
  • Option B deletes everything and creates the objects again from scratch. Role passwords are reset automatically.

Both options start from the same test scenario, so you can try the restore before you need it.

Restoring uses the same APIs as creating an instance. Your Infralib configuration needs:

Module Flag Default What it does
platform-apis platform-apis.postgresql.install true Installs the PostgreSQLInstance, PostgreSQLUser and PostgreSQLDatabase APIs.
crossplane-aws global.createObservers, global.createNamespacedObservers false Installs the RDS and EC2 providers and the VPC lookups the instance needs. Set both to true.
crossplane-sql — — Creates users and databases inside the instance. Add the module to the argocd-apps step.

See Create a PostgreSQL Instance for how these resources work. For the base modules every platform API needs, see Infralib Requirements.

You also need the AWS CLI with access to the account, to check that the snapshot exists.

Create an instance with two roles. test-owner owns the database database-two-test but cannot log in. test-user can log in and is granted the test_owner role, so it can use the database.

apiVersion: database.entigo.com/v1alpha1
kind: PostgreSQLInstance
metadata:
name: postgresql-instance-test
spec:
deletionProtection: false
engineVersion: '17.10'
instanceType: db.t3.micro
---
apiVersion: database.entigo.com/v1alpha1
kind: PostgreSQLUser
metadata:
name: test-owner
spec:
instanceRef:
name: postgresql-instance-test
login: false
name: test_owner
---
apiVersion: database.entigo.com/v1alpha1
kind: PostgreSQLUser
metadata:
name: test-user
spec:
grant:
roles:
- test_owner
instanceRef:
name: postgresql-instance-test
login: true
---
apiVersion: database.entigo.com/v1alpha1
kind: PostgreSQLDatabase
metadata:
name: database-two-test
spec:
instanceRef:
name: postgresql-instance-test
owner: test_owner

Start a Pod with the test-user credentials:

apiVersion: v1
kind: Pod
metadata:
name: postgres
spec:
terminationGracePeriodSeconds: 1
containers:
- name: postgres
image: postgres:alpine
command: ['sleep', 'infinity']
env:
- name: PGHOST
valueFrom:
secretKeyRef:
name: postgresql-instance-test-test-user
key: endpoint
- name: PGPORT
valueFrom:
secretKeyRef:
name: postgresql-instance-test-test-user
key: port
- name: PGUSER
valueFrom:
secretKeyRef:
name: postgresql-instance-test-test-user
key: username
- name: PGPASSWORD
valueFrom:
secretKeyRef:
name: postgresql-instance-test-test-user
key: password
- name: PGSSLMODE
value: 'require'

Connect to the database from the Pod:

Terminal window
kubectl exec -it postgres -- bash
psql database-two-test

Insert example data:

CREATE TABLE IF NOT EXISTS example (
id SERIAL PRIMARY KEY,
name VARCHAR(100) NOT NULL,
email VARCHAR(255) UNIQUE NOT NULL,
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
);
INSERT INTO example (name, email) VALUES
('Alice Johnson', 'alice@example.com'),
('Bob Smith', 'bob@example.com'),
('Carol White', 'carol@example.com');
SELECT * FROM example;

The data is present:

id | name | email | created_at
----+---------------+-------------------+----------------------------
1 | Alice Johnson | alice@example.com | 2026-03-10 14:02:12.007906
2 | Bob Smith | bob@example.com | 2026-03-10 14:02:12.007906
3 | Carol White | carol@example.com | 2026-03-10 14:02:12.007906
(3 rows)

Create a snapshot of the instance named test-restoration and check that it exists:

Terminal window
aws rds describe-db-snapshots --no-paginate --query "DBSnapshots[].[DBSnapshotIdentifier]" --output table --region eu-north-1
# Shows test-restoration

Remove the test Pod:

Terminal window
kubectl delete pod postgres

The Kubernetes objects are kept. Only the RDS instance is replaced with one restored from the snapshot.

snapshotIdentifier cannot be changed while deletionProtection is enabled. Turn it off first:

Terminal window
kubectl patch pginstances.database.entigo.com postgresql-instance-test --type=merge -p '{"spec":{"deletionProtection":false}}'

Set spec.snapshotIdentifier to the snapshot ID:

Terminal window
kubectl patch pginstances.database.entigo.com postgresql-instance-test --type=merge -p '{"spec":{"snapshotIdentifier":"test-restoration"}}'

The platform creates a new RDS instance from the snapshot. Watch it until READY is True:

Terminal window
kubectl get instances.rds.aws.m.upbound.io -w -l crossplane.io/composite=postgresql-instance-test
#NAME SYNCED READY EXTERNAL-NAME AGE
#postgresql-instance-test-instance-338f591f True False 9s

Continue with Verify.

3. Option B: Restore the instance and recreate the objects

Section titled “3. Option B: Restore the instance and recreate the objects”

The Kubernetes objects and the RDS instance are deleted, and everything is created again from scratch. The role passwords are reset automatically.

Delete the database resources:

Terminal window
kubectl delete postgresqldatabases.database.entigo.com database-two-test
kubectl delete postgresqlusers.database.entigo.com test-user
kubectl delete postgresqlusers.database.entigo.com test-owner
kubectl delete pginstances.database.entigo.com postgresql-instance-test

Create the objects again, with spec.snapshotIdentifier set to the snapshot ID:

apiVersion: database.entigo.com/v1alpha1
kind: PostgreSQLInstance
metadata:
name: postgresql-instance-test
spec:
deletionProtection: false
engineVersion: '17.10'
instanceType: db.t3.micro
snapshotIdentifier: test-restoration
---
apiVersion: database.entigo.com/v1alpha1
kind: PostgreSQLUser
metadata:
name: test-owner
spec:
instanceRef:
name: postgresql-instance-test
login: false
name: test_owner
---
apiVersion: database.entigo.com/v1alpha1
kind: PostgreSQLUser
metadata:
name: test-user
spec:
grant:
roles:
- test_owner
instanceRef:
name: postgresql-instance-test
login: true
---
apiVersion: database.entigo.com/v1alpha1
kind: PostgreSQLDatabase
metadata:
name: database-two-test
spec:
instanceRef:
name: postgresql-instance-test
owner: test_owner

Wait for the objects to become ready. The roles already exist in the restored instance, so the SQL provider rotates their passwords automatically.

Re-create the postgres Pod from step 1 and connect to the database:

Terminal window
kubectl exec -it postgres -- bash
postgres:/# psql database-two-test

Query the example data:

SELECT * FROM example;

The rows inserted before the snapshot are back:

id | name | email | created_at
----+---------------+-------------------+----------------------------
1 | Alice Johnson | alice@example.com | 2026-03-10 14:02:12.007906
2 | Bob Smith | bob@example.com | 2026-03-10 14:02:12.007906
3 | Carol White | carol@example.com | 2026-03-10 14:02:12.007906
(3 rows)
Symptom Cause / fix
no matches for kind "PostgreSQLInstance" The API is not installed. Check the Prerequisites.
snapshotIdentifier cannot be changed when deletionProtection is enabled Set spec.deletionProtection to false first, then set snapshotIdentifier.
SYNCED is False The platform could not create a cloud resource, for example because the snapshot ID is wrong. kubectl describe pginstances.database.entigo.com <name> shows the error under Conditions and Events.
The restored instance was replaced by an empty one spec.snapshotIdentifier was removed or changed. It must stay in place after the restore.
The application cannot log in after Option B The role passwords were reset. Restart the Pods so they read the new values from the Secrets.

Whether a snapshot exists to restore from is decided by cluster-wide settings, not by the PostgreSQLInstance object: backupRetentionPeriod controls how far back you can restore, and postgresBackupBeforeDeletion controls whether a deleted instance leaves a final snapshot behind.

See Create a PostgreSQL Instance.