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

问题描述 投票:45回答:4

Official page没有提到这种情况。但是许多用户只需要没有本地数据库的psql(我在AWS上有它)。 Brew没有psql

macos postgresql psql macos-sierra
4个回答
29
投票

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

所以获取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

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

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

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

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

$ brew tap homebrew/services

......你会得到这个功能。有关Homebrew Services的更多信息,请阅读this excellent blog post that explains how it works


132
投票

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

brew install libpq

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

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

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

7
投票

libpq 11.2 MacOS&zsh或bash

下面的工作

  1. 安装libpq
brew install libpq
  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

0
投票

你可以试试brew install postgresql

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

© www.soinside.com 2019 - 2024. All rights reserved.