为什么我不能将PostgreSQL添加到我的路径中?

时间:2013-11-17 04:58:46

标签: macos postgresql

升级到Mavericks后,PostgreSQL开始播放,只要我调用pg_restore而没有调用完整路径,就会显示此错误消息:

pg_restore: command not found

如果我指定它的完整路径,但这显然不是最佳的:

/Applications/Postgres93.app/Contents/MacOS/bin/pg_restore --verbose --clean --no-acl --no-owner -h localhost -U steven -d db/testivate_development $file_path

要解决此问题,我尝试删除所有版本的PostgreSQL(使用Homebrew),然后安装Postgres.app。你可以确认这是这样的:

$ sudo find / -name pg_restore
/Applications/Postgres93.app/Contents/MacOS/bin/pg_restore
find: /dev/fd/3: Not a directory
find: /dev/fd/4: Not a directory

要将PostgreSQL添加到我的路径,我已尝试将以下每行添加到~/.bash_profile~/bashrc~/.zshrc,并在每次尝试后重新启动:

export PATH="/Applications/Postgres.app/Contents/MacOS/bin:$PATH"

...根据postgresapp.com文档,然后......

export PATH="/Applications/Postgres93.app/Contents/MacOS/bin:$PATH"

......根据以下评论。

这些都没有解决我的问题。

8 个答案:

答案 0 :(得分:11)

尝试将此行添加到.bash_profile:

export PATH="/Applications/Postgres93.app/Contents/MacOS/bin:$PATH"

并删除或注释掉之前的参考资料。

答案 1 :(得分:10)

我也有这个问题,所以不要在.bash_profile中将它添加到我的路径中:

export PATH="/Applications/Postgres93.app/Contents/MacOS/bin:$PATH"

这是推荐的内容,我添加了

export PATH="/Applications/Postgres.app/Contents/Versions/9.3/bin:$PATH"

代替。 &#9.3; 9.3'被您自己的版本取代。

我之后使用

验证了它
which psql

它找到了我的版本,而在之前没有报告任何内容。

然后我用

创建了一个测试数据库
createdb test

这就像一个魅力。

答案 2 :(得分:6)

如果您使用的是zsh,请在.zshrc中尝试此行,然后重新启动终端

export PATH=$PATH:/Applications/Postgres.app/Contents/Versions/9.4/bin

答案 3 :(得分:4)

其他人提供的export PATH=...示例应该是您问题的解决方案。由于它不起作用,您将不得不调试与PostgreSQL无关的shell问题。

首先,执行which pg_restore以查看您的路径中是否存在另一个名为pg_restore的文件,这会让您感到困惑。如果没有找到任何内容,which通常不提供输出而不是有用的错误,否则它将打印它找到的路径。例如,您可能会在/usr/local/bin中找到PostgreSQL的旧安装。

如果这不起作用,请尝试从新she​​ll中echo $PATH。你在那里看到PostgreSQL二进制目录的路径吗?如果没有,则不会在shell dot-rc文件中设置$PATH。如果您将其添加到名为~/bashrc的文件中,则会出现这种情况,因为bash(1)实际上已读取~/.bashrc。注意额外的点!我怀疑这个是你的实际问题。

如果结果不是问题,您可以(重新)使用source ~/.bashrc将rc文件读入当前会话。同样,echo $PATH如果仍然不包含路径,则dot-rc文件包含一个错误,并且不会执行更新$PATH的部分。您可以bash --verbose ~/.bashrc运行它,并且您将看到每个命令正在执行。失败的命令应该是显示的最后一个。 (请注意,当您使用bash运行脚本时,它不会在当前shell中设置变量。)

答案 4 :(得分:4)

您需要在bash_profile中添加路径

  

nano~ / .bash_profile

添加此行(我的postgres版本为9.1):

  

export PATH = $ PATH:/Library/PostgreSQL/9.1/bin /

答案 5 :(得分:0)

在带有PostgreSQL 9.6.0.0的macOS Sierra 10.12.1上

/Applications/Postgres.app/Contents/MacOS/Postgres

Postgres是二进制文件。

答案 6 :(得分:0)

在我的macOS上,Postgre 9.6安装在

/Library/PostgreSQL/9.6

答案 7 :(得分:0)

在macOS High Sierra 10.13.2和PostgreSQL 9.6上它对我有用:

export PATH=$PATH:/Library/PostgreSQL/9.6/bin:$PATH
相关问题