Postgres setting autocommit off globally
Asked Answered
V

3

7

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?

Vaasta answered 12/12, 2012 at 9:57 Comment(2)
There is no such configuration setting.Mamelon
+1 for including PostgreSQL version. You don't turn autocommit off globally, you must BEGIN an explicit transaction if you don't want autocommit.Neeley
B
16

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?

Buroker answered 18/10, 2013 at 9:27 Comment(0)
O
8

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

BEGIN;
  INSERT ...;
  UPDATE ...;
COMMIT; -- when you're done
Osteomalacia answered 12/12, 2012 at 11:21 Comment(0)
S
1

Like exhuma said, you can set it to off in your personal ~/.psqlrc file.

\set AUTOCOMMIT off 

But since you asked for a global level, the right file on Ubuntu is psqlrc (without leading dot) in /etc/postgresql-common/

To evaluate the right directory on your system, you may use:

pg_config --sysconfdir 

There is a sample psqlrc-file in

/usr/share/postgresql/12/psqlrc.sample

(for Version 12, obviously) but it doesn't contain further information.

Locate it on your system with

locate psqlrc 

I can't say, whether this information is valid for older versions than 12, but from my memory, it is, at least for the personal rc-file.

Scopula answered 1/7, 2021 at 22:41 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.