在 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. C# 数据结构 基础 论述

    问题: 信息世界中,计算机是加工处理的信息的载体,在这个过程中面临着三个问题: 1.如何方便高效的组织数据 2.如何在计算机中存储数据(内存和外存) 3.如何对存储的数据进行高效的操作 目的: 我们都 ...

  2. css3实现钟表特效

    <!doctype html><html><head><meta http-equiv="Content-Type" content=&q ...

  3. applicationContext.xml详解 spring+mybatis+struts

    今天给大家详细解释一项关于Spring的applicationContext.xml文件,这对于初学者来说,应该是很有帮助的, 以下是详解Spring的applicationContext.xml文件 ...

  4. Web Adaptor重装配置时 提示已经配置成功的问题

    环境 ArcGIS 10.1/10.2/10.3 Windwos 8.1 Tomcat 7.0.5 问题描述 较早之前在本机上安装配置过一个10.2.1版本的ArcGIS产品,包括桌面.Server和 ...

  5. MySQL协议简单分析

     tcpdump -i eth0 -s0  -l -w - port 3306|strings|grep -i -E 'select|update|insert|delete|set' 

  6. python手记(31)

    #!/usr/bin/env python #-*- coding: utf-8 -*- import cv2 import numpy as np fn="test2.jpg" ...

  7. VS2013中直接浏览网页显示“无法显示此页”的可能原因

    今天在VS2013里面新建了一个空的web应用程序WebApplication1,然后新建了一个 WebForm1.aspx 直接浏览WebForm1.aspx后,网页直接显示: 在网上查询了写资料, ...

  8. wcf中的File-less Activation

    File-less Activation Although .svc files make it easy to expose WCF services, an even easier approac ...

  9. bzoj1455

    学习了一下可合并堆的一种写法——左偏树感觉左偏树是一种类似启发式的方法学习左偏树后这题就水过去了 ..] of longint; v:..] of boolean; i,n,m,x,y,f:longi ...

  10. Delphi 编写的Web Service

      一编写服务程序 第一步:File----->New----->Other------>WebServices----->Soap Server Application选择I ...