最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

Mac?OS上安裝PostgreSQL完整圖文教程

 更新時(shí)間:2026年01月11日 11:25:58   作者:yingjuxia.com  
這篇文章主要介紹了Mac?OS上安裝PostgreSQL的完整圖文教程,問文中通過代碼詳細(xì)介紹了如何設(shè)置密碼、允許遠(yuǎn)程連接、常用命令、備份與恢復(fù)、卸載以及常見問題解決方法,需要的朋友可以參考下

macOS 上安裝 PostgreSQL(完整圖文教程)

適用于 macOS 12+(Monterey / Ventura / Sonoma / Sequoia),支持 Apple Silicon(M1/M2/M3)Intel
推薦使用 Homebrew(最簡單、最常用)

一、推薦方式:使用 Homebrew 安裝(99% 用戶選這個(gè))

1. 安裝 Homebrew(如果還沒裝)

打開 終端(Terminal),粘貼運(yùn)行:

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

安裝過程會提示輸入密碼并按回車。

2. 安裝 PostgreSQL

brew install postgresql

自動(dòng)安裝最新穩(wěn)定版(如 PostgreSQL 17),并包含:

  • psql 命令行工具
  • pg_dump、createdb
  • pgAdmin 可選(后面教你裝)

3. 啟動(dòng) PostgreSQL 服務(wù)

# 啟動(dòng)服務(wù)(當(dāng)前會話)
brew services start postgresql

# 或手動(dòng)啟動(dòng)(推薦)
pg_ctl -D /opt/homebrew/var/postgres start   # Apple Silicon
# pg_ctl -D /usr/local/var/postgres start    # Intel 舊版

4. 設(shè)置開機(jī)自啟(可選)

brew services start postgresql

以后系統(tǒng)啟動(dòng)時(shí)自動(dòng)運(yùn)行 PostgreSQL。

5. 驗(yàn)證安裝成功

psql --version
# 輸出類似:psql (PostgreSQL) 17.0

# 進(jìn)入數(shù)據(jù)庫
psql postgres

在 psql 中運(yùn)行:

SELECT version();
\l
\q

二、其他安裝方式(了解即可)

方式說明推薦度
Postgres.app拖拽式 GUI 應(yīng)用,一鍵啟動(dòng)★★★★
官方安裝包.dmg 安裝,帶 pgAdmin★★★
Docker容器化,隔離環(huán)境★★★★

三、Postgres.app 方式(適合新手 / 想圖形化啟動(dòng))

  1. 下載:https://postgresapp.com
  2. 拖到 應(yīng)用程序 文件夾
  3. 雙擊打開 → 自動(dòng)初始化并啟動(dòng)
  4. 菜單欄有小象圖標(biāo),可一鍵啟停

默認(rèn)數(shù)據(jù)目錄:~/Library/Application Support/Postgres/var-17

四、圖形化管理工具(推薦安裝一個(gè))

方式 1:安裝 pgAdmin 4(官方 GUI)

brew install --cask pgadmin4

安裝后從 Launchpad 打開,添加本地服務(wù)器:

  • Host: localhost
  • Port: 5432
  • User: 你的 mac 用戶名(Homebrew 版默認(rèn))

方式 2:DBeaver(免費(fèi)多數(shù)據(jù)庫 GUI)

brew install --cask dbeaver-community

五、Homebrew 版 PostgreSQL 重要路徑

路徑說明
/opt/homebrew/var/postgres數(shù)據(jù)目錄(M1/M2/M3)
/usr/local/var/postgres數(shù)據(jù)目錄(Intel 舊版)
/opt/homebrew/bin/psql命令行工具
/opt/homebrew/etc/postgresql@17配置文件

六、設(shè)置密碼 & 創(chuàng)建用戶(推薦)

Homebrew 安裝的 PostgreSQL 默認(rèn)無密碼,通過本地 socket 認(rèn)證。

設(shè)置postgres角色密碼:

psql postgres
ALTER USER postgres WITH PASSWORD 'your_secure_password';
\q

創(chuàng)建應(yīng)用專用用戶和數(shù)據(jù)庫

psql postgres
CREATE DATABASE myapp;
CREATE USER appuser WITH ENCRYPTED PASSWORD 'apppass123';
GRANT ALL PRIVILEGES ON DATABASE myapp TO appuser;
\q

測試連接:

psql -h localhost -U appuser -d myapp

七、允許遠(yuǎn)程連接(開發(fā)/測試用)

1. 修改監(jiān)聽地址

nano /opt/homebrew/var/postgres/postgresql.conf

找到并修改:

# listen_addresses = 'localhost'
listen_addresses = '*'

2. 修改認(rèn)證方式

nano /opt/homebrew/var/postgres/pg_hba.conf

末尾添加:

# 允許局域網(wǎng)
host    all             all             192.168.1.0/24          md5

# 允許所有(僅測試?。?
# host    all             all             0.0.0.0/0               md5

3. 重啟服務(wù)

brew services restart postgresql

4. 開放 macOS 防火墻(系統(tǒng)設(shè)置 → 網(wǎng)絡(luò) → 防火墻)

或命令行:

sudo /usr/libexec/ApplicationFirewall/socketfilterfw --add /opt/homebrew/bin/postgres

八、常用命令總結(jié)(終端)

命令說明
brew services start postgresql啟動(dòng)服務(wù)
brew services stop postgresql停止服務(wù)
brew services restart postgresql重啟
psql postgres進(jìn)入數(shù)據(jù)庫
pg_dump mydb > backup.sql備份
psql mydb < backup.sql恢復(fù)
createdb mydb創(chuàng)建數(shù)據(jù)庫
dropdb mydb刪除數(shù)據(jù)庫
pg_ctl status查看狀態(tài)

九、備份與恢復(fù)

# 備份
pg_dump -U postgres myapp > myapp_backup.sql

# 恢復(fù)
psql -U postgres myapp < myapp_backup.sql
# 或
createdb myapp_restore
psql -U postgres myapp_restore < myapp_backup.sql

十、卸載 PostgreSQL(徹底清理)

# 停止服務(wù)
brew services stop postgresql

# 卸載
brew uninstall postgresql

# 刪除數(shù)據(jù)(謹(jǐn)慎?。?
rm -rf /opt/homebrew/var/postgres
rm -rf /usr/local/var/postgres

# 刪除配置文件
rm -rf /opt/homebrew/etc/postgresql@*

十一、常見問題(FAQ)

問題解決方法
psql: error: could not connect to serverbrew services start postgresql
FATAL: role "postgres" does not exist重新初始化:initdb /opt/homebrew/var/postgres
permission denied for database postgres檢查數(shù)據(jù)目錄權(quán)限:chmod 700 /opt/homebrew/var/postgres
想換端口修改 postgresql.conf 中的 port = 5433

十二、學(xué)習(xí)資源

恭喜!你已成功在 macOS 上安裝 PostgreSQL!

到此這篇關(guān)于Mac OS上安裝PostgreSQL的文章就介紹到這了,更多相關(guān)Mac OS安裝PostgreSQL內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

