Skip to content

feat(db): offer read replica connection on tiger db connect#165

Merged
aprimakina merged 2 commits into
mainfrom
feat/db-connect-read-replica
Jun 17, 2026
Merged

feat(db): offer read replica connection on tiger db connect#165
aprimakina merged 2 commits into
mainfrom
feat/db-connect-read-replica

Conversation

@aprimakina

@aprimakina aprimakina commented Jun 16, 2026

Copy link
Copy Markdown
Contributor

When tiger db connect / psql runs in an interactive terminal and the service has active read replicas, prompt the user to connect to one instead of the primary. With no replicas, non-TTY stdin, or --no-replica-prompt, it connects to the primary directly as before.

Notes

  • Replicas share the primary's credentials (password storage/recovery still operates on the primary).
  • --pooled is strict for the primary (hard error if no pooler) and best-effort for replicas (warns, falls back to direct).
  • Refactors GetConnectionDetails/GetReplicaConnectionDetails onto a shared buildConnectionDetails helper.

When running `tiger db connect`/`psql` in an interactive terminal, prompt
the user to connect to a read replica instead of the primary, or to create
a new read replica and connect to it when none exist. The prompt is skipped
when stdin is not a TTY or when `--no-replica-prompt` is passed.

Details:
- Detect replicas via the `/replicaSets` API; list active ones in a menu.
- Read replicas share the primary's credentials, so password storage and
  recovery operate on the primary service.
- After a replica becomes active, wait for its endpoint to accept TCP
  connections before handing off to psql (avoids a transient "connection
  refused" race).
- `--pooled` is strict for the primary (hard error if unavailable) and
  best-effort for replicas (warn and fall back to a direct connection).

Refactors `GetConnectionDetails`/`GetReplicaConnectionDetails` onto a shared
`buildConnectionDetails` helper and adds `common.WaitForReplicaSet`. Updates
README, specs, and CLAUDE.md.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@aprimakina aprimakina self-assigned this Jun 16, 2026
@aprimakina aprimakina force-pushed the feat/db-connect-read-replica branch from e5a5f04 to 52b388d Compare June 17, 2026 10:52
Drop the "create a new read replica" option from the `tiger db connect`
prompt. The prompt now only appears when the service has one or more
active read replicas, offering to connect to the primary or one of them;
with no replicas it connects to the primary directly without prompting.

Removes the replica-creation flow (createReplicaSet, primaryResources,
endpoint-readiness wait) and the now-unused WaitForReplicaSet/poll
abstraction, reverting wait.go to its prior form. Also simplifies the
selection menu to a single source of truth for choices.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@aprimakina aprimakina force-pushed the feat/db-connect-read-replica branch from 52b388d to 3344e3e Compare June 17, 2026 11:02
@aprimakina aprimakina marked this pull request as ready for review June 17, 2026 11:02
@aprimakina aprimakina requested a review from Askir June 17, 2026 11:02

@Askir Askir left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good over all just a bit confused over the pooler behaviour.

Comment on lines +83 to +84
// --pooled is best-effort on replicas: warn and connect directly if the
// chosen replica has no pooler.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a particular reason for why we do it this way for replicas? Sorry not super familiar with connection poolers in general.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For the primary, --pooled is the explicit request, so we fail hard if it's unavailable (unchanged behavior). For a replica, it's just a modifier on the connect action you already chose interactively, so rather than blocking the connection, we warn and fall back to a direct connection.

@aprimakina aprimakina merged commit 11fe798 into main Jun 17, 2026
2 checks passed
@aprimakina aprimakina deleted the feat/db-connect-read-replica branch June 17, 2026 12:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants