Postgres setting autocommit off globally

2019-06-18 15:34发布

问题:

How do you set autocommit off in psql 8.4 at a global level? is there a configuration attribute that i can change that will introduce this behaviour for all dbs on a cluster to start db sessions with autocommit off?

回答1:

Simply add the following to ~/.psqlrc:

\set AUTOCOMMIT off 

Note that this only works when using the psql shell! I assume this is what you are talking about?



回答2:

Use a transaction if you want want a (open) transaction:

BEGIN;
  INSERT ...;
  UPDATE ...;
COMMIT; -- when you're done