Mac上使用homebrew安装PostgreSql

//安装
$ brew install postgresql -v
//初始化数据库
$ initdb /usr/local/var/postgres -E utf8
//配置开机启动
$ mkdir -p ~/Library/LaunchAgents   //若无此文件夹则新建
$ cp /usr/local/Cellar/postgresql/9.6.1/homebrew.mxcl.postgresql.plist ~/Library/LaunchAgents/
$ launchctl load -w ~/Library/LaunchAgents/homebrew.mxcl.postgresql.plist
//手动启动
$ pg_ctl -D /usr/local/var/postgres -l /usr/local/var/postgres/server.log start
//查看状态
pg_ctl -D /usr/local/var/postgres -l /usr/local/var/postgres/server.log status
//停止
$ pg_ctl -D /usr/local/var/postgres -l /usr/local/var/postgres/server.log stop -s -m fast
//创建一个用户名为postgres的用户,回车输入2次用户密码(例密码为 root)
createuser postgres -P
//创建一个用户名为animal_dev的用户,回车输入2次用户密码(例密码为 animal_dev)
createuser animal_dev -P
//创建一个用户名为animal_prod的用户,回车输入2次用户密码(例密码为 animal_prod)
createuser animal_prod -P

使用dataGrip连接数据库
Mac上使用homebrew安装PostgreSql_第1张图片

CREATE SCHEMA animal_dev AUTHORIZATION animal_dev;
GRANT ALL ON SCHEMA animal_dev TO animal_dev;

CREATE TABLE fud_test (
  id serial primary key,
  description CHARACTER VARYING(1024)
);
ALTER table fud_test owner to animal_dev;

--------------------------------------------------------------

CREATE SCHEMA animal_prod AUTHORIZATION animal_prod;
GRANT ALL ON SCHEMA animal_prod TO animal_prod;

CREATE TABLE fud_test (
  id serial primary key,
  description CHARACTER VARYING(1024)
);
ALTER table fud_test owner to animal_prod;

你可能感兴趣的:(无头无尾)