Skip to content

Allow force-quit if a transaction is running#1573

Open
maximsmol wants to merge 2 commits intodbcli:mainfrom
latchbio:maximsmol/force-quit
Open

Allow force-quit if a transaction is running#1573
maximsmol wants to merge 2 commits intodbcli:mainfrom
latchbio:maximsmol/force-quit

Conversation

@maximsmol
Copy link
Copy Markdown
Contributor

@maximsmol maximsmol commented Apr 5, 2026

Description

Currently if pgcli detects an active transaction, it will not allow quitting with ^D or the quit command. This means the user is stuck until the transaction finishes. I've been working around this issue with bash job control (^Z to suspend, then killing the process manually).

Note that the ROLLBACK option does not work since the connection has a query in progress:

> select pg_sleep(60)
^C^Ccancelled query
>^D
A transaction is ongoing. Choose `c` to COMMIT, `r` to ROLLBACK, `a` to abort exit. [a]: r
sending query failed: another command is already in progress
Time: 0.010s

This is particularly problematic in two cases:

  1. Hanging queries that freeze the session for a long time (e.g. pg_sleep(3600))
  2. When a connection has failed but pgcli does not realize it has to reconnect (e.g. after the system goes to sleep for a long time while pgcli is running, like on a laptop)

This patch simply adds a force option to the in-transaction exit dialog that allows exiting annyway.

Checklist

  • I've added this contribution to the changelog.rst.
  • I've added my name to the AUTHORS file (or it's already there).
  • I installed pre-commit hooks (pip install pre-commit && pre-commit install).
  • I verified that my changes work as expected (this may include manually testing them in your local environment, or in other available environments). Cross this out if not relevant (for example, if you're making a documentation change).
  • Please squash merge this pull request (uncheck if you'd like us to merge as multiple commits)

Signed-off-by: maximsmol <1472826+maximsmol@users.noreply.github.com>
Signed-off-by: maximsmol <1472826+maximsmol@users.noreply.github.com>
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.

1 participant