postgresql 如何检查自动提交是否打开 postgres 的 psql

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/41298283/
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 02:28:40  来源:igfitidea点击:

How to check if autocommit is on or not postgres' psql

postgresqlautocommit

提问by codec

I am using postgres 9.5. How can I check if auto commit is on or off? I tried SHOW AUTOCOMMITwhere I got ERROR: unrecognized configuration parameter "autocommit"then I did a \set autocommit offand then SHOW AUTOCOMMITgives me blank output. How can identify if autocommit is on or off? Also can I set it to off while/after the database in created in my sql file?

我正在使用 postgres 9.5。如何检查自动提交是打开还是关闭?我尝试SHOW AUTOCOMMIT了我得到的地方ERROR: unrecognized configuration parameter "autocommit"然后我做了一个\set autocommit off然后SHOW AUTOCOMMIT给了我空白输出。如何确定自动提交是打开还是关闭?我也可以在我的 sql 文件中创建数据库时/之后将其设置为关闭吗?

回答by McNets

According to thisDustin Marx article, you can use:

根据达斯汀马克思的文章,你可以使用:

\echo :AUTOCOMMIT

If it's desired to "always" have autocommit disabled, the \set AUTOCOMMIT off meta-command can be added to one's local ~/.psqlrc file. For an even more global setting, this meta-command can be placed in apsqlrc file in the database's system config directory (which can be located using PostgreSQL operating system-level command pg_config --sysconfdir).

如果希望“始终”禁用自动提交,可以将 \set AUTOCOMMIT off 元命令添加到本地 ~/.psqlrc 文件中。对于更全局的设置,可以将此元命令放置在数据库系统配置目录(可以使用 PostgreSQL 操作系统级命令 pg_config --sysconfdir 定位)的 apsqlrc 文件中。

回答by Deep Sehgal

One quick and dirty way is to just execute commit; and look for the below message to infer auto-commit is on or not.

一种快速而肮脏的方法是只执行提交;并查找以下消息以推断自动提交是否开启。

Error report - SQL Error: Cannot commit when autoCommit is enabled.

错误报告 - SQL 错误:启用自动提交时无法提交。

Note: I used SQL developer so not sure about other IDEs

注意:我使用 SQL developer 所以不确定其他 IDE