postgresql Postgres 全局设置自动提交关闭

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/13837146/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-21 00:38:13  来源:igfitidea点击:

Postgres setting autocommit off globally

postgresqltransactionsautocommit

提问by ajeeshpu

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?

您如何在全局级别在 psql 8.4 中设置自动提交?是否有我可以更改的配置属性,它将为集群上的所有 dbs 引入此行为,以在关闭自动提交的情况下启动 db 会话?

回答by exhuma

Simply add the following to ~/.psqlrc:

只需将以下内容添加到~/.psqlrc

\set AUTOCOMMIT off 

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

请注意,这仅在使用psqlshell 时有效!我想这就是你在说什么?

回答by Frank Heikens

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

如果您想要(开放)交易,请使用交易:

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