postgresql 安装了 Postgres.app 但它不起作用

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

Installed Postgres.app but it won't work

postgresqlherokupsql

提问by rodrigoalvesvieira

I just installed Postgres.appon my Mac but it won't work properly. I finished the installation and the app icon is on the menu bar and it says it is listening on port 5432, however, that is what happens if I try to run it from the command-line:

我刚刚在 Mac 上安装了Postgres.app,但它无法正常工作。我完成了安装,应用程序图标在菜单栏上,它说它正在侦听端口 5432,但是,如果我尝试从命令行运行它,就会发生这种情况:

~ $ psql
zsh: correct 'psql' to 'sl' [nyae]? n
zsh: command not found: psql

I had previously installed PostgreSQL via Homebrew but removed it before installing Postgres.app. I am running Mac OS X Lion.

我之前通过 Homebrew 安装了 PostgreSQL,但在安装 Postgres.app 之前将其删除。我正在运行 Mac OS X Lion。

I appreciate any help, I really want to have PostgreSQL running on my machine.

感谢您的帮助,我真的很想让 PostgreSQL 在我的机器上运行。

回答by mu is too short

The psqlbinary for Postgres.app is inside the application bundle and you'll have to add the appropriate directory to your PATH. From the fine manual:

psqlPostgres.app的二进制文件位于应用程序包中,您必须将适当的目录添加到您的PATH. 从精美的手册

Configure your $PATH

Postgres.app includes many command line tools. If you want to use them, you must configure the $PATHvariable.

If you are using bash(default shell on OS X), add the following line to ~/.bash_profile:

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

[...]

配置您的 $PATH

Postgres.app 包括许多命令行工具。如果要使用它们,则必须配置$PATH变量。

如果您使用的是bash(OS X 上的默认 shell),请将以下行添加到~/.bash_profile

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

[...]

So adjust your PATHsetting in your zsh config files to include the

因此,请PATH在 zsh 配置文件中调整您的设置以包含

Contents/Versions/latest/bin 

directory inside your Postgres.appbundle.

Postgres.app包内的目录。

回答by jamesmarkcook

I'm reading this as of April 2014 and the directory you must include in your path as far as my Postgres app is concerned is slightly different.

我在 2014 年 4 月阅读这篇文章,就我的 Postgres 应用程序而言,您必须包含在路径中的目录略有不同。

I had to include this:

我必须包括这个:

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

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

I can now run psql in my terminal.

我现在可以在我的终端中运行 psql。

回答by Alexander of Norway

What you should do it use /latest instead of version so you dont need to change it again when updating Postgres.

你应该怎么做,使用 /latest 而不是 version,这样你就不需要在更新 Postgres 时再次更改它。

How to: http://postgresapp.com/documentation/cli-tools.html

如何:http: //postgresapp.com/documentation/cli-tools.html

then run:

然后运行:

. ~/.bash_profile

to reload .bash_profile and update any functions you add.

重新加载 .bash_profile 并更新您添加的任何功能。

回答by Rodrigo Oliveira

On zsh shellyou have the modify .zshrc:

在 zsh shell 上,您可以修改.zshrc

PSQL_PATH="/Applications/Postgres.app/Contents/Versions/latest/bin"
PATH="$PATH:$PSQL_PATH"

On prompt:

在提示

exec $SHELL
which psql

回答by glevine

This might seem stupid, but I'm curious where you installed Postgres.app? As was suggested in mu is too short's answer, the documentation mentions adding /Applications/Postgres.app/Contents/MacOS/binto your path. However, this requires that you have installed Postgres.app in your /Applications/folder.

这可能看起来很愚蠢,但我很好奇你在哪里安装 Postgres.app?正如在mu is too short的回答中所建议的那样,文档提到添加/Applications/Postgres.app/Contents/MacOS/bin到您的路径中。但是,这需要您在/Applications/文件夹中安装 Postgres.app 。

Before trying any of the more complicated solutions you might have found on Stack Overflow, and other resources via Google, you should make sure you've installed Postgres.app to the right place. It may be as simple as moving Postgres.app to /Applications/since psqlwill be found in /Applications/Postgres.appbefore any other places.

在尝试您可能在 Stack Overflow 上找到的任何更复杂的解决方案以及通过 Google 找到的其他资源之前,您应该确保已将 Postgres.app 安装到正确的位置。这可能就像将 Postgres.app 移动到/Applications/因为psql/Applications/Postgres.app在任何其他地方之前找到一样简单。

Alternatively, you could use whatever path to Postgres.app you would like. So if you want it in your home directory, then you could use export PATH="~/Postgres.app/Contents/MacOS/bin:$PATH".

或者,您可以使用任何您想要的 Postgres.app 路径。所以如果你想在你的主目录中使用它,那么你可以使用export PATH="~/Postgres.app/Contents/MacOS/bin:$PATH".

HTH

HTH

回答by Caner ?akmak

I'm a previous Ubuntu user, now in OSX Trying to run the "which sql" and "pg_restore" commands directly from a terminal I opened didn't work. I clicked on the elephant icon and opened a terminal by "Open psql". Once I've quit from the psql console and written the commands in that terminal, they all worked.

我以前是 Ubuntu 用户,现在在 OSX 尝试直接从我打开的终端运行“which sql”和“pg_restore”命令没有用。我点击了大象图标并通过“打开 psql”打开了一个终端。一旦我从 psql 控制台退出并在该终端中编写了命令,它们都可以正常工作。

回答by Frank HN

On ZSH terminal, before trying the above solutions you have to install Postgres in the first place. While using HombrewFirst, hit,

在 ZSH 终端上,在尝试上述解决方案之前,您必须首先安装 Postgres。在使用HombrewFirst 时,点击,

brew install postgresThen check if it is installed by which psql

brew install postgres然后检查它是否安装了 which psql