PostgreSQL数据库是必须要掌握的数据库之一,如果使用Mac系统的安装postgresql有两种方式,一种是从官网下载图形化dmg安装包,另一种是使用Homebrew管理工具安装。搜索引擎能搜到很多教程,但是一些复制拼接的博客和年代久远的教程会给新手造成困扰。

本教程前提是已安装Homebrew,shell是zsh

一、安装启动

查找postgresql可用版本

brew search postgresql

安装PostgreSQL

# 安装指定版本(推荐)

brew install postgresql@15

# 安装默认版本

brew install postgresql

# 检查

psql -V 或者 psql --version

# 初始化数据库

initdb --locale=C -E UTF-8 /usr/local/var/postgres

# 添加环境变量

echo 'export PATH="/opt/homebrew/opt/postgresql@15/bin:$PATH"' >> ~/.zshrc

source ~/.zshrc

# 配置并启动PostgreSQL服务

brew services start postgresql@15

参考文章:

https://cloud.tencent.com/developer/article/2259801

https://bbs.huaweicloud.com/blogs/294285

精彩链接

评论可见,请评论后查看内容,谢谢!!!
 您阅读本篇文章共花了: