postgresql psql 将默认 statement_timeout 设置为 postgres 中的用户
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/24092463/
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
psql set default statement_timeout as a user in postgres
提问by Erik
I want to set a default statement_timeout
for my access to a postgres database. After configuring my environment variables, I now have it where psql
logs me on my preferred database and table. However, while I'm exploring several of tables in it, I'd like to have a statement timeout of around a minute. This can be done simply by typing SET statement_timeout TO '1min';
at the beginning of each session, but this is obnoxious to type every time. I don't have access to the server configuration nor would I want to change it. Ideally I could do something to the effect of alias psql='psql -c "SET statement_timeout TO '1min';"' except the
-c` flag of psql doesn't allow interactive input. Are there any nice solutions to this problem, or am I always doomed to set the timeout manually for each interactive session?
我想statement_timeout
为我对 postgres 数据库的访问设置默认值。配置我的环境变量后,我现在可以将它psql
记录在我首选的数据库和表上。但是,当我探索其中的几个表时,我希望语句超时大约为一分钟。这可以通过SET statement_timeout TO '1min';
在每次会话开始时简单地输入来完成,但是每次输入都令人讨厌。我无权访问服务器配置,也不想更改它。理想情况下,我可以alias psql='psql -c "SET statement_timeout TO '1min';"' except the
对 psql的-c` 标志不允许交互式输入的效果做一些事情。这个问题有什么好的解决方案,还是我总是注定要为每个交互式会话手动设置超时?
回答by khampson
You could use your .psqlrc
file (if you don't have one in your home directory, create it; if you're on Windows
instead of *nix
, the file is %APPDATA%\postgresql\psqlrc.confinstead) and set the following command:
你可以使用你的.psqlrc
文件(如果你没有一个在你的主目录,创建它;如果你是在Windows
代替*nix
,该文件是 %APPDATA%\ PostgreSQL的\ psqlrc.conf代替),并设置下面的命令:
set statement_timeout to 60000; commit;
That setting is in milliseconds, so that'll set the timeout to 1 minute. .psqlrc
isn't used with -c
nor -X
invocations of psql
, so that should allow you to get your interactive-mode timeout to 1 minute.
该设置以毫秒为单位,因此将超时设置为 1 分钟。.psqlrc
不与-c
或 的-X
调用一起使用psql
,因此应该允许您将交互模式超时设置为 1 分钟。
You can then execute the following in psql
to verify that the configuration has taken effect:
然后可以在里面执行以下命令psql
来验证配置是否生效:
show statement_timeout;