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

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

相关文章:

  • 基于BoxMOT的目标检测与跟踪全流程详解
  • HTA8127内置升压的77W单体声D类音频功放
  • 如何在 Windows 11 或 10 上通过 PowerShell 安装 Docker Desktop
  • 大腾智能 PDM 系统:全生命周期管理重塑制造企业数字化转型路径
  • 使用pip安装ptflops报错
  • Spring用到的设计模式
  • Day125 | 灵神 | 二叉树 | 二叉树中的第K大层和
  • 基于RT-Thread的STM32F4开发第七讲——RTC(硬件、软件)
  • C++构造函数和析构函数
  • 【2025最新】下载安装Anaconda
  • 数据共享中的库表交换怎么做?
  • 二、OpenCV图像处理-几何变换
  • 【CSS border-image】图片边框拉伸不变形,css边框属性,用图片打造个性化边框
  • Docker 与 Kubernetes 部署 RabbitMQ 集群(一)
  • el-table控制type=“expand“展开列 根据条件显示或隐藏展开按钮
  • 什么是DAQ采集卡?它的优势有哪些?
  • 【PINN】DeepXDE学习训练营(32)——pinn_forward-fractional_diffusion_1d.py
  • ES6 新增 API 方法
  • 【通用智能体】Intelligent Internet Agent (II-Agent):面向复杂网络任务的智能体系统深度解析
  • Go语言中为什么map、slice、channel需要var之后还要make一下?
  • 网站备案快吗/深圳推广公司哪家最好
  • 武汉专业建站网/微软bing搜索引擎
  • 织梦手机网站怎么仿制/2021小学生新闻摘抄
  • 深圳网站建设61916/青岛网站关键词排名优化
  • 怎么授权小说做游戏网站/建站模板哪个好
  • 商务网站开发的基本流程/互联网品牌宣传推广服务公司