fix(replicas): never REFRESH with copy_data=true after a data copy
A second logical copy unique-conflicts on existing PKs and leaves tablesync workers stuck, so live UPDATEs never apply on slaves. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
+3
-2
@@ -159,8 +159,9 @@ repair script re-applies grants. `REPLICA_DSNS` must connect as a role that can
|
|||||||
`deploy/replicas.env` exists on that host.
|
`deploy/replicas.env` exists on that host.
|
||||||
|
|
||||||
Keep migrations schema-only. After each migrate, subscribers get
|
Keep migrations schema-only. After each migrate, subscribers get
|
||||||
`ALTER SUBSCRIPTION … REFRESH PUBLICATION WITH (copy_data = true)` so **new
|
`ALTER SUBSCRIPTION … REFRESH PUBLICATION WITH (copy_data = false)` so **new
|
||||||
tables** join replication (Postgres does not add them by itself).
|
tables** join the subscription without a second full copy (repair already
|
||||||
|
copied rows; a second copy unique-conflicts and stalls live UPDATEs).
|
||||||
|
|
||||||
## 9) Data changes **without** deploy (import settings, edit tenant, …)
|
## 9) Data changes **without** deploy (import settings, edit tenant, …)
|
||||||
|
|
||||||
|
|||||||
@@ -322,7 +322,7 @@ repair_replica() {
|
|||||||
run_psql "$(libpq_dsn "$replica_dsn")" -v ON_ERROR_STOP=1 -q \
|
run_psql "$(libpq_dsn "$replica_dsn")" -v ON_ERROR_STOP=1 -q \
|
||||||
-c "ALTER SUBSCRIPTION \"${sub}\" ENABLE"
|
-c "ALTER SUBSCRIPTION \"${sub}\" ENABLE"
|
||||||
run_psql "$(libpq_dsn "$replica_dsn")" -v ON_ERROR_STOP=1 -q \
|
run_psql "$(libpq_dsn "$replica_dsn")" -v ON_ERROR_STOP=1 -q \
|
||||||
-c "ALTER SUBSCRIPTION \"${sub}\" REFRESH PUBLICATION" || true
|
-c "ALTER SUBSCRIPTION \"${sub}\" REFRESH PUBLICATION WITH (copy_data = false)" || true
|
||||||
done
|
done
|
||||||
|
|
||||||
echo " repair done"
|
echo " repair done"
|
||||||
|
|||||||
@@ -192,10 +192,11 @@ refresh_subscriptions() {
|
|||||||
return 0
|
return 0
|
||||||
fi
|
fi
|
||||||
for sub in "${subs[@]}"; do
|
for sub in "${subs[@]}"; do
|
||||||
echo " ALTER SUBSCRIPTION $sub REFRESH PUBLICATION (copy_data)"
|
echo " ALTER SUBSCRIPTION $sub REFRESH PUBLICATION (copy_data=false)"
|
||||||
# New tables added to FOR ALL TABLES are NOT replicated until this runs.
|
# Do not recopy existing tables — that starts tablesync workers which
|
||||||
|
# unique-conflict with data already on the replica and block live UPDATEs.
|
||||||
run_psql "$(libpq_dsn "$dsn")" -v ON_ERROR_STOP=1 -q \
|
run_psql "$(libpq_dsn "$dsn")" -v ON_ERROR_STOP=1 -q \
|
||||||
-c "ALTER SUBSCRIPTION \"${sub}\" REFRESH PUBLICATION WITH (copy_data = true)"
|
-c "ALTER SUBSCRIPTION \"${sub}\" REFRESH PUBLICATION WITH (copy_data = false)"
|
||||||
done
|
done
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user