postgresql psql 客户端历史记录保存在哪里?(~/.psql_history 不存在!)

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/17924906/
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-09-11 00:19:16  来源:igfitidea点击:

Where is psql client history kept? (~/.psql_history non-existent!)

postgresqlpsql

提问by Bentley4

A password is visible in my psql prompt (by pushing up arrow to view previous inputted commands). So I would like to delete that entry from the psql client.

在我的 psql 提示中可以看到密码(通过向上推箭头查看以前输入的命令)。所以我想从 psql 客户端中删除该条目。

Other resources(1, 2) claim that psql client history is kept in is a ~/.psql_historyfile, however this file is simply not there. (it's not in .bash_historyeither)

其他资源(1, 2)声称 psql 客户端历史记录保存在一个~/.psql_history文件中,但是该文件根本不存在。(它不在.bash_history两者中)

So there must be another file where the history of psql prompt is kept, any ideas where?

所以必须有另一个文件保存 psql 提示的历史记录,任何想法在哪里?

I log in to my prompt like this sudo -u postgres psql my_db

我像这样登录我的提示 sudo -u postgres psql my_db

Note: I am working on Ubuntu 12.04

注意:我正在处理 Ubuntu 12.04

回答by a_horse_with_no_name

When you use:

当您使用:

sudo -u postgres psql my_db

you run psql as the (Linux) user postgres, therefor the .psql_historyfile is in the home directory of the postgres user (e.g. /home/postgres/.psql_history), not in the home directory of the user you originally logged in with.

您以 (Linux) 用户身份运行 psql postgres,因此该.psql_history文件位于 postgres 用户(例如/home/postgres/.psql_history)的主目录中,而不是您最初登录时使用的用户的主目录中。

In some installations, the location of the postgresuser's home directory is /var/lib/postgresql. You can check this by running:

在某些安装中,postgres用户主目录的位置是/var/lib/postgresql. 您可以通过运行来检查:

grep postgres /etc/passwd | cut -d ':' -f 6

回答by Daniel Vérité

The filename is given by an internal variable named HISTFILE. Technically it doesn't have to be ~/.psql_history.

文件名由名为 的内部变量给出 HISTFILE。从技术上讲,它不一定是~/.psql_history.

Check the ~/.psqlrcfile for an alternate setting. For example it might be:

检查~/.psqlrc文件以获取替代设置。例如它可能是:

\set HISTFILE ~/.psql_history- :DBNAME

\set HISTFILE ~/.psql_history- :DBNAME

as mentioned in the manualfor a per-database history file.

如每个数据库历史文件的手册中所述。

回答by SPRBRN

I have a server here (Amazon Linux AMI, Centos like) that has no postgres home folder. Still it remembers the history of psql. Using the locatecommand I found the history file located in /var/lib/pgsql93/.psql_history. On another machine it's in /var/lib/pgsql/. After editing this file, removing all relevant lines, the history was gone.

我这里有一台没有 postgres 主文件夹的服务器(Amazon Linux AMI、Centos 之类的)。它仍然记得 psql 的历史。使用该locate命令,我找到了位于/var/lib/pgsql93/.psql_history. 在另一台机器上它在/var/lib/pgsql/. 编辑此文件,删除所有相关行后,历史记录消失了。

When the locate command doesn't return results, use the command updatedbto create the database for the locate command. You cannot run these commands as user postgres btw.

当 locate 命令没有返回结果时,使用该命令updatedb为 locate 命令创建数据库。顺便说一句,您不能以 postgres 用户身份运行这些命令。

回答by melocoton

You need to modify /etc/passwd. Put the location of your pgsql folder on postgres line and try : grep postgres /etc/passwd | cut -d ':' -f 6

您需要修改 /etc/passwd.conf 文件。将 pgsql 文件夹的位置放在 postgres 行上并尝试: grep postgres /etc/passwd | cut -d ':' -f 6