在 mac 下,可以利用 homebrew 直接安装 PostgreSQL:

1
brew install postgresql -v

稍等片刻,PostgreSQL 就安装完成。接下来就是初始数据库,在终端执行一下命令,初始配置 PostgreSQL:

1
initdb /usr/local/var/postgres -E utf8

上面指定 "/usr/local/var/postgres" 为 PostgreSQL 的配置数据存放目录,并且设置数据库数据编码是 utf8,更多配置信息可以 "initdb --help" 查看。

设成开机启动 PostgreSQL:

1
2
ln -sfv /usr/local/opt/postgresql/*.plist ~/Library/LaunchAgents
launchctl load ~/Library/LaunchAgents/homebrew.mxcl.postgresql.plist

启动 PostgreSQL:

1
pg_ctl -D /usr/local/var/postgres -l /usr/local/var/postgres/server.log start

关闭 PostgreSQL:

1
pg_ctl -D /usr/local/var/postgres stop -s -m fast

创建一个 PostgreSQL 用户

1
2
3
createuser username -P
#Enter password for new role:
#Enter it again:

上面的 username 是用户名,回车输入 2 次用户密码后即用户创建完成。更多用户创建信息可以 "createuser --help" 查看。

创建数据库

1
createdb dbname -O username -E UTF8 -e

上面创建了一个名为 dbname 的数据库,并指定 username 为改数据库的拥有者(owner),数据库的编码(encoding)是 UTF8,参数 "-e" 是指把数据库执行操作的命令显示出来。

更多数据库创建信息可以 "createdb --help" 查看。

连接数据库

1
psql -U username -d dbname -h 127.0.0.1

WARNING: enabling "trust" authentication for local connections

You can change this by editing pg_hba.conf or using the option -A, or

--auth-local and --auth-host, the next time you run initdb.

Success. You can now start the database server using:

/usr/local/Cellar/postgresql/9.5.1/bin/pg_ctl -D /usr/local/var/postgres -l logfile start

==> 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.0) of PostgreSQL, see:

http://www.postgresql.org/docs/9.5/static/upgrading.html

To migrate existing data from a previous minor version (9.0-9.4) of PosgresSQL, see:

http://www.postgresql.org/docs/9.5/static/pgupgrade.html

You will need your previous PostgreSQL installation from brew to perform `pg_upgrade`.

Do not run `brew cleanup postgresql` until you have performed the migration.

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

[转] Mac 下 PostgreSQL 的安装与使用的更多相关文章

  1. Mac 下 PostgreSQL 的安装与使用

    在 mac 下,可以利用 homebrew 直接安装 PostgreSQL: 1 brew install postgresql -v 稍等片刻,PostgreSQL 就安装完成.接下来就是初始数据库 ...

  2. mac下sublime text3安装SFTP及使用

    mac下sublime text3安装SFTP 1.shift+command+p进入控制面板 2.输入install进入程序安装界面选择需要安装的插件(SFTP) 3.直接进行安装(需要联网) 4. ...

  3. mac 下用 brew 安装mongodb

    转自:mac 下用 brew 安装mongodb 经过这位仁兄的文章指导,终于连上了mongodb. 启动mongo数据库,就是打开一个终端sudo mongod,然后打开另一个终端sudo mong ...

  4. mac下java的安装和升级以及相关环境设置

    安装:brew cask install java8 如果存在多个java,可以设置JAVA_HOME指定java版本 打开终端,执行/usr/libexec/java_home -V 查看MAC下J ...

  5. Mac下的mongodb安装

    mac下的mongodb安装主要有两种方式,一是手工安装,需在官网下载源文件,二是通过homebrew,至于homebrew不做介绍.既然是Mac系统下,我认为直接通过homebrew安装最好,省事还 ...

  6. mac下Spark的安装与使用

    每次接触一个新的知识之前我都抱有恐惧之心,因为总认为自己没有接触到的知识都很高大上,比如上篇介绍到的Hadoop的安装与使用与本篇要介绍的Spark,其实在自己真正琢磨以后才发现本以为高大上的知识其实 ...

  7. Mac下anaconda的安装和基本使用

    Mac下anaconda的安装和基本使用 安装 在conda官网下载安装conda. 打开terminal输入conda -V,回车显示conda的版本说明安装成功. 将conda更新到最新版本 co ...

  8. MAC下用homebrew安装及配置apache、php和mysql

    我们用到php运行环境的时候总喜欢用集成包,其实在mac下,用homebrew也可以很快的安装这些东西,配置也很简单. homebrew homebrew是mac下的一个包安装管理工具,使用非常简单方 ...

  9. CentOS 6.3下PostgreSQL 的安装与配置

    一.简介 PostgreSQL 是一种非常复杂的对象-关系型数据库管理系统(ORDBMS),也是目前功能最强大,特性最丰富和最复杂的自由软件数据库系统.有些特性甚至连商业数据库都不具备.这个起源于伯克 ...

随机推荐

  1. resolvconf: Error: /etc/resolv.conf isn't a symlink, not doing anything.

    一.问题出现的原因 resolv.conf默认是个软链接,resolvconf默认会检查resolv.conf不是软链接就报错 默认的情况是这样的: #ls -l /etc/resolv.conflr ...

  2. kernel编程规范

    1. 制表符8个空格2. 每行最长80字符3. 代码块的{放在首行,但是函数的{放在次行4. 只有一行的if块,不加{}5. 不在()前后加空格6. 正常关键字后加一个空格,if, switch, c ...

  3. [BZOJ 1502] [NOI2005] 月下柠檬树 【Simpson积分】

    题目链接: BZOJ - 1502 题目分析 这是我做的第一道 Simpson 积分的题目.Simpson 积分是一种用 (fl + 4*fmid + fr) / 6 * (r - l) 来拟合 fl ...

  4. attr

    今天用attr的时候忽然不知道html中没有的attribute可以不可以用该方法新增了, 查了appframework的文档,居然木有看出解答. 百度之,js原生的setAttribute当然是可以 ...

  5. Connect them

    zoj3204: 最小生成树,要求最小字典序的解. 用kruscal算法,先排序,输出的时候也要排序. /* zoj3204 解题思路: 赤裸裸的最小生成树.只是要求输出字典序最小的连接方案. 所以在 ...

  6. 【POJ3415】 Common Substrings(后缀数组|SAM)

    Common Substrings Description A substring of a string T is defined as: T(i, k)=TiTi+1...Ti+k-1, 1≤i≤ ...

  7. 【POJ1113】Wall(凸包)

    [题目] Description Once upon a time there was a greedy King who ordered his chief Architect to build a ...

  8. net.sf.json在处理json对象转换为普通java实体对象时的问题和解决方案

    我使用的net.sf.json是json-lib-2.4-jdk15.jar,把json对象转换为普通java实体对象时候有个问题,josn对象转换为java对象之后,json串里面的那几个小数点的值 ...

  9. R语言 多元线性回归分析

    #线性模型中有关函数#基本函数 a<-lm(模型公式,数据源) #anova(a)计算方差分析表#coef(a)提取模型系数#devinace(a)计算残差平方和#formula(a)提取模型公 ...

  10. lemon OA 下阶段工作安排

    lemon OA 下阶段工作安排 经验总结 lemon OA系统作为一个中型的java web系统,在架构上还是有着很好地可学习的地方.但是由于经验不足,过程比较迂回.如果真的有经验的话,应该可以做到 ...