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

给你一囗甜甜゛ 提交于 2020-01-31 04:48:25

问题


I am using postgres 9.5. How can I check if auto commit is on or off? I tried SHOW AUTOCOMMIT where I got ERROR: unrecognized configuration parameter "autocommit" then I did a \set autocommit off and then SHOW AUTOCOMMIT gives 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?


回答1:


According to this Dustin 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).




回答2:


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.

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



来源:https://stackoverflow.com/questions/41298283/how-to-check-if-autocommit-is-on-or-not-postgres-psql

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!