当前位置: 首页 > ds >正文

macOS 安装 PostgreSQL

在这里插入图片描述

文章目录

    • 安装
      • 安装信息
    • 验证
    • GUI 工具下载


安装

最简单的方式是通过 brew 安装

brew install postgresql@17

该版本在 brew 上的详情页:https://formulae.brew.sh/formula/postgresql@17

你也可以根据需要,搜索 安装更新版本


如果你没有安装 brew,建议安装,参考:
https://blog.csdn.net/lovechris00/article/details/121613647


安装信息

你可以不必清理,因为包含安装地址、配置环境变量的语句,以及启动方法

% brew install postgresql@17
==> Downloading https://ghcr.io/v2/homebrew/core/postgresql/17/manifests/17.5
##################################################################################################################### 100.0%
==> Fetching dependencies for postgresql@17: lz4, xz, zstd, libunistring and gettext
==> Downloading https://ghcr.io/v2/homebrew/core/lz4/manifests/1.10.0-1
##################################################################################################################### 100.0%
==> Fetching lz4
==> Downloading https://ghcr.io/v2/homebrew/core/lz4/blobs/sha256:5bd143b7b784989e549637ea4e484af85ba481e640dde69bc35f3843ae
##################################################################################################################### 100.0%
==> Downloading https://ghcr.io/v2/homebrew/core/xz/manifests/5.8.1
##################################################################################################################### 100.0%
==> Fetching xz
==> Downloading https://ghcr.io/v2/homebrew/core/xz/blobs/sha256:dcd7823f2624cbcd08f55c232097a79300c7d76ab5969004db1a4785c6c
##################################################################################################################### 100.0%
==> Downloading https://ghcr.io/v2/homebrew/core/zstd/manifests/1.5.7
##################################################################################################################### 100.0%
==> Fetching zstd
==> Downloading https://ghcr.io/v2/homebrew/core/zstd/blobs/sha256:b039c851ef22617804576274872c33727ebb3a0b5e0db2ab62e0d8a97
##################################################################################################################### 100.0%
==> Downloading https://ghcr.io/v2/homebrew/core/libunistring/manifests/1.3
##################################################################################################################### 100.0%
==> Fetching libunistring
==> Downloading https://ghcr.io/v2/homebrew/core/libunistring/blobs/sha256:3cd26bae2d5fcf61294f14c18e5e7ec773a59ed1bf710fb92
##################################################################################################################### 100.0%
==> Downloading https://ghcr.io/v2/homebrew/core/gettext/manifests/0.25
##################################################################################################################### 100.0%
==> Fetching gettext
==> Downloading https://ghcr.io/v2/homebrew/core/gettext/blobs/sha256:8dba9424a9409d3ba085acccfd8c88c196e31e31944c32c1d811cf
##################################################################################################################### 100.0%
==> Fetching postgresql@17
==> Downloading https://ghcr.io/v2/homebrew/core/postgresql/17/blobs/sha256:2c9bea8ba80e55662401b8fdb3895162395c552980bf06b0
##################################################################################################################### 100.0%
==> Installing dependencies for postgresql@17: lz4, xz, zstd, libunistring and gettext
==> Installing postgresql@17 dependency: lz4
==> Downloading https://ghcr.io/v2/homebrew/core/lz4/manifests/1.10.0-1
Already downloaded: /Users/es/Library/Caches/Homebrew/downloads/8e11e90eb21a06e0f199af9d80e011e3693c77dd353b2477579d95c8471a5802--lz4-1.10.0-1.bottle_manifest.json
==> Pouring lz4--1.10.0.arm64_sequoia.bottle.1.tar.gz
🍺  /opt/homebrew/Cellar/lz4/1.10.0: 24 files, 713.5KB
==> Installing postgresql@17 dependency: xz
==> Downloading https://ghcr.io/v2/homebrew/core/xz/manifests/5.8.1
Already downloaded: /Users/es/Library/Caches/Homebrew/downloads/86a115cc1d43ff8a480fd907f812e70a403e1675d8a7223f61bbb08cbd2adc27--xz-5.8.1.bottle_manifest.json
==> Pouring xz--5.8.1.arm64_sequoia.bottle.tar.gz
🍺  /opt/homebrew/Cellar/xz/5.8.1: 96 files, 2.5MB
==> Installing postgresql@17 dependency: zstd
==> Downloading https://ghcr.io/v2/homebrew/core/zstd/manifests/1.5.7
Already downloaded: /Users/es/Library/Caches/Homebrew/downloads/596a67b1677f62a8e24e6fdfa7c879891221cb8261242f4355fb4deff1a2ec39--zstd-1.5.7.bottle_manifest.json
==> Pouring zstd--1.5.7.arm64_sequoia.bottle.tar.gz
🍺  /opt/homebrew/Cellar/zstd/1.5.7: 32 files, 2.2MB
==> Installing postgresql@17 dependency: libunistring
==> Downloading https://ghcr.io/v2/homebrew/core/libunistring/manifests/1.3
Already downloaded: /Users/es/Library/Caches/Homebrew/downloads/a570da63bc1839c7e217f203abd54d4d873ebd6b99f6e88994d0e79e2ebe987c--libunistring-1.3.bottle_manifest.json
==> Pouring libunistring--1.3.arm64_sequoia.bottle.tar.gz
🍺  /opt/homebrew/Cellar/libunistring/1.3: 59 files, 5.4MB
==> Installing postgresql@17 dependency: gettext
==> Downloading https://ghcr.io/v2/homebrew/core/gettext/manifests/0.25
Already downloaded: /Users/es/Library/Caches/Homebrew/downloads/344607fc5b91bb0c1287d07bb445cc40cc465a163a52e12eed3cc5cd60498f78--gettext-0.25.bottle_manifest.json
==> Pouring gettext--0.25.arm64_sequoia.bottle.tar.gz
🍺  /opt/homebrew/Cellar/gettext/0.25: 2,418 files, 27.7MB
==> Installing postgresql@17
==> Pouring postgresql@17--17.5.arm64_sequoia.bottle.tar.gz
==> Downloading https://formulae.brew.sh/api/formula.jws.json
==> /opt/homebrew/Cellar/postgresql@17/17.5/bin/initdb --locale=C -E UTF-8 /opt/homebrew/var/postgresql@17
==> Caveats
This formula has created a default database cluster with:initdb --locale=C -E UTF-8 /opt/homebrew/var/postgresql@17When uninstalling, some dead symlinks are left behind so you may want to run:brew cleanup --prune-prefixpostgresql@17 is keg-only, which means it was not symlinked into /opt/homebrew,
because this is an alternate version of another formula.If you need to have postgresql@17 first in your PATH, run:echo 'export PATH="/opt/homebrew/opt/postgresql@17/bin:$PATH"' >> ~/.zshrcFor compilers to find postgresql@17 you may need to set:export LDFLAGS="-L/opt/homebrew/opt/postgresql@17/lib"export CPPFLAGS="-I/opt/homebrew/opt/postgresql@17/include"To start postgresql@17 now and restart at login:brew services start postgresql@17
Or, if you don't want/need a background service you can just run:LC_ALL="C" /opt/homebrew/opt/postgresql@17/bin/postgres -D /opt/homebrew/var/postgresql@17
==> Summary
🍺  /opt/homebrew/Cellar/postgresql@17/17.5: 3,820 files, 72MB
==> Running `brew cleanup postgresql@17`...
Disable this behaviour by setting HOMEBREW_NO_INSTALL_CLEANUP.
Hide these hints with HOMEBREW_NO_ENV_HINTS (see `man brew`).

