Restore a PostgreSQL Instance
Restore a PostgreSQL instance from a snapshot.
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.
Prerequisites
Section titled “Prerequisites”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.
1. Create a test scenario
Section titled “1. Create a test scenario”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/v1alpha1kind: PostgreSQLInstancemetadata: name: postgresql-instance-testspec: deletionProtection: false engineVersion: '17.10' instanceType: db.t3.micro---apiVersion: database.entigo.com/v1alpha1kind: PostgreSQLUsermetadata: name: test-ownerspec: instanceRef: name: postgresql-instance-test login: false name: test_owner---apiVersion: database.entigo.com/v1alpha1kind: PostgreSQLUsermetadata: name: test-userspec: grant: roles: - test_owner instanceRef: name: postgresql-instance-test login: true---apiVersion: database.entigo.com/v1alpha1kind: PostgreSQLDatabasemetadata: name: database-two-testspec: instanceRef: name: postgresql-instance-test owner: test_ownerStart a Pod with the test-user credentials:
apiVersion: v1kind: Podmetadata: name: postgresspec: 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:
kubectl exec -it postgres -- bashpsql database-two-testInsert 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:
aws rds describe-db-snapshots --no-paginate --query "DBSnapshots[].[DBSnapshotIdentifier]" --output table --region eu-north-1# Shows test-restorationRemove the test Pod:
kubectl delete pod postgres2. Option A: Restore only the instance
Section titled “2. Option A: Restore only the instance”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:
kubectl patch pginstances.database.entigo.com postgresql-instance-test --type=merge -p '{"spec":{"deletionProtection":false}}'Set spec.snapshotIdentifier to the snapshot ID:
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:
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 9sContinue 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:
kubectl delete postgresqldatabases.database.entigo.com database-two-testkubectl delete postgresqlusers.database.entigo.com test-userkubectl delete postgresqlusers.database.entigo.com test-ownerkubectl delete pginstances.database.entigo.com postgresql-instance-testCreate the objects again, with spec.snapshotIdentifier set to the snapshot ID:
apiVersion: database.entigo.com/v1alpha1kind: PostgreSQLInstancemetadata: name: postgresql-instance-testspec: deletionProtection: false engineVersion: '17.10' instanceType: db.t3.micro snapshotIdentifier: test-restoration---apiVersion: database.entigo.com/v1alpha1kind: PostgreSQLUsermetadata: name: test-ownerspec: instanceRef: name: postgresql-instance-test login: false name: test_owner---apiVersion: database.entigo.com/v1alpha1kind: PostgreSQLUsermetadata: name: test-userspec: grant: roles: - test_owner instanceRef: name: postgresql-instance-test login: true---apiVersion: database.entigo.com/v1alpha1kind: PostgreSQLDatabasemetadata: name: database-two-testspec: instanceRef: name: postgresql-instance-test owner: test_ownerWait for the objects to become ready. The roles already exist in the restored instance, so the SQL provider rotates their passwords automatically.
4. Verify
Section titled “4. Verify”Re-create the postgres Pod from step 1 and connect to the database:
kubectl exec -it postgres -- bashpostgres:/# psql database-two-testQuery 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)Troubleshooting
Section titled “Troubleshooting”| 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. |
EnvironmentConfig
Section titled “EnvironmentConfig”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.