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

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.lryc.cn/news/2384821.html

相关文章:

  • 打破传统范式,线上 3D 画展彰显多元亮点
  • Linux系统:基础命令之 ls~pwd~cd
  • MuJoCo安装记录
  • 软件工程(八):UML类图的几种关系
  • python定时删除指定索引
  • 基于OAuth2-proxy和Keycloak为comfyui实现SSO
  • SmartSoftHelp 之 SQL Server 数据库安全备份与安全还原详解---深度优化版:SmartSoftHelp DeepCore XSuite
  • Spring 代理与 Redis 分布式锁冲突:一次锁释放异常的分析与解决
  • 【数据结构】队列的完整实现
  • 2025 全球优质 AI 产品深度测评:从通用工具到垂直领域的技术突围 —— 轻量聚合工具篇
  • Python爬虫实战:获取天气网最近一周北京的天气数据,为日常出行做参考
  • 根据YOLO数据集标签计算检测框内目标面积占比(YOLO7-10都适用)
  • Helm简介、安装、配置、使用!
  • LLM笔记(九)KV缓存(2)
  • 开发 前端搭建npm v11.4.0 is known not to run on Node.js v14.18.1.
  • LVS 负载均衡集群应用实战
  • MySQL——基本查询内置函数
  • Day34打卡 @浙大疏锦行
  • 【Jitsi Meet】(腾讯会议的平替)Docker安装Jitsi Meet指南-使用内网IP访问
  • AdGuard解锁高级版(Nightly)_v4.10.36 安卓去除手机APP广告
  • C++修炼:红黑树的模拟实现
  • 基于Python+YOLO模型的手势识别系统
  • 自制操作系统day10叠加处理
  • docker初学
  • ## Docker 中 Elasticsearch 启动失败:日志文件权限问题排查与解决
  • 鸿蒙Flutter实战:23-混合开发详解-3-源码模式引入
  • leetcode:2469. 温度转换(python3解法,数学相关算法题)
  • 【软件安装】Windows操作系统中安装mongodb数据库和mongo-shell工具
  • 跨域问题及其CORS解决方案:gin框架中配置跨域
  • 记共享元素动画导致的内存泄露