Unix Technical Forum

psql CLI: warn about ongoing transaction on exit

This is a discussion on psql CLI: warn about ongoing transaction on exit within the pgsql Bugs forums, part of the PostgreSQL category; --> Hello PostgreSQL developers, we recently got a wishlist Debian bug [1] that asks for the psql command line tool ...


Go Back   Unix Technical Forum > Database Server Software > PostgreSQL > pgsql Bugs

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 04-10-2008, 11:07 AM
Martin Pitt
 
Posts: n/a
Default psql CLI: warn about ongoing transaction on exit

Hello PostgreSQL developers,

we recently got a wishlist Debian bug [1] that asks for the psql
command line tool to "warn about an ongoing transaction on exit:

users=> begin;
BEGIN
[...]
users=> \q
$ ...

It would be really nice if psql prompted me whether I wanted to do
this. As it stands, it just rolls back the transaction."

Does this stand a chance to get implemented/accepted? I'm happy to
look into this and craft a patch if you would adopt it upstream.

Thanks,

Martin

[1] http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=439943

--
Martin Pitt http://www.piware.de
Ubuntu Developer http://www.ubuntu.com
Debian Developer http://www.debian.org

---------------------------(end of broadcast)---------------------------
TIP 2: Don't 'kill -9' the postmaster

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 04-10-2008, 11:07 AM
Neil Conway
 
Posts: n/a
Default Re: psql CLI: warn about ongoing transaction on exit

On Sun, 2007-09-16 at 20:34 +0200, Martin Pitt wrote:
> users=> begin;
> BEGIN
> [...]
> users=> \q
> $ ...
>
> It would be really nice if psql prompted me whether I wanted to do
> this. As it stands, it just rolls back the transaction."


At a minimum, I think we could make the fact that the transaction
has been rolled back more obvious (e.g. echo a ROLLBACK command tag
to the output or a similar warning message). Asking for confirmation
might be too chatty, and it's certainly not possible in
non-interactive mode.

-Neil



---------------------------(end of broadcast)---------------------------
TIP 2: Don't 'kill -9' the postmaster

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 04-10-2008, 11:07 AM
Tom Lane
 
Posts: n/a
Default Re: psql CLI: warn about ongoing transaction on exit

Neil Conway <neilc@samurai.com> writes:
> At a minimum, I think we could make the fact that the transaction
> has been rolled back more obvious (e.g. echo a ROLLBACK command tag
> to the output or a similar warning message). Asking for confirmation
> might be too chatty, and it's certainly not possible in
> non-interactive mode.


+1 for some kind of notification that work was rolled back. I concur
that demanding confirmation could have unpleasant consequences.

regards, tom lane

---------------------------(end of broadcast)---------------------------
TIP 6: explain analyze is your friend

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #4 (permalink)  
Old 04-10-2008, 11:07 AM
Martin Pitt
 
Posts: n/a
Default Re: psql CLI: warn about ongoing transaction on exit

Hi,

Neil Conway [2007-09-17 10:16 -0700]:
> At a minimum, I think we could make the fact that the transaction
> has been rolled back more obvious (e.g. echo a ROLLBACK command tag
> to the output or a similar warning message). Asking for confirmation
> might be too chatty, and it's certainly not possible in
> non-interactive mode.


Unless you do isatty(STDIN_FILENO). Nothing should change for
noninteractive mode. However, I agree that it might be annoying.

If you just output a rollback command on exit, then it is already too
late to rescue the pending transaction, so I'm not sure whether that
would help this use case so much.

What do you think about displaying a different prompt when a
transaction is pending, like showing the number of open transactions
in parentheses or so? '(2 transactions pending) mydb$' is way too
long, and '(T2) mydb$' is not intuitive. Hmm..

Thanks,

Martin
--
Martin Pitt http://www.piware.de
Ubuntu Developer http://www.ubuntu.com
Debian Developer http://www.debian.org

---------------------------(end of broadcast)---------------------------
TIP 1: if posting/reading through Usenet, please send an appropriate
subscribe-nomail command to majordomo@postgresql.org so that your
message can get through to the mailing list cleanly

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #5 (permalink)  
Old 04-10-2008, 11:07 AM
Neil Conway
 
Posts: n/a
Default Re: psql CLI: warn about ongoing transaction on exit

Martin Pitt said:
> If you just output a rollback command on exit, then it is already too
> late to rescue the pending transaction, so I'm not sure whether that
> would help this use case so much.


Well, the DBA can always replay the transaction manually -- I think
notifying the DBA that their modifications have been discarded
is actually more important. Presumably this isn't a particularly
common case...

> What do you think about displaying a different prompt when a
> transaction is pending, like showing the number of open transactions
> in parentheses or so?


Well, there can be at most one active transaction associated with
a given database session. In any case, this feature already exists:
see the %x escape sequence for the PROMPT[1-3] psql variables.

-Neil



---------------------------(end of broadcast)---------------------------
TIP 2: Don't 'kill -9' the postmaster

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #6 (permalink)  
Old 04-10-2008, 11:07 AM
Tom Lane
 
Posts: n/a
Default Re: psql CLI: warn about ongoing transaction on exit

Martin Pitt <martin@piware.de> writes:
> What do you think about displaying a different prompt when a
> transaction is pending,


That's been possible for a long time, see the prompt-string variable
in psql.

regards, tom lane

---------------------------(end of broadcast)---------------------------
TIP 1: if posting/reading through Usenet, please send an appropriate
subscribe-nomail command to majordomo@postgresql.org so that your
message can get through to the mailing list cleanly

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump


All times are GMT. The time now is 03:07 AM.


Powered by vBulletin® Version 3.6.5
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
SEO by vBSEO 3.2.0
www.UnixAdminTalk.com