跳至主要内容

安裝

MacOS

Homebrew以及dmg安裝包進行安裝都可以,不過 Homebrew 跟 dmg 圖形化安裝還是有些區別,根據自己習慣任選其一即可,簡單介紹下兩種安裝方式的區別

PostgreSQLHomebrewdmg
安裝目錄/opt/homebrew/Cellar/postgresql@15/Library/PostgreSQL/15
數據目錄默认为:/opt/homebrew/var/postgresql@15默认为:/Library/PostgreSQL/15/data
用戶要求需要創建 postgres 用戶
默認用戶與執行安裝的用戶同名postgres
psql工具/命令行需要使用 -d 參數指定數據庫進入需要使用 -U 參數指定用戶進入,且需要使用密碼

Homebrew 安裝

安装 Homebrew

/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"

查找 PostgreSQL 安裝包

# 查找 postgresql 可用版本
brew search postgresql

# 輸出示例
==> Formulae
postgresql@10 postgresql@12 postgresql@14 postgresql@9.4 qt-postgresql
postgresql@11 postgresql@13 postgresql@15 postgresql@9.5 postgrest

安裝 PostgreSQL

# 安裝指定版本(推薦)
brew install postgresql@15

# 安裝默認版本
brew install postgresql

配置並啟動 PostgreSQL 服務

brew services start postgresql@15

添加環境變量

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

dmg 安裝

創建用戶

系統設置->用户與群組->添加帳戶,添加 postgres 帳戶

Cache Flow

下載 PostgreSQL

https://www.enterprisedb.com/downloads/postgres-postgresql-downloads

Cache Flow

開始安裝

選擇安裝位置及內容

Cache Flow Cache Flow Cache Flow Cache Flow Cache Flow Cache Flow

環境變量

echo 'export PATH="/Library/PostgreSQL/15/bin:$PATH"' >> ~/.zshrc
source ~/.zshrc