我在 ./zshrc 中配置下面环境变量:

export PATH="/opt/homebrew/opt/postgresql@17/bin:$PATH" 
export LDFLAGS="-L/opt/homebrew/opt/postgresql@17/lib"
export CPPFLAGS="-I/opt/homebrew/opt/postgresql@17/include"

验证

查看是否安装成功:

psql --version

% psql --version
psql (PostgreSQL) 17.5 (Homebrew)

然后可以进行一系列启动等操作


GUI 工具下载

如果你要是用 GUI 连接查看信息,可以使用 PgAdmin、DBeaver 等客户端工具:

  • PgAdmin :https://www.pgadmin.org/download/
  • DBeaver : https://dbeaver.io
  • macOS 下的数据库客户端工具
    https://blog.csdn.net/lovechris00/article/details/118418864

http://www.xdnf.cn/news/8433.html

相关文章:

  • 基于大模型的股骨干骨折全周期预测与诊疗方案研究报告
  • 可视化大屏全屏后重载echarts图表
  • JUC并发编程1
  • MyBatis 笔记:parameterType、resultType 与 resultMap 的区别详解
  • Android 网络全栈攻略(四)—— 从 OkHttp 拦截器来看 HTTP 协议一
  • 146. LRU Cache
  • Anthropic公司近日发布了两款新一代大型语言模型Claude Opus 4与Claude Sonnet 4
  • 矩阵:线性代数在AI大模型中的核心支柱
  • 深入解析MySQL中的HAVING关键字:从入门到实战
  • Docker 与 Kubernetes 部署 RabbitMQ 集群(二)
  • C++ 忘掉std::cout吧,fmt和spdlog的结合
  • 达梦数据库-报错-01-[-3205]:全文索引词库加载出错
  • paddle 打包代码 ocr
  • 国产高云FPGA实现MIPI视频解码+图像缩放,基于OV5647摄像头,提供Gowin工程源码和技术支持
  • 04-jenkins学习之旅-java后端项目部署实践
  • 攻略生成模块
  • python邮件地址检验 2024年信息素养大赛复赛/决赛真题 小学组/初中组 python编程挑战赛 真题详细解析
  • C++---vector模拟实现
  • 黑马点评-实现安全秒杀优惠券(使并发一人一单,防止并发超卖)
  • Java桌面应用开发详解:自制截图工具从设计到打包的全流程【附源码与演示】
  • LVS + Keepalived + Nginx 高可用负载均衡系统实验
  • 详解Mysql的 Binlog、UndoLog 和 RedoLog
  • 「金融证券行业」 如何搭建自己的研发智能管理体系?
  • Linux 操作文本文件列数据的常用命令
  • @Column 注解属性详解
  • 【Nature子刊聚焦:超构表面多维调控与AI驱动的设计革命 ——2024-2025年超构表面领域突破性进展速览 】
  • 职坐标解析物联网协议与传感器技术实战应用
  • MuJoCo安装记录
  • 一个基于 ESP-IDF 的 RPC over UDP 示例
  • 2025 最新 Redis 面试题大全