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:
2026-08-18 15:45:25 +03:30
co-authored by Cursor
parent d055c50b94
commit 810d1672a5
3 changed files with 8 additions and 6 deletions
+3 -2
View File
@@ -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.
Keep migrations schema-only. After each migrate, subscribers get
`ALTER SUBSCRIPTION … REFRESH PUBLICATION WITH (copy_data = true)` so **new
tables** join replication (Postgres does not add them by itself).
`ALTER SUBSCRIPTION … REFRESH PUBLICATION WITH (copy_data = false)` so **new
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, …)
+1 -1
View File
@@ -322,7 +322,7 @@ repair_replica() {
run_psql "$(libpq_dsn "$replica_dsn")" -v ON_ERROR_STOP=1 -q \
-c "ALTER SUBSCRIPTION \"${sub}\" ENABLE"
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
echo " repair done"
+4 -3
View File
@@ -192,10 +192,11 @@ refresh_subscriptions() {
return 0
fi
for sub in "${subs[@]}"; do
echo " ALTER SUBSCRIPTION $sub REFRESH PUBLICATION (copy_data)"
# New tables added to FOR ALL TABLES are NOT replicated until this runs.
echo " ALTER SUBSCRIPTION $sub REFRESH PUBLICATION (copy_data=false)"
# 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 \
-c "ALTER SUBSCRIPTION \"${sub}\" REFRESH PUBLICATION WITH (copy_data = true)"
-c "ALTER SUBSCRIPTION \"${sub}\" REFRESH PUBLICATION WITH (copy_data = false)"
done
}