Geo [LR]: rake tasks to create and drop the logical replication subscription

Geo with logical replication (LR) needs a way to create and drop the LR subscription on the secondary as a first-class rake task. Today only the publication side is covered in product code, and every consumer of the subscription lifecycle has reimplemented the same raw SQL independently.

Why

ee/lib/tasks/gitlab/geo/logical_replication.rake ships gitlab:geo:logical_replication:publication:create, publication:delete, publication:set_tables, and subscription:refresh, but there is no subscription:create or subscription:drop anywhere in the codebase.

Because of that gap, the subscription lifecycle lives as vendored raw psql in three separate places:

The teardown ordering is subtle and every consumer has to get it right on its own: ALTER SUBSCRIPTION ... DISABLE, then ALTER SUBSCRIPTION ... SET (slot_name = NONE) so DROP never hangs on the publisher connection, then DROP SUBSCRIPTION, then drop the detached replication slot on the publisher. Forgetting the publisher slot causes unbounded WAL retention on the publisher.

Promotion (!250118 (merged)) aborts with ActiveSubscriptionError while a subscription exists, even one that is merely disabled. Dropping the subscription is a mandatory pre-promotion step, and today there is no product-side implementation of it.

How

Extend the existing gitlab:geo:logical_replication:subscription namespace, reusing the Tasks::Gitlab::Geo::LogicalReplication helpers and the GEO_SUBSCRIPTION env var convention already used by subscription:refresh.

  • subscription:create: takes connection parameters via env vars, uses a publication name that defaults to geo_publication, sets copy_data = true by default, and is guarded to run only on a Geo secondary.
  • subscription:drop: idempotent (no-op if the subscription does not exist), uses the safe teardown ordering (DISABLE, SET slot_name = NONE, DROP), then attempts pg_drop_replication_slot on the publisher. If the publisher is unreachable, it prints the manual command instead of failing, mirroring the warning path already used by the instrumentor cutover tool.

What

  • Add gitlab:geo:logical_replication:subscription:create
  • Add gitlab:geo:logical_replication:subscription:drop with safe teardown ordering, idempotency, and publisher slot handling
  • Specs for both tasks, including re-run/no-op paths
  • Document both tasks alongside the existing publication tasks
  • Open a follow-up on the Dedicated side for instrumentor to call these instead of its vendored SQL

Exit criteria

  • Both tasks exist and are idempotent.
  • A promotion can be prepared with subscription:drop alone, satisfying the MR 250118 pre-promotion requirement.
  • Instrumentor and geo-caproni-lr can delete their vendored subscription SQL.

Related:

Edited by Douglas Barbosa Alexandre