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
+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
}