postgresql 在 psql 中自定义寻呼机
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/14474138/
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
customize pager in psql
提问by halloleo
When I use psql
, the command line tool of PostgreSQL, in interactive mode, it lists data as paginated output.
当我psql
在交互模式下使用PostgreSQL 的命令行工具时,它会将数据列为分页输出。
However, because I use psql
in a terminal application which can handle long outputs itself, I rather would like to get the whole output without the paginating with the annoying --more--
line.
但是,因为我psql
在一个可以处理长输出的终端应用程序中使用,所以我宁愿获得整个输出而不用烦人的--more--
行进行分页。
Is there any way to customise the paging behavior in psql
? I tried to set LESS
in the surrounding shell environment to cat
, but this din't help.
有没有办法自定义分页行为psql
?我试图LESS
在周围的 shell 环境中设置为cat
,但这没有帮助。
Any suggestions?
有什么建议?
回答by mu is too short
From the fine psql
manual:
\pset option [ value ]
[...]pager
Controls use of a pager program for query and psql help output. If the environment variablePAGER
is set, the output is piped to the specified program. Otherwise a platform-dependent default (such asmore
) is used.When the
pager
option is off, the pager program is not used. When the pager option is on, the pager is used when appropriate
\pset option [ value ]
[...]pager
控制用于查询和 psql 帮助输出的寻呼程序的使用。如果PAGER
设置了环境变量 ,则输出将通过管道传输到指定的程序。否则将使用依赖于平台的默认值(例如more
)。当该
pager
选项关闭时,不使用寻呼程序。当寻呼机选项打开时,在适当的时候使用寻呼机
So you can say this from the psql
prompt:
所以你可以从psql
提示中说:
psql> \pset pager off
to turn the pager off. If you want this to always apply, you can add \pset pager off
to your ~/.psqlrc
file.
关闭寻呼机。如果您希望它始终适用,您可以添加\pset pager off
到您的~/.psqlrc
文件中。
You can also use \?
from the psql
prompt to get a quick summary of the special commands at your disposal.
您还可以使用\?
从psql
提示中获取您可以使用的特殊命令的快速摘要。
回答by spikendu
For completeness we might mention that for a one-off or to use as a setting in one of your scripts... (and as mentioned by "mu", see the psql --help (manual))
为了完整起见,我们可能会提到一次性或用作您的脚本之一中的设置......(正如“mu”所提到的,请参阅 psql --help(手册))
As a command in a script
作为脚本中的命令
psql --pset=pager-off -c "
<sqlCommand>
"<databaseName>
psql --pset=pager-off -c "
<sqlCommand>
"<databaseName>
From your commandline
从你的命令行
psql --pset=pager=off
<databaseName>
psql --pset=pager=off
<databaseName>
This would be in effect for the single command only so it is most useful in a script.
这仅对单个命令有效,因此它在脚本中最有用。
You can use this method in lieu of making temporary changes within the psql utility or permanent settings via the init file (~/.psqlrc).
您可以使用此方法代替通过 init 文件 (~/.psqlrc) 在 psql 实用程序或永久设置中进行临时更改。