在 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. 内存管理tcmalloc

    tcmalloc https://code.google.com/p/gperftools/

  2. List Of All Machine Learning Sorted By Citation

    List Of All Machine Learning Sorted By Citation With > 300 citations 2013-10-10 See Citation Anal ...

  3. 基于springMVC+springSecurity3.x+Mybaits3.x的权限系统,,开放源码,支持开源

    原文地址:http://blog.csdn.net/mmm333zzz/article/details/16863543/

  4. 我的第一份vim程序

    vim太好用了吧!!!根本停不下来啊! devc++再见! /*==================================================================== ...

  5. WordPress wp-admin/includes/post.php脚本安全漏洞

    漏洞名称: WordPress wp-admin/includes/post.php脚本安全漏洞 CNNVD编号: CNNVD-201309-168 发布时间: 2013-09-13 更新时间: 20 ...

  6. 【转】Android:Bluetooth 的打开和关闭--不错

    原文网址:http://www.ifeegoo.com/android-turn-on-and-turn-off-bluetooth.html 摘要:Android 中打开和关闭 Bluetooth ...

  7. [XenServer] XenServer修改IP 以及 root密码

     A.修改IP以及DNS 1. root用户登录console 2.输入命令获得UUID xe pif-list 3.利用UUID查看之前的IP,注意替换下面的1111111111 xe pif-pa ...

  8. leetcode 字符串分割对称

    public class Solution { public List<List<String>> partition(String s) { int len=s.length ...

  9. AXI总线

    AXI(Advanced eXtensible Interface)是一种总协议,该协议是ARM公司提出的AMBA(Advanced Microcontroller Bus Architecture) ...

  10. windows调用ubuntu下的sublimeText2环境搭建

    部署需求: windows: windows 7 32 sp1 32位: linux :ubuntu 12.04 LTS 64位: 环境: windows安装:xmanager 4 linux安装:g ...