psql + autocommit

Started by John Sidney-Woollettover 21 years ago34 messagesgeneral
Jump to latest
#1John Sidney-Woollett
johnsw@wardbrook.com

With the advent of postgres v8, would it be possible to change the
default behaviour of psql from AUTOCOMMIT=ON to AUTOCOMMIT=OFF ?

Although this might break backward compatibility, it might be acceptable
on the basis that v8 is such a major release.

Also adding a new command line parameter to control the AUTOCOMMIT
setting for those users that will experience broken scripts executed
(especially using the -c command) might help ease the pain, since they
would only have to add a new switch to their existing scripts, or
explictly set the AUTOCOMMIT variable in their scripts. Otherwise they
could add a final COMMIT at the end of the script.

In Oracle's SQLPlus, AUTOCOMMIT=OFF is the default behaviour and is (in
my view) preferable to the current situation.

I know the AUTOCOMMIT can be set in an active session, but I sometimes
forget leading to an un-rollback-able data loss/damage. Using the
.psqlrc file can lead to inconsistancies between different accounts
where some have the setting defined and others don't.

The final reason for doing so would be to closer to the SQL spec.

John Sidney-Woollett

#2Peter Eisentraut
peter_e@gmx.net
In reply to: John Sidney-Woollett (#1)
Re: psql + autocommit

John Sidney-Woollett wrote:

With the advent of postgres v8, would it be possible to change the
default behaviour of psql from AUTOCOMMIT=ON to AUTOCOMMIT=OFF ?

Absolutely not. This will break every psql use in existence.

--
Peter Eisentraut
http://developer.postgresql.org/~petere/

#3Tom Lane
tgl@sss.pgh.pa.us
In reply to: John Sidney-Woollett (#1)
Re: psql + autocommit

John Sidney-Woollett <johnsw@wardbrook.com> writes:

With the advent of postgres v8, would it be possible to change the
default behaviour of psql from AUTOCOMMIT=ON to AUTOCOMMIT=OFF ?

If that's what you want, set it in your ~/.psqlrc.

regards, tom lane

#4John Sidney-Woollett
johnsw@wardbrook.com
In reply to: Peter Eisentraut (#2)
Re: psql + autocommit

No it won't!

It will break any newly compiled version of psql expecting to work to
the old behaviour. It won't affect anyone using an older version of
postgres or psql (ie pre version 8).

To ease any pain, what about a configuration setting for the build
script for postgres (and psql) which changes the default behaviour for
the AUTOCOMMIT setting.

I personally would want to build it with AUTOCOMMIT=OFF is I had the
setting to do so.

This change apart from being more standards compliant would help make
psql "safer" than it currently is.

John Sidney-Woollett

Peter Eisentraut wrote:

Show quoted text

John Sidney-Woollett wrote:

With the advent of postgres v8, would it be possible to change the
default behaviour of psql from AUTOCOMMIT=ON to AUTOCOMMIT=OFF ?

Absolutely not. This will break every psql use in existence.

#5Peter Eisentraut
peter_e@gmx.net
In reply to: John Sidney-Woollett (#4)
Re: psql + autocommit

John Sidney-Woollett wrote:

It will break any newly compiled version of psql expecting to work to
the old behaviour. It won't affect anyone using an older version of
postgres or psql (ie pre version 8).

Of course there are no backward compatibility issues when you keep using
the old version. The problem is that people will use the new psql
expecting it to behave like the old one. This isn't a small secondary
change; it fundamentally changes the interaction with the program.

--
Peter Eisentraut
http://developer.postgresql.org/~petere/

#6John Sidney-Woollett
johnsw@wardbrook.com
In reply to: Peter Eisentraut (#5)
Re: psql + autocommit

I agree with you 100% about this - whoever it won't affect new users
starting with v8 (including many new Windows users), and those migrating
from other dbs (like Oracle).

If a config switch was available for the build process that could
preserve the "old" behavior - it wouldn't really pose a problem for
existing users migrating their systems to v8 provided they set the
switch appropriately.

A warning message on psql start might help:

++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Welcome to psql 8.0, the PostgreSQL interactive terminal.

Type: \copyright for distribution terms
\h for help with SQL commands
\? for help on internal slash commands
\g or terminate with semicolon to execute query
\q to quit

AUTOCOMMIT is ON/OFF <-- depending on the way it is built

dbname=#
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

This is an opportunity here to make psql more standards compliant and it
can be done in such a way so as not to p*ss off the existing user base,
and break their applications.

John Sidney-Woollett

Peter Eisentraut wrote:

Show quoted text

John Sidney-Woollett wrote:

It will break any newly compiled version of psql expecting to work to
the old behaviour. It won't affect anyone using an older version of
postgres or psql (ie pre version 8).

Of course there are no backward compatibility issues when you keep using
the old version. The problem is that people will use the new psql
expecting it to behave like the old one. This isn't a small secondary
change; it fundamentally changes the interaction with the program.

#7Peter Eisentraut
peter_e@gmx.net
In reply to: John Sidney-Woollett (#6)
Re: psql + autocommit

John Sidney-Woollett wrote:

If a config switch was available for the build process that could
preserve the "old" behavior - it wouldn't really pose a problem for
existing users migrating their systems to v8 provided they set the
switch appropriately.

Such a switch exists: you put \set AUTOCOMMIT in your psql configuration
file. We don't put feature-altering switches in the build process if
we can help it. Since most people use prebuilt binaries, such a switch
would be mostly useless at best.

--
Peter Eisentraut
http://developer.postgresql.org/~petere/

#8John Sidney-Woollett
johnsw@wardbrook.com
In reply to: Peter Eisentraut (#7)
Re: psql + autocommit

I can see this is going nowhere fast! :)

I'd like to see a global setting that I could change, not one on a user
by user basis...

I'd also like a message in the Welcome banner telling me what the
current AUTOCOMMIT setting is...

John Sidney-Woollett

Peter Eisentraut wrote:

Show quoted text

John Sidney-Woollett wrote:

If a config switch was available for the build process that could
preserve the "old" behavior - it wouldn't really pose a problem for
existing users migrating their systems to v8 provided they set the
switch appropriately.

Such a switch exists: you put \set AUTOCOMMIT in your psql configuration
file. We don't put feature-altering switches in the build process if
we can help it. Since most people use prebuilt binaries, such a switch
would be mostly useless at best.

#9Peter Eisentraut
peter_e@gmx.net
In reply to: John Sidney-Woollett (#8)
Re: psql + autocommit

John Sidney-Woollett wrote:

I'd like to see a global setting that I could change, not one on a
user by user basis...

Then I suggest that in addition to the per-user configuration file
~/.psqlrc you implement a global configuration file
/etc/postgresql/psqlrc. That would be the place you could put such a
setting.

I'd also like a message in the Welcome banner telling me what the
current AUTOCOMMIT setting is...

Put

\echo 'AUTOCOMMIT is' :AUTOCOMMIT

in your configuration file and you're done.

--
Peter Eisentraut
http://developer.postgresql.org/~petere/

#10John Sidney-Woollett
johnsw@wardbrook.com
In reply to: Peter Eisentraut (#9)
Re: psql + autocommit

OK that's exactly what I want - thanks! I wasn't aware of a global
psqlrc file.

BTW, I still think the default behaviour is incorrect...

But at least I can work around it now and have the change be global. :)

Thanks again

John Sidney-Woollett

Peter Eisentraut wrote:

Show quoted text

John Sidney-Woollett wrote:

I'd like to see a global setting that I could change, not one on a
user by user basis...

Then I suggest that in addition to the per-user configuration file
~/.psqlrc you implement a global configuration file
/etc/postgresql/psqlrc. That would be the place you could put such a
setting.

I'd also like a message in the Welcome banner telling me what the
current AUTOCOMMIT setting is...

Put

\echo 'AUTOCOMMIT is' :AUTOCOMMIT

in your configuration file and you're done.

#11daniel
daniel@littlesaigon.homedns.org
In reply to: John Sidney-Woollett (#1)
Re: psql + autocommit

daniel wrote:
put
\set AUTOCOMMIT 'off'
in your configuration file and you're done.
daniel

Show quoted text

John Sidney-Woollett wrote:

OK that's exactly what I want - thanks! I wasn't aware of a global
psqlrc file.

BTW, I still think the default behaviour is incorrect...

But at least I can work around it now and have the change be global. :)

Thanks again

John Sidney-Woollett

Peter Eisentraut wrote:

John Sidney-Woollett wrote:

I'd like to see a global setting that I could change, not one on a
user by user basis...

Then I suggest that in addition to the per-user configuration file
~/.psqlrc you implement a global configuration file
/etc/postgresql/psqlrc. That would be the place you could put such
a setting.

I'd also like a message in the Welcome banner telling me what the
current AUTOCOMMIT setting is...

Put

\echo 'AUTOCOMMIT is' :AUTOCOMMIT

in your configuration file and you're done.

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

#12John Sidney-Woollett
johnsw@wardbrook.com
In reply to: John Sidney-Woollett (#10)
Re: psql + autocommit

Does psql v7.4 support a global psqlrc file? I tried adding it to
/etc/postgresql/psqlrc and /etc/psqlrc but in both cases it was ignored.

Adding it to $HOME/.psqlrc worked fine, but means that I need to install
it for each user.

Any ideas why the global file doesn't work?

John Sidney-Woollett

Show quoted text

Then I suggest that in addition to the per-user configuration file
~/.psqlrc you implement a global configuration file
/etc/postgresql/psqlrc. That would be the place you could put such a
setting.

I'd also like a message in the Welcome banner telling me what the
current AUTOCOMMIT setting is...

Put

\echo 'AUTOCOMMIT is' :AUTOCOMMIT

in your configuration file and you're done.

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

#13cluster
skrald@amossen.dk
In reply to: John Sidney-Woollett (#1)
Re: psql + autocommit

Does psql v7.4 support a global psqlrc file? I tried adding it to
/etc/postgresql/psqlrc and /etc/psqlrc but in both cases it was ignored.

I'm really interested in this global setting to. I cannot find any
documentation on where to place this config file either.

#14cluster
skrald@amossen.dk
In reply to: John Sidney-Woollett (#1)
Re: psql + autocommit

To ease any pain, what about a configuration setting for the build
script for postgres (and psql) which changes the default behaviour for
the AUTOCOMMIT setting.

I really agree on the need for a posibility to set autocommit = off
*regardless* of the client:
On a system using both psql, php and perl on a large bunch of clients it
is a pain - real pain - to set this behavior up individually.

It could be really nice if I had a choise of ensuring that any default
behavior was the more "secure" autommit = off. So please bring back this
setting in postgresql.conf. Please.

#15Alvaro Herrera
alvherre@dcc.uchile.cl
In reply to: John Sidney-Woollett (#12)
Re: psql + autocommit

On Wed, Sep 15, 2004 at 10:32:20PM +0100, John Sidney-Woollett wrote:

Does psql v7.4 support a global psqlrc file? I tried adding it to
/etc/postgresql/psqlrc and /etc/psqlrc but in both cases it was ignored.

Try with $PGDATA/etc/psqlrc

Oh, wait, apparently that was added on 8.0.

--
Alvaro Herrera (<alvherre[a]dcc.uchile.cl>)
"Use it up, wear it out, make it do, or do without"

#16William Yu
wyu@talisys.com
In reply to: John Sidney-Woollett (#12)
Re: psql + autocommit

A script to do this should be trivial. This is just off the top of my head.

#!/usr/bin/perl
open(USER, "/etc/passwd");
while(<USER>) {
@tmp = split(/:/, $_);
$home_dir = $tmp[5];
if ($home_dir) {
open(PGCONF, "> $home_dir/.psqlrc");
print PGCONF "\\set AUTOCOMMIT 'off'\n";
close(PGCONF);
}
}
close(USER);

John Sidney-Woollett wrote:

Show quoted text

Adding it to $HOME/.psqlrc worked fine, but means that I need to install
it for each user.

#17Peter Eisentraut
peter_e@gmx.net
In reply to: John Sidney-Woollett (#12)
Re: psql + autocommit

John Sidney-Woollett wrote:

Any ideas why the global file doesn't work?

There is no support for a global configuration file at this time. I
suggested that you *implement* it.

--
Peter Eisentraut
http://developer.postgresql.org/~petere/

#18Bruce Momjian
bruce@momjian.us
In reply to: Peter Eisentraut (#17)
Re: psql + autocommit

Peter Eisentraut wrote:

John Sidney-Woollett wrote:

Any ideas why the global file doesn't work?

There is no support for a global configuration file at this time. I
suggested that you *implement* it.

8.0 has a global psqlrc.

-- 
  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
#19Lars Haugseth
lars@tinde.com
In reply to: Peter Eisentraut (#17)
Re: psql + autocommit

* Peter Eisentraut:
| John Sidney-Woollett wrote:
| > Any ideas why the global file doesn't work?
|
| There is no support for a global configuration file at this time. I
| suggested that you *implement* it.

Version 8.0.0beta2 supports a global configuration file. It's should be
located in '~postgres/etc/pgsql'.

--
Lars Haugseth

#20John Sidney-Woollett
johnsw@wardbrook.com
In reply to: Lars Haugseth (#19)
Re: psql + autocommit

Thanks - I'll live with modifying the ~/.psqlrc file until we move to
version 8.

John Sidney-Woollett

Lars Haugseth wrote:

Show quoted text

* Peter Eisentraut:
| John Sidney-Woollett wrote:
| > Any ideas why the global file doesn't work?
|
| There is no support for a global configuration file at this time. I
| suggested that you *implement* it.

Version 8.0.0beta2 supports a global configuration file. It's should be
located in '~postgres/etc/pgsql'.

#21John Sidney-Woollett
johnsw@wardbrook.com
In reply to: Lars Haugseth (#19)
#22Barry S
barry@nospam.4.me.thx.com
In reply to: John Sidney-Woollett (#1)
#23Peter Eisentraut
peter_e@gmx.net
In reply to: Lars Haugseth (#19)
#24Michael Paesold
mpaesold@gmx.at
In reply to: Peter Eisentraut (#23)
#25Lars Haugseth
lars@tinde.com
In reply to: Michael Paesold (#24)
#26Bruce Momjian
bruce@momjian.us
In reply to: Lars Haugseth (#25)
#27John Sidney-Woollett
johnsw@wardbrook.com
In reply to: Bruce Momjian (#26)
#28Peter Eisentraut
peter_e@gmx.net
In reply to: John Sidney-Woollett (#27)
#29John Sidney-Woollett
johnsw@wardbrook.com
In reply to: Peter Eisentraut (#28)
#30Bruce Momjian
bruce@momjian.us
In reply to: Peter Eisentraut (#28)
#31Peter Eisentraut
peter_e@gmx.net
In reply to: Bruce Momjian (#30)
#32Bruce Momjian
bruce@momjian.us
In reply to: Peter Eisentraut (#31)
#33Greg Sabino Mullane
greg@turnstep.com
In reply to: John Sidney-Woollett (#12)
#34Michael Paesold
mpaesold@gmx.at
In reply to: Greg Sabino Mullane (#33)