psql将默认statement_timeout设置为postgres中的用户 [英] psql set default statement_timeout as a user in postgres

查看:781
本文介绍了psql将默认statement_timeout设置为postgres中的用户的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想为访问postgres数据库设置默认的 statement_timeout 。配置完环境变量之后,现在可以在 psql 将其登录到首选数据库和表的地方。但是,在浏览其中的几个表时,我希望语句的超时时间大约为一分钟。只需在每个会话开始时输入 SET statement_timeout TO'1min'; 即可完成此操作,但是每次键入都令人讨厌。我无权访问服务器配置,也不想更改它。理想情况下,我可以采取以下措施来实现 alias psql ='psql -c SET statement_timeout TO'1min';',但psql的 -c`标志不会允许交互式输入。是否有解决此问题的好方法,还是我总是注定要为每个交互式会话手动设置超时?

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?

推荐答案

您可以使用您的 .psqlrc 文件(如果主目录中没有该文件,请创建该文件;如果您使用的是 Windows 而不是 * nix ,文件是%APPDATA%\postgresql\psqlrc.conf ),并设置以下命令:

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.conf instead) and set the following command:

set statement_timeout to 60000; commit;

该设置以毫秒为单位,因此将超时设置为1分钟。 .psqlrc 不与 -c -X psql 的调用,因此应该使您的交互模式超时达到1分钟。

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.

您然后可以在 psql 中执行以下命令,以验证配置已生效:

You can then execute the following in psql to verify that the configuration has taken effect:

show statement_timeout;

这篇关于psql将默认statement_timeout设置为postgres中的用户的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