Postgresql -bash:psql:找不到命令

发布于 2024-11-26 08:17:46 字数 264 浏览 2 评论 0原文

我已经安装了 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(11

德意的啸 2024-12-03 08:18:06

以 root 身份运行 pg-wrapper 以使已安装的客户端和服务器程序可通过 PATH 访问,并将 SQL 手册页添加到手册页配置文件中。该实用程序在 postgrespro-std-14-client 包中提供。

/opt/pgpro/std-14/bin/pg-wrapper links update

有关如何处理可能的冲突的详细信息,请参阅说明。

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.

/opt/pgpro/std-14/bin/pg-wrapper links update

For details on how to handle possible conflicts, see this description.

九歌凝 2024-12-03 08:18:06

在Centos 7.9上安装后,我遇到了这个问题。我的发现结果如下:

  • 在 postgres 上安装到目录 /usr/pgsql-15
  • 执行 echo $PATH 产生 /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:

  • Installation on postgres went to to directory /usr/pgsql-15
  • Perfoming echo $PATH yielded /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

遥远的她 2024-12-03 08:18:05

有时,当 gem 安装命令由于各种原因找不到 pg 客户端库(例如 psql 不在路径中)时,我们会遇到此问题。

在这些情况下,为命令提供 pg_config 的路径可能会解决问题。

gem install pg -v 1.3.5 -- --with-pg-config=/path/to/pg_config

就我而言,我在安装 postgresql@12< 时遇到了类似的问题/code> 在 Rosetta 环境中使用 Homebrew。

以下命令解决了我的问题。

gem install pg -v 1.3.5 -- --with-pg-config=/usr/local/Homebrew/Cellar/postgresql@12/12.13/bin/pg_config

Sometimes we face this issue when the gem installation command doesn't find the pg client library for various reasons, such as if psql 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.

gem install pg -v 1.3.5 -- --with-pg-config=/usr/local/Homebrew/Cellar/postgresql@12/12.13/bin/pg_config
慵挽 2024-12-03 08:18:04

一定有两个原因,要么软件包未安装,要么 psql 未在 PATH 中定义,

简单的方法是在 /usr/bin 或 /usr/local/sbin/ 中创建链接,

首先找到该文件

sudo find / -name psql

,然后创建软链接

sudo ln -sf /opt/pgpro/1c-14/bin/psql /usr/local/sbin/psql

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

sudo find / -name psql

then create soft link

sudo ln -sf /opt/pgpro/1c-14/bin/psql /usr/local/sbin/psql
扎心 2024-12-03 08:18:03

如果您使用 Postgres Mac 应用程序(由 Heroku 提供)和 Bundler,您可以将 pg_config 直接在应用程序内添加到您的捆绑包中。

bundle config build.pg --with-pg-config=/Applications/Postgres.app/Contents/Versions/9.4/bin/pg_config

...然后再次运行捆绑包。

注意:首先使用以下命令检查版本。

ls /Applications/Postgres.app/Contents/Versions/

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.

bundle config build.pg --with-pg-config=/Applications/Postgres.app/Contents/Versions/9.4/bin/pg_config

...then run bundle again.

Note: check the version first using the following.

ls /Applications/Postgres.app/Contents/Versions/
吻泪 2024-12-03 08:18:02

检查 PostgreSQL 是否安装。

如果没有,您可以使用此命令在 ubuntu 中执行相同操作。

sudo apt update
sudo apt install postgresql postgresql-contrib

Check if PostgreSQL is installed or not.

If not you can do the same in ubuntu using this command.

sudo apt update
sudo apt install postgresql postgresql-contrib
尸血腥色 2024-12-03 08:18:00

如果您在 FedoraCentOS 上运行它,这对我有用(PostgreSQL 9.6):

在终端中:

$ sudo visudo -f /etc/sudoers

将以下文本修改为:

Defaults    secure_path = /sbin:/bin:/usr/sbin:/usr/bin

退出

Defaults    secure_path = /sbin:/bin:/usr/sbin:/usr/bin:/usr/pgsql-9.6/bin

,然后:

$ printenv PATH

$ sudo su postgres

$ psql

要退出 postgreSQL 终端,您需要输入数字:

$ \q

来源: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:

$ sudo visudo -f /etc/sudoers

modify the following text from:

Defaults    secure_path = /sbin:/bin:/usr/sbin:/usr/bin

to

Defaults    secure_path = /sbin:/bin:/usr/sbin:/usr/bin:/usr/pgsql-9.6/bin

exit, then:

$ printenv PATH

$ sudo su postgres

$ psql

To exit postgreSQL terminal, you need to digit:

$ \q

Source: https://serverfault.com/questions/541847/why-doesnt-sudo-know-where-psql-is#comment623883_541880

朕就是辣么酷 2024-12-03 08:17:59

这可能是由于 psql 不在 PATH 中

$ locate psql
/usr/lib/postgresql/9.6/bin/psql

然后在 /usr/bin 中创建一个链接

ln -s /usr/lib/postgresql/9.6/bin/psql /usr/bin/psql

然后尝试执行 psql 它应该可以工作。

It can be due to psql not being in PATH

$ locate psql
/usr/lib/postgresql/9.6/bin/psql

Then create a link in /usr/bin

ln -s /usr/lib/postgresql/9.6/bin/psql /usr/bin/psql

Then try to execute psql it should work.

南冥有猫 2024-12-03 08:17:57

问题是针对 Linux 的,但我在 Windows 机器上使用 git bash 也遇到了同样的问题。

我的 pqsql 安装在这里:
C:\Program Files\PostgreSQL\10\bin\psql.exe

您可以将 psql.exe 的位置添加到 Path 环境变量 作为
在另一个答案中进行了描述
,并在下面的屏幕截图中显示:

将 psql.exe 添加到您的 Path 环境变量

更改上述内容后,请关闭所有 cmd 和/或 bash 窗口,并重新打开它们(如评论@Ayush Shankar 中所述)。如果您使用的是 Visual Studio Code 等 IDE,请关闭并重新打开整个 IDE(如评论 @Somraj Chowdhury 中所述)

您可能需要使用以下命令更改默认日志记录用户。

psql -U postgres

这里 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 as
described in this other answer
, and shown in the screenshot below:

add psql.exe to your Path environment variable

After changing the above, please close all cmd and/or bash 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.

psql -U postgres

Here postgres is the username. Without -U, it will pick the windows loggedin user.

雨落星ぅ辰 2024-12-03 08:17:54

也许 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 the PATH for the postgres user.

一笔一画续写前缘 2024-12-03 08:17:52
export PATH=/usr/pgsql-9.2/bin:$PATH

程序可执行文件psql位于目录/usr/pgsql-9.2/bin中,默认情况下该目录不包含在路径中,因此我们必须告诉shell (终端)程序在哪里可以找到psql。大多数软件包安装时,都会添加到现有路径,例如 /usr/local/bin,但不会添加到此程序。

因此,如果我们不想每次执行程序时都键入程序的完整路径,则必须将程序的路径添加到 shell PATH 变量中。

此行通常应添加到 shell 启动脚本中,对于 bash shell,该脚本将位于文件 ~/.bashrc 中。

export PATH=/usr/pgsql-9.2/bin:$PATH

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 find psql. 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文