Postgresql -bash:psql:找不到命令
我已经安装了 PostgreSQL 并且运行正常。但是,当我恢复备份时,出现错误 -bash: psql: command not find
:
[root@server1 ~]# su postgres
[postgres@server1 root]$ psql -f all.sql
bash: psql: command not found
[postgres@server1 root]$
我做错了什么?
I have installed PostgreSQL and it is working ok. However, when I went to restore a backup I got the error -bash: psql: command not found
:
[root@server1 ~]# su postgres
[postgres@server1 root]$ psql -f all.sql
bash: psql: command not found
[postgres@server1 root]$
What have I done wrong?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(11)
以 root 身份运行 pg-wrapper 以使已安装的客户端和服务器程序可通过 PATH 访问,并将 SQL 手册页添加到手册页配置文件中。该实用程序在 postgrespro-std-14-client 包中提供。
有关如何处理可能的冲突的详细信息,请参阅此说明。
Run pg-wrapper as root to make the installed client and server programs available via PATH and add SQL man pages to the man page configuration file. This utility is provided in the postgrespro-std-14-client package.
For details on how to handle possible conflicts, see this description.
在Centos 7.9上安装后,我遇到了这个问题。我的发现结果如下:
/usr/pgsql-15
/sbin:/bin:/usr/sbin:/usr/bin< /code>
从上面路径的输出中,您意识到 postgresql 安装目录不在 PATH 中。
解决方案
将
/usr/pgsql-15
添加到 ~/.basr_profile 用户文件的 PATH 中,如下所示:PATH=$PATH:/usr/pgsql-15/bin
导出路径
After doing an installation on Centos 7.9, I encountered this problem. My finding yielded the following:
/usr/pgsql-15
/sbin:/bin:/usr/sbin:/usr/bin
From the output of path above you realise postgresql installation directory is not in PATH.
Resolution
Add
/usr/pgsql-15
to PATH on your ~/.basr_profile user file as below:PATH=$PATH:/usr/pgsql-15/bin
export PATH
有时,当 gem 安装命令由于各种原因找不到
pg
客户端库(例如psql
不在路径中)时,我们会遇到此问题。在这些情况下,为命令提供 pg_config 的路径可能会解决问题。
gem install pg -v 1.3.5 -- --with-pg-config=/path/to/pg_config
就我而言,我在安装
postgresql@12< 时遇到了类似的问题/code> 在 Rosetta 环境中使用 Homebrew。
以下命令解决了我的问题。
Sometimes we face this issue when the gem installation command doesn't find the
pg
client library for various reasons, such as ifpsql
is not in the path.In those cases, providing the command with the path to
pg_config
may fix the issue.gem install pg -v 1.3.5 -- --with-pg-config=/path/to/pg_config
In my case, I faced a similar issue when I installed
postgresql@12
with Homebrew in the Rosetta environment.Following command solved the issue in my case.
一定有两个原因,要么软件包未安装,要么 psql 未在 PATH 中定义,
简单的方法是在 /usr/bin 或 /usr/local/sbin/ 中创建链接,
首先找到该文件
,然后创建软链接
there must be two reasons for this either the package is not install or psql is not defined in the PATH
the simple way is to create a link within the /usr/bin or /usr/local/sbin/
First find the the file
then create soft link
如果您使用 Postgres Mac 应用程序(由 Heroku 提供)和 Bundler,您可以将 pg_config 直接在应用程序内添加到您的捆绑包中。
...然后再次运行捆绑包。
注意:首先使用以下命令检查版本。
If you are using the Postgres Mac app (by Heroku) and Bundler, you can add the pg_config directly inside the app, to your bundle.
...then run bundle again.
Note: check the version first using the following.
检查 PostgreSQL 是否安装。
如果没有,您可以使用此命令在 ubuntu 中执行相同操作。
Check if PostgreSQL is installed or not.
If not you can do the same in ubuntu using this command.
如果您在 Fedora 或 CentOS 上运行它,这对我有用(PostgreSQL 9.6):
在终端中:
将以下文本修改为:
退出
,然后:
要退出 postgreSQL 终端,您需要输入数字:
来源:https://serverfault.com/questions/541847/why-doesnt-sudo-知道 psql-is#comment623883_541880
In case you are running it on Fedora or CentOS, this is what worked for me (PostgreSQL 9.6):
In terminal:
modify the following text from:
to
exit, then:
To exit postgreSQL terminal, you need to digit:
Source: https://serverfault.com/questions/541847/why-doesnt-sudo-know-where-psql-is#comment623883_541880
这可能是由于 psql 不在 PATH 中
然后在 /usr/bin 中创建一个链接
然后尝试执行 psql 它应该可以工作。
It can be due to psql not being in PATH
Then create a link in /usr/bin
Then try to execute psql it should work.
问题是针对 Linux 的,但我在 Windows 机器上使用 git bash 也遇到了同样的问题。
我的 pqsql 安装在这里:
C:\Program Files\PostgreSQL\10\bin\psql.exe
您可以将
psql.exe
的位置添加到 Path 环境变量 作为在另一个答案中进行了描述,并在下面的屏幕截图中显示:
更改上述内容后,请关闭所有
cmd
和/或 bash 窗口,并重新打开它们(如评论@Ayush Shankar 中所述)。如果您使用的是 Visual Studio Code 等 IDE,请关闭并重新打开整个 IDE(如评论 @Somraj Chowdhury 中所述)您可能需要使用以下命令更改默认日志记录用户。
这里
postgres
是用户名。如果没有-U
,它将选择 Windows 登录用户。The question is for linux but I had the same issue with git bash on my Windows machine.
My pqsql is installed here:
C:\Program Files\PostgreSQL\10\bin\psql.exe
You can add the location of
psql.exe
to your Path environment variable asdescribed in this other answer, and shown in the screenshot below:
After changing the above, please close all
cmd
and/orbash
windows, and re-open them (as mentioned in the comments @Ayush Shankar). If you are using an IDE like Visual Studio Code, please close and re-open the entire IDE (as mentioned in the comments @Somraj Chowdhury)You might need to change default logging user using below command.
Here
postgres
is the username. Without-U
, it will pick the windows loggedin user.也许 psql 不在 postgres 用户的
PATH
中。使用 locate 命令查找 psql 的位置并确保其路径位于PATH 中
对于 postgres 用户。perhaps psql isn't in the
PATH
of the postgres user. Use the locate command to find where psql is and ensure that it's path is in thePATH
for the postgres user.程序可执行文件
psql
位于目录/usr/pgsql-9.2/bin
中,默认情况下该目录不包含在路径中,因此我们必须告诉shell (终端)程序在哪里可以找到psql
。大多数软件包安装时,都会添加到现有路径,例如 /usr/local/bin,但不会添加到此程序。因此,如果我们不想每次执行程序时都键入程序的完整路径,则必须将程序的路径添加到 shell PATH 变量中。
此行通常应添加到 shell 启动脚本中,对于 bash shell,该脚本将位于文件
~/.bashrc
中。The program executable
psql
is in the directory/usr/pgsql-9.2/bin
, and that directory is not included in the path by default, so we have to tell our shell (terminal) program where to findpsql
. When most packages are installed, they are added to an existing path, such as/usr/local/bin
, but not this program.So we have to add the program's path to the shell PATH variable if we do not want to have to type the complete path to the program every time we execute it.
This line should typically be added to theshell startup script, which for the bash shell will be in the file
~/.bashrc
.