Add Geo LR subscription create and drop rake tasks

Adds subscription:create and subscription:drop to the existing gitlab:geo:logical_replication:subscription rake namespace, alongside the current publication:create/delete/set_tables and subscription:refresh tasks.

Today the subscription lifecycle is reimplemented as raw SQL in three separate places: the Dedicated instrumentor seed job, the instrumentor cutover tool, and a local test environment. This gives them one tested, product-side implementation to call instead, and it's a prerequisite for Geo LR promotion (!250118 (merged)), which requires the subscription to be dropped before promoting.

subscription:create creates the subscription on a Geo secondary with copy_data = true by default, using GEO_PUBLISHER_CONNECTION_STRING for the publisher connection. subscription:drop is idempotent, safely disables and detaches the slot before dropping so it never hangs on the publisher connection, then tries to drop the orphaned slot on the publisher, printing the manual SQL to run if the publisher is unreachable.

GEO_PUBLISHER_CONNECTION_STRING="postgresql://primary-host/gitlabhq_production" bundle exec rake "gitlab:geo:logical_replication:subscription:create"
GEO_PUBLISHER_CONNECTION_STRING="postgresql://primary-host/gitlabhq_production" bundle exec rake "gitlab:geo:logical_replication:subscription:drop"

Updates from review

  • Added GEO_SUBSCRIPTION_COPY_DATA=false as an optional env override to skip the initial data copy on create, useful when re-attaching a site that already has the data.
  • drop now also cleans up stranded tablesync slots (pg_<oid>_sync_%) left on the publisher after a mid-sync drop, and retries while the walsender still holds the slot.
  • The subscription lookup is scoped to current_database(), so a same-named subscription on another database in the cluster (for example ci) no longer causes false positives.
  • GEO_PUBLISHER_CONNECTION_STRING accepts any libpq parameters, so passfile= or certificate auth can be used to keep passwords out of statements and logs.

Closes #618152 (closed)

Edited by Douglas Barbosa Alexandre

Merge request reports

Loading
Loading