Skip to content

Commit 4e8f662

Browse files
Add Postgres readiness checks before psql execs
Prevents race conditions where pod is found but Postgres isn't ready yet.
1 parent 4d548af commit 4e8f662

File tree

3 files changed

+18
-0
lines changed

3 files changed

+18
-0
lines changed

testing/chainsaw/e2e/pgbackrest-restore/templates/create-cluster.yaml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,12 @@ spec:
8181
postgres-operator.crunchydata.com/role=master'
8282
)
8383
84+
# Wait for PostgreSQL to be ready
85+
until kubectl exec --namespace "${NAMESPACE}" "${PRIMARY}" \
86+
-- psql -qAt --command 'SELECT 1' 2>/dev/null; do
87+
sleep 1
88+
done
89+
8490
kubectl exec --stdin --namespace "${NAMESPACE}" "${PRIMARY}" -- psql -q --file=- <<'SQL'
8591
CREATE TABLESPACE barn LOCATION '/tablespaces/barn/data';
8692
GRANT ALL ON TABLESPACE barn TO public;

testing/chainsaw/e2e/pgbackrest-restore/templates/lose-data.yaml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,12 @@ spec:
3131
- name: PRIMARY
3232
value: ($primary)
3333
content: |
34+
# Wait for PostgreSQL to be ready
35+
until kubectl exec --namespace "${NAMESPACE}" "${PRIMARY}" \
36+
-- psql -qAt --command 'SELECT 1' 2>/dev/null; do
37+
sleep 1
38+
done
39+
3440
OBJECTIVE=$(
3541
kubectl exec --namespace "${NAMESPACE}" "${PRIMARY}" \
3642
-- psql -qAt --command 'SELECT clock_timestamp()'

testing/chainsaw/e2e/pgbackrest-restore/templates/verify-backup.yaml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,12 @@ spec:
1717
postgres-operator.crunchydata.com/role=master'
1818
)
1919
20+
# Wait for PostgreSQL to be ready
21+
until kubectl exec --namespace "${NAMESPACE}" "${PRIMARY}" \
22+
-- psql -qAt --command 'SELECT 1' 2>/dev/null; do
23+
sleep 1
24+
done
25+
2026
kubectl exec --namespace "${NAMESPACE}" "${PRIMARY}" \
2127
-- psql --command 'SELECT pg_switch_wal()' --pset footer=off
2228

0 commit comments

Comments
 (0)