博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
[转] Mac 下 PostgreSQL 的安装与使用
阅读量:6567 次
发布时间:2019-06-24

本文共 3091 字,大约阅读时间需要 10 分钟。

在 mac 下,可以利用  直接安装 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

?  /usr/local/Cellar/postgresql/9.5.1: 3,118 files, 35M

XXXdeMacBook-Air:chat-room XXX$ initdb /usr/local/var/postgres -E utf8

The files belonging to this database system will be owned by user "XXX".

This user must also own the server process.

 

The database cluster will be initialized with locale "zh_CN.UTF-8".

initdb: could not find suitable text search configuration for locale "zh_CN.UTF-8"

The default text search configuration will be set to "simple".

 

Data page checksums are disabled.

 

initdb: directory "/usr/local/var/postgres" exists but is not empty

If you want to create a new database system, either remove or empty

the directory "/usr/local/var/postgres" or run initdb

with an argument other than "/usr/local/var/postgres".

XXXdeMacBook-Air:chat-room XXX$ 

 

转载于:https://www.cnblogs.com/qiangxia/p/5308787.html

你可能感兴趣的文章
RequireJS进阶(二)
查看>>
我设计的网站的分布式架构
查看>>
linux extract rar files
查看>>
Knockout.Js官网学习(监控属性Observables)
查看>>
ORA-12514: TNS: 监听程序当前无法识别连接描述符中请求的服务解决
查看>>
azure之MSSQL服务性能测试
查看>>
Android BitmapFactory.Options
查看>>
前端构建:Less入了个门
查看>>
phonegap(cordova) 自己定义插件代码篇(三)----支付宝支付工具整合
查看>>
linux 批量进行:解压缩某一类压缩文件类型的文件
查看>>
激活modelsim se 10.4 时运行patch_dll.bat不能生成TXT
查看>>
Node.js中针对中文的查找和替换无效的解决方法
查看>>
如何查看Ubuntu下已安装包版本号
查看>>
VS2017 配置ImageMagick
查看>>
【Leetcode】Search in Rotated Sorted Array
查看>>
tomcat架构分析(valve源码导读)
查看>>
spring中InitializingBean接口使用理解(转)
查看>>
基于php5.5使用PHPMailer-5.2发送邮件
查看>>
InstallShield 2012 Spring新功能试用(16): Suite/Advanced UI 或 Advanced UI安装程序能在安装时进行输入合法性校验与反馈...
查看>>
C#面试宝典
查看>>