PostgreSQL有两种安装方式,使用命令行安装没有用户界面,使用官网安装包安装有用户界面,操作也比较简单。
一、官网安装
官网:https://www.postgresql.org/download/macosx/
二、Homebrew安装
(安装 homebrew可以参考homebrew安装教程安装,homebrew是macOS上很有用的软件包管理工具。)
1. 使用homebrew安装
brew install postgresql
2. 安装成功后有一些有用的提示
This formula has created a default database cluster with:
initdb --locale=C -E UTF-8 /opt/homebrew/var/postgresql@14
For more details, read:
https://www.postgresql.org/docs/14/app-initdb.html
To start postgresql@14 now and restart at login:
brew services start postgresql@14
Or, if you don't want/need a background service you can just run:
/opt/homebrew/opt/postgresql@14/bin/postgres -D /opt/homebrew/var/postgresql@14
Summary
🍺 /opt/homebrew/Cellar/postgresql@14/14.10_1: 3,317 files, 45.4MB
Running `brew cleanup postgresql@14`...
Disable this behaviour by setting HOMEBREW_NO_INSTALL_CLEANUP.
Hide these hints with HOMEBREW_NO_ENV_HINTS (see `man brew`).
3. 查找数据库集群目录
这时候,homebrew安装完后的信息就非常重要了!我们可以看到,它告诉我们它已经提前创建了一个默认的数据库集群,并且告诉了我们位置:
This formula has created a default database cluster with: initdb --locale=C -E UTF-8 /opt/homebrew/var/postgresql@14
4. 复制粘贴数据库集群的位置,然后启动数据库
pg_ctl start -D <database cluster directory>
Reference:
https://mp.weixin.qq.com/s?__biz=MzA4OTk4NDg3OA==&mid=2652256521&idx=1&sn=2e10d71f12f5a1c660be4adda3728fc4&chksm=8bf00308bc878a1ea57c3a7f00a3cdf14d834dfe4b738f1d97755f1c1297d51c6bfa292c3148&scene=27
网友评论