使用homebrew安装

  ~ brew install postgresql
Updating Homebrew...
^C==> Downloading https://homebrew.bintray.com/bottles/postgresql-10.4.high_sierra
######################################################################## 100.0%
==> Pouring postgresql-10.4.high_sierra.bottle.tar.gz
==> /usr/local/Cellar/postgresql/10.4/bin/initdb /usr/local/var/postgres
==> Caveats
To migrate existing data from a previous major version of PostgreSQL run:
  brew postgresql-upgrade-database

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/10.4: 3,389 files, 39.2MB

启动服务可以使用

  brew postgresql-upgrade-database

或者

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

使用举例:

$ createdb exampledb
[keke.zhaokk@zkkMac ~]
$ psql exampledb
psql (9.6.1)
Type "help" for help.

exampledb=# create table users(id serial, name varchar(25));
CREATE TABLE
exampledb=# insert into users(name) values('keke');
INSERT 0 1
exampledb=# insert into users(name) values('xiayq');
INSERT 0 1
exampledb=# select * from users;
 id | name
----+-------
  1 | keke
  2 | xiayq
(2 rows)