相關(guān)文章

  • postgresql中時(shí)間轉(zhuǎn)換和加減操作

    postgresql中時(shí)間轉(zhuǎn)換和加減操作

    這篇文章主要介紹了postgresql中時(shí)間轉(zhuǎn)換和加減操作,具有很好的參考價(jià)值,希望對大家有所幫助。一起跟隨小編過來看看吧
    2020-12-12
  • PostgreSQL查看帶有綁定變量SQL的通用方法詳解

    PostgreSQL查看帶有綁定變量SQL的通用方法詳解

    今天我們要探討的是 custom執(zhí)行計(jì)劃和通用執(zhí)行計(jì)劃。這一技術(shù)在 Oracle中被稱為綁定變量窺視。但 Postgresql中并沒有這樣的定義,更嚴(yán)格地說,Postgresql叫做custom執(zhí)行計(jì)劃和通用執(zhí)行計(jì)劃
    2022-09-09
  • Ruoyi從mysql切換到postgresql的幾個(gè)踩坑實(shí)戰(zhàn)

    Ruoyi從mysql切換到postgresql的幾個(gè)踩坑實(shí)戰(zhàn)

    最近由于工作的原因,需要將Ruoyi從mysql切換到postgresql,所以這篇文章主要給大家介紹了關(guān)于Ruoyi從mysql切換到postgresql的幾個(gè)踩坑實(shí)戰(zhàn),需要的朋友可以參考下
    2023-02-02
  • 解決PostgreSQL服務(wù)啟動(dòng)后占用100% CPU卡死的問題

    解決PostgreSQL服務(wù)啟動(dòng)后占用100% CPU卡死的問題

    前文書說到,今天耗費(fèi)了九牛二虎之力,終于馴服了NTFS權(quán)限安裝好了PostgreSQL,卻不曾想,服務(wù)啟動(dòng)后,新的狀況又出現(xiàn)了。
    2009-08-08
  • 修改postgresql存儲目錄的操作方式

    修改postgresql存儲目錄的操作方式

    這篇文章主要介紹了修改postgresql存儲目錄的操作方式,具有很好的參考價(jià)值,希望對大家有所幫助。一起跟隨小編過來看看吧
    2021-01-01
  • postgresql 實(shí)現(xiàn)取出分組中最大的幾條數(shù)據(jù)

    postgresql 實(shí)現(xiàn)取出分組中最大的幾條數(shù)據(jù)

    這篇文章主要介紹了postgresql 實(shí)現(xiàn)取出分組中最大的幾條數(shù)據(jù),具有很好的參考價(jià)值,希望對大家有所幫助。一起跟隨小編過來看看吧
    2021-01-01
  • postgresql 刪除重復(fù)數(shù)據(jù)案例詳解

    postgresql 刪除重復(fù)數(shù)據(jù)案例詳解

    這篇文章主要介紹了postgresql 刪除重復(fù)數(shù)據(jù)案例詳解,本篇文章通過簡要的案例,講解了該項(xiàng)技術(shù)的了解與使用,以下就是詳細(xì)內(nèi)容,需要的朋友可以參考下
    2021-08-08
  • PostgreSQL邏輯復(fù)制解密原理解析

    PostgreSQL邏輯復(fù)制解密原理解析

    邏輯復(fù)制,是基于復(fù)制標(biāo)識復(fù)制數(shù)據(jù)及其變化的一種方法,區(qū)別于物理復(fù)制對頁面操作的描述,邏輯復(fù)制是對事務(wù)及數(shù)據(jù)元組的一種描述,這篇文章主要介紹了PostgreSQL邏輯復(fù)制解密原理解析,需要的朋友可以參考下
    2022-09-09
  • postgresql 實(shí)現(xiàn)將字段為空的值替換為指定值

    postgresql 實(shí)現(xiàn)將字段為空的值替換為指定值

    這篇文章主要介紹了postgresql 實(shí)現(xiàn)將字段為空的值替換為指定值,具有很好的參考價(jià)值,希望對大家有所幫助。一起跟隨小編過來看看吧
    2021-01-01
  • 如何查看postgres數(shù)據(jù)庫端口

    如何查看postgres數(shù)據(jù)庫端口

    這篇文章主要介紹了如何查看postgres數(shù)據(jù)庫端口操作,具有很好的參考價(jià)值,希望對大家有所幫助。一起跟隨小編過來看看吧
    2021-01-01

最新評論

诏安县| 通辽市| 凤台县| 苍梧县| 大邑县| 汝阳县| 望江县| 水城县| 磴口县| 巫溪县| 拉孜县| 青阳县| 保德县| 永福县| 扬州市| 柳江县| 汉沽区| 肃宁县| 香河县| 铁岭县| 克山县| 宿迁市| 嘉义市| 昌黎县| 灵武市| 修文县| 安义县| 永济市| 溆浦县| 徐闻县| 水富县| 成都市| 隆昌县| 安顺市| 民丰县| 利川市| 连平县| 五大连池市| 黄浦区| 壤塘县| 甘德县|