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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-21 00:44:58  来源:igfitidea点击:

customize pager in psql

postgresqlcommand-linepsqlpager

提问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 psqlin 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 LESSin 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 psqlmanual:

精美的psql手册

\pset option [ value ]
[...]
pager
Controls use of a pager program for query and psql help output. If the environment variable PAGERis set, the output is piped to the specified program. Otherwise a platform-dependent default (such as more) is used.

When the pageroption 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 psqlprompt:

所以你可以从psql提示中说:

psql> \pset pager off

to turn the pager off. If you want this to always apply, you can add \pset pager offto your ~/.psqlrcfile.

关闭寻呼机。如果您希望它始终适用,您可以添加\pset pager off到您的~/.psqlrc文件中。

You can also use \?from the psqlprompt 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 实用程序或永久设置中进行临时更改。