psql:如何不将单个命令记录到历史记录中

psql: How do I not record a single command into history

在 bash 中有一个设置(通常默认情况下启用),使得任何以 space 开头的命令都不会记录到历史文件中。

psql 中有类似的东西吗?

所以这是可能的。

\set HISTCONTROL ignorespace 添加到您的 .psqlrc 文件。

那么当你在命令前加上 space 时,比如设置密码,它不会被添加到历史文件中。

来自manual

HISTCONTROL

If this variable is set to ignorespace, lines which begin with a space are not entered into the history list. If set to a value of ignoredups, lines matching the previous history line are not entered. A value of ignoreboth combines the two options. If unset, or if set to none (or any other value than those above), all lines read in interactive mode are saved on the history list.