M1 Mac安装PostgreSQL
生活随笔
收集整理的這篇文章主要介紹了
M1 Mac安装PostgreSQL
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
1: 安裝postgresql: arch -arm64 brew install postgresql
chirs@ChrisdeMacBook-Pro ~ % brew install postgresql Error: Cannot install under Rosetta 2 in ARM default prefix (/opt/homebrew)! To rerun under ARM use:arch -arm64 brew install ... To install under x86_64, install Homebrew into /usr/local. chirs@ChrisdeMacBook-Pro ~ % arch -arm64 brew install postgresql ==> Downloading https://ghcr.io/v2/homebrew/core/krb5/manifests/1.19.2 ######################################################################## 100.0% ==> Downloading https://ghcr.io/v2/homebrew/core/krb5/blobs/sha256:62a2882f4193d6871d9c8116b897a8d33d6a4fedb954646a0eefdc4bfe623110 ==> Downloading from https://pkg-containers.githubusercontent.com/ghcr1/blobs/sha256:62a2882f4193d6871d9c8116b897a8d33d6a4fedb954646a0eefdc4bfe623110?se=2022-01-14T09%3A35%3A00Z&sig=IBtMKLxA%2BFVqJgkKlnDy7uP%2Fx ######################################################################## 100.0% ==> Downloading https://ghcr.io/v2/homebrew/core/readline/manifests/8.1 ######################################################################## 100.0% ==> Downloading https://ghcr.io/v2/homebrew/core/readline/blobs/sha256:940e7c2b80ef7f59b26726a5669a31fcb8ba7cbbb17eb1f2ca589dafa6e68e5e ==> Downloading from https://pkg-containers.githubusercontent.com/ghcr1/blobs/sha256:940e7c2b80ef7f59b26726a5669a31fcb8ba7cbbb17eb1f2ca589dafa6e68e5e?se=2022-01-14T09%3A35%3A00Z&sig=dtdFZOmYtx4c9bU8Gq4q26Kneg6fW ######################################################################## 100.0% ==> Downloading https://ghcr.io/v2/homebrew/core/postgresql/manifests/13.4 ######################################################################## 100.0% ==> Downloading https://ghcr.io/v2/homebrew/core/postgresql/blobs/sha256:c6f7b67506131a89ceef01656356022c5eb52c6535cd07dbbbb5e2f2c2aa26e8 ==> Downloading from https://pkg-containers.githubusercontent.com/ghcr1/blobs/sha256:c6f7b67506131a89ceef01656356022c5eb52c6535cd07dbbbb5e2f2c2aa26e8?se=2022-01-14T09%3A35%3A00Z&sig=gDSXfsALUwU72ch96pVO6zeXT1Fux ######################################################################## 100.0% ==> Installing dependencies for postgresql: krb5 and readline ==> Installing postgresql dependency: krb5 ==> Pouring krb5--1.19.2.arm64_big_sur.bottle.tar.gz 🍺 /opt/homebrew/Cellar/krb5/1.19.2: 162 files, 5.9MB ==> Installing postgresql dependency: readline ==> Pouring readline--8.1.arm64_big_sur.bottle.tar.gz 🍺 /opt/homebrew/Cellar/readline/8.1: 48 files, 1.7MB ==> Installing postgresql ==> Pouring postgresql--13.4.arm64_big_sur.bottle.tar.gz ==> /opt/homebrew/Cellar/postgresql/13.4/bin/initdb --locale=C -E UTF-8 /opt/homebrew/var/postgres ==> Caveats To migrate existing data from a previous major version of PostgreSQL run:brew postgresql-upgrade-databaseThis formula has created a default database cluster with:initdb --locale=C -E UTF-8 /opt/homebrew/var/postgres For more details, read:https://www.postgresql.org/docs/13/app-initdb.htmlTo start postgresql:brew services start postgresql Or, if you don't want/need a background service you can just run:/opt/homebrew/opt/postgresql/bin/postgres -D /opt/homebrew/var/postgres ==> Summary 🍺 /opt/homebrew/Cellar/postgresql/13.4: 3,230 files, 43.6MB ==> `brew cleanup` has not been run in the last 30 days, running now... Removing: /Users/chirs/Library/Logs/Homebrew/libtool... (64B) Removing: /Users/chirs/Library/Logs/Homebrew/autoconf... (64B) Removing: /Users/chirs/Library/Logs/Homebrew/m4... (64B) Removing: /Users/chirs/Library/Logs/Homebrew/six... (64B) Removing: /Users/chirs/Library/Logs/Homebrew/protobuf... (64B) Removing: /Users/chirs/Library/Logs/Homebrew/automake... (64B) Removing: /Users/chirs/Library/Logs/Homebrew/telnet... (64B) ==> Caveats ==> postgresql To migrate existing data from a previous major version of PostgreSQL run:brew postgresql-upgrade-databaseThis formula has created a default database cluster with:initdb --locale=C -E UTF-8 /opt/homebrew/var/postgres For more details, read:https://www.postgresql.org/docs/13/app-initdb.htmlTo start postgresql:brew services start postgresql Or, if you don't want/need a background service you can just run:/opt/homebrew/opt/postgresql/bin/postgres -D /opt/homebrew/var/postgres2: 初始化數據庫: initdb --locale=C -E UTF-8 /opt/homebrew/var/postgres
chirs@ChrisdeMacBook-Pro ~ % initdb --locale=C -E UTF-8 /opt/homebrew/var/postgres The files belonging to this database system will be owned by user "chirs". This user must also own the server process.The database cluster will be initialized with locale "C". The default text search configuration will be set to "english".Data page checksums are disabled.initdb: error: directory "/opt/homebrew/var/postgres" exists but is not empty If you want to create a new database system, either remove or empty the directory "/opt/homebrew/var/postgres" or run initdb with an argument other than "/opt/homebrew/var/postgres".3:如果有報錯信息: initdb: error: directory “/opt/homebrew/var/postgres” exists but is not empty, 刪除文件 rm -rf /opt/homebrew/var/postgres
chirs@ChrisdeMacBook-Pro ~ % rm -rf /opt/homebrew/var/postgres chirs@ChrisdeMacBook-Pro ~ % initdb --locale=C -E UTF-8 /opt/homebrew/var/postgres The files belonging to this database system will be owned by user "chirs". This user must also own the server process.The database cluster will be initialized with locale "C". The default text search configuration will be set to "english".Data page checksums are disabled.creating directory /opt/homebrew/var/postgres ... ok creating subdirectories ... ok selecting dynamic shared memory implementation ... posix selecting default max_connections ... 100 selecting default shared_buffers ... 128MB selecting default time zone ... Asia/Shanghai creating configuration files ... ok running bootstrap script ... ok performing post-bootstrap initialization ... ok syncing data to disk ... okinitdb: warning: enabling "trust" authentication for local connections You can change this by editing pg_hba.conf or using the option -A, or --auth-local and --auth-host, the next time you run initdb.Success. You can now start the database server using:pg_ctl -D /opt/homebrew/var/postgres -l logfile start4: 啟動服務: pg_ctl -D /opt/homebrew/var/postgres -l logfile start
chirs@ChrisdeMacBook-Pro ~ % pg_ctl -D /opt/homebrew/var/postgres -l logfile start waiting for server to start.... done server started5: 創建一個數據庫用戶: createuser username -P
chirs@ChrisdeMacBook-Pro ~ % pg_ctl -D /opt/homebrew/var/postgres -l logfile start waiting for server to start.... done server started chirs@ChrisdeMacBook-Pro ~ % createuser username -P Enter password for new role: Enter it again:6: 創建一個數據庫: createdb dbname -O username -E UTF8 -e
chirs@ChrisdeMacBook-Pro ~ % createdb dbname -O username -E UTF8 -e SELECT pg_catalog.set_config('search_path', '', false); CREATE DATABASE dbname OWNER username ENCODING 'UTF8';7: 登入: psql -U username -d dbname
總結
以上是生活随笔為你收集整理的M1 Mac安装PostgreSQL的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: redis sentinel(哨兵)
- 下一篇: 关于逸马驰骋兄转移数据库的一种方案(记录