turning off autocommit behavior in psql

Started by David Van Wieover 23 years ago6 messageshackers
Jump to latest
#1David Van Wie
vanwie@cryptio.net

Hi,

I've been using postgres for a little over a year now, and overall I've
been very pleased with it. Thanks!

The psql client is really nice, but I was frustrated by the lack of a
"no-autocommit" mode. So, I made a few small modifications to the client
to wrap everything in a transaction block automatically. I've been using
it locally for a while, and it seems to work alright. The patch is
attached (it's a patch to the 7.2.1 branch).

Do other people think this is a useful feature?

The one thing that I don't like about the patch, but that I'm not sure how
to handle, is telling the user that one transaction has ended and another
has begun. Currently, I am just printing NOTICE messages ("NOTICE:
aborting current transaction and beginning a new one", for example) but
this seems wrong, since the messages aren't coming from the backend.
Suggestions on how to handle this?

...dave

Attachments:

no-auto-commit.difftext/plain; charset=US-ASCII; name=no-auto-commit.diffDownload+47-6
#2Tom Lane
tgl@sss.pgh.pa.us
In reply to: David Van Wie (#1)
Re: turning off autocommit behavior in psql

David Van Wie <vanwie@cryptio.net> writes:

The psql client is really nice, but I was frustrated by the lack of a
"no-autocommit" mode. So, I made a few small modifications to the client
to wrap everything in a transaction block automatically.

I believe our intention has been to modify the backend to offer that
behavior (with a GUC variable to turn it on or off). Supporting it
only in psql doesn't seem the way to go.

regards, tom lane

#3David Van Wie
vanwie@cryptio.net
In reply to: Tom Lane (#2)
Re: turning off autocommit behavior in psql

On Thu, 22 Aug 2002, Tom Lane wrote:

I believe our intention has been to modify the backend to offer that
behavior (with a GUC variable to turn it on or off). Supporting it
only in psql doesn't seem the way to go.

After playing around with the transaction code for a while, I think I have
a reasonable idea of how to do this in the backend. This is my first time
working with the backend code, so it's entirely possible that I'm going
about this completely wrong, but the change seems to work and pass
regression tests.

I added a GUC variable "autocommit" which defaults to true. (Current
behavior). When it is set to false, the backend should begin a transaction
block if it is not inside one when executing any command. I did this by
changing StartTransactionCommand() in backend/access/transam/xact.c to
call BeginTransactionBlock() after StartTransaction() if it is not
currently in a transaction block.

Does this sound like a reasonable approach?

My first attempt at a patch (to current cvs source) is attached.

...dave

Attachments:

no-autocommit.difftext/plain; charset=US-ASCII; name=no-autocommit.diffDownload+35-18
#4Bruce Momjian
bruce@momjian.us
In reply to: David Van Wie (#3)
Re: turning off autocommit behavior in psql

Your patch has been added to the PostgreSQL unapplied patches list at:

http://candle.pha.pa.us/cgi-bin/pgpatches

I will try to apply it within the next 48 hours.

---------------------------------------------------------------------------

David Van Wie wrote:

On Thu, 22 Aug 2002, Tom Lane wrote:

I believe our intention has been to modify the backend to offer that
behavior (with a GUC variable to turn it on or off). Supporting it
only in psql doesn't seem the way to go.

After playing around with the transaction code for a while, I think I have
a reasonable idea of how to do this in the backend. This is my first time
working with the backend code, so it's entirely possible that I'm going
about this completely wrong, but the change seems to work and pass
regression tests.

I added a GUC variable "autocommit" which defaults to true. (Current
behavior). When it is set to false, the backend should begin a transaction
block if it is not inside one when executing any command. I did this by
changing StartTransactionCommand() in backend/access/transam/xact.c to
call BeginTransactionBlock() after StartTransaction() if it is not
currently in a transaction block.

Does this sound like a reasonable approach?

My first attempt at a patch (to current cvs source) is attached.

...dave

Content-Description:

[ Attachment, skipping... ]

---------------------------(end of broadcast)---------------------------
TIP 1: subscribe and unsubscribe commands go to majordomo@postgresql.org

-- 
  Bruce Momjian                        |  http://candle.pha.pa.us
  pgman@candle.pha.pa.us               |  (610) 359-1001
  +  If your life is a hard drive,     |  13 Roberts Road
  +  Christ can be your backup.        |  Newtown Square, Pennsylvania 19073
#5Tom Lane
tgl@sss.pgh.pa.us
In reply to: Bruce Momjian (#4)
Re: turning off autocommit behavior in psql

Bruce Momjian <pgman@candle.pha.pa.us> writes:

Your patch has been added to the PostgreSQL unapplied patches list at:

Please wait for this to be reviewed.

regards, tom lane

#6Bruce Momjian
bruce@momjian.us
In reply to: David Van Wie (#3)
Re: turning off autocommit behavior in psql

Tom Lane has applied this patch and merged it into our code. Thanks.

---------------------------------------------------------------------------

David Van Wie wrote:

On Thu, 22 Aug 2002, Tom Lane wrote:

I believe our intention has been to modify the backend to offer that
behavior (with a GUC variable to turn it on or off). Supporting it
only in psql doesn't seem the way to go.

After playing around with the transaction code for a while, I think I have
a reasonable idea of how to do this in the backend. This is my first time
working with the backend code, so it's entirely possible that I'm going
about this completely wrong, but the change seems to work and pass
regression tests.

I added a GUC variable "autocommit" which defaults to true. (Current
behavior). When it is set to false, the backend should begin a transaction
block if it is not inside one when executing any command. I did this by
changing StartTransactionCommand() in backend/access/transam/xact.c to
call BeginTransactionBlock() after StartTransaction() if it is not
currently in a transaction block.

Does this sound like a reasonable approach?

My first attempt at a patch (to current cvs source) is attached.

...dave

Content-Description:

[ Attachment, skipping... ]

---------------------------(end of broadcast)---------------------------
TIP 1: subscribe and unsubscribe commands go to majordomo@postgresql.org

-- 
  Bruce Momjian                        |  http://candle.pha.pa.us
  pgman@candle.pha.pa.us               |  (610) 359-1001
  +  If your life is a hard drive,     |  13 Roberts Road
  +  Christ can be your backup.        |  Newtown Square, Pennsylvania 19073