postgresql 在 macOS 上没有完整 Postgres 的情况下安装 psql 的正确方法?

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

Correct way to install psql without full Postgres on macOS?

macospostgresqlpsqlmacos-sierra

提问by Vitaly Zdanevich

Official pagedo not mention such case. But many users need only psqlwithout a local database (I have it on AWS). Brew do not have psql.

官方页面没有提到这种情况。但是许多用户只需要psql没有本地数据库(我在 AWS 上有)。酿造没有psql

回答by PPS

You could also use homebrew to install libpq.

您也可以使用自制软件来安装 libpq。

brew install libpq

This would give you psql, pg_dump and a whole bunch of other client utilities without installing Postgres.

这将为您提供 psql、pg_dump 和一大堆其他客户端实用程序,而无需安装 Postgres。

You then add the installation directory to your path. In my case, the directory location is:

然后将安装目录添加到您的路径中。就我而言,目录位置是:

/usr/local/Cellar/libpq/10.3/bin

回答by Andrew Bobulsky

Homebrew only really has the postgresformula, and doesn't have any specific formula that only installs the psqltool.

Homebrew 只有真正具有postgres公式,并且没有任何仅安装该psql工具的特定公式。

So the "correct way" to get the psqlapplication is indeed to install the postgresformula, and you'll see toward the bottom of the "caveats" section that it doesn't actually run the database, it just puts the files on your system:

因此,获取psql应用程序的“正确方法”确实是安装postgres公式,您将在“警告”部分的底部看到它实际上并没有运行数据库,它只是将文件放在您的系统上:

$  brew install postgres
==> Downloading https://homebrew.bintray.com/bottles/postgresql-9.6.5.sierra.bottle.tar.gz
######################################################################## 100.0%
==> Pouring postgresql-9.6.5.sierra.bottle.tar.gz
==> /usr/local/Cellar/postgresql/9.6.5/bin/initdb /usr/local/var/postgres
==> Caveats
<snip>
To have launchd start postgresql now and restart at login:
  brew services start postgresql
Or, if you don't want/need a background service you can just run:
  pg_ctl -D /usr/local/var/postgres start
==> Summary
  /usr/local/Cellar/postgresql/9.6.5: 3,269 files, 36.7MB

Now you can use psqlto connect to remote Postgres servers, and won't be running a local one, although you could if you really wanted to.

现在您可以使用psql连接到远程 Postgres 服务器,并且不会运行本地服务器,尽管如果您真的想要,您也可以。

To verify that the local postgresdaemon isn't running, check your installed homebrew services:

要验证本地postgres守护程序没有运行,请检查您安装的自制服务:

$ brew services list
Name       Status  User Plist
mysql      stopped      
postgresql stopped      

If you don't have Homebrew Servicesinstalled, just

如果您没有安装Homebrew Services,只需

$ brew tap homebrew/services

...and you'll get this functionality. For more information on Homebrew Services, read this excellent blog post that explains how it works.

...您将获得此功能。有关Homebrew 服务的更多信息,请阅读这篇出色的博客文章,它解释了它是如何工作的

回答by C.K.

libpq 11.2
MacOS & zsh or bash

libpq 11.2
MacOS & zsh 或 bash

below works

下面的作品

  1. install libpq
  1. 安装 libpq
brew install libpq
  1. update PATH

    if use zsh:

    echo 'export PATH="/usr/local/opt/libpq/bin:$PATH"' >> ~/.zshrc
    source ~/.zshrc
    

    if use bash:

    echo 'export PATH="/usr/local/opt/libpq/bin:$PATH"' >> ~/.bash_profile
    source ~/.bash_profile
    
  1. 更新路径

    如果使用 zsh:

    echo 'export PATH="/usr/local/opt/libpq/bin:$PATH"' >> ~/.zshrc
    source ~/.zshrc
    

    如果使用 bash:

    echo 'export PATH="/usr/local/opt/libpq/bin:$PATH"' >> ~/.bash_profile
    source ~/.bash_profile
    

回答by Virak

Install libpq:

安装 libpq:

 brew install libpq

Then, create a symlink:

然后,创建一个符号链接:

ln -s /usr/local/opt/libpq/bin/psql /usr/local/bin/psql

Hope it helps.

希望能帮助到你。

回答by Josh Goebel

If you truly don't need postgresql then you don't even have to alter your path to use libra, just link libpq. The docs say the only reason it isn't is to avoid conflicts with the PostgreSQL package.

如果您真的不需要 postgresql,那么您甚至不必更改使用 libra 的路径,只需链接libpq. 文档说它不是的唯一原因是避免与 PostgreSQL 包发生冲突。

brew uninstall postgresql
brew install libpq
brew link --force libpq

回答by Saidur Rahman

You could try brew install postgresql

你可以试试 brew install postgresql

But this provides a nice GUI to manage your databases https://postgresapp.com

但这提供了一个很好的 GUI 来管理您的数据库https://postgresapp.com