在MacOSX上安装PostgreSQL并启动、登录、停止

环境

操作系统:Mac OS 10.10
软件包管理工具:brew 0.9.5
数据库管理系统:psql (PostgreSQL) 9.4.1

我经常在本地环境中使用PostgreSQL,但每次都要去搜索,这样会浪费时间,所以简单的做个备忘录。

安装。

brew install postgresql

看到输出结果时,发现已经完成了安装和启动。

==> Downloading https://homebrew.bintray.com/bottles/postgresql-9.4.1.yosemite.bottle.1.tar.gz
Already downloaded: /Library/Caches/Homebrew/postgresql-9.4.1.yosemite.bottle.1.tar.gz
==> Pouring postgresql-9.4.1.yosemite.bottle.1.tar.gz
==> Caveats
If builds of PostgreSQL 9 are failing and you have version 8.x installed,
you may need to remove the previous version first. See:
  https://github.com/Homebrew/homebrew/issues/2510

To migrate existing data from a previous major version (pre-9.4) of PostgreSQL, see:
  http://www.postgresql.org/docs/9.4/static/upgrading.html

To have launchd start postgresql at login:
    ln -sfv /usr/local/opt/postgresql/*.plist ~/Library/LaunchAgents
Then to load postgresql now:
    launchctl load ~/Library/LaunchAgents/homebrew.mxcl.postgresql.plist
Or, if you don't want/need launchctl, you can just run:
    postgres -D /usr/local/var/postgres
==> Summary
?  /usr/local/Cellar/postgresql/9.4.1: 2996 files, 40M


根据版本,好像可以这样做,但根据我的版本,似乎无法通过brew自行启动和停止。

启动

postgres -D /usr/local/var/postgres

停下来

pg_ctl -D /usr/local/var/postgres stop

控制台登录

psql 

退出控制台

\q

请参考以下内容:

使用psql的方法
http://ash.jp/db/pg_psql.htm

bannerAds