在M1 Mac上安装PostgreSQL等
由于 PostgreSQL 的安装遇到了问题,以免忘记,需要做好备忘。
本次环境情况为:
*macOS M1操作系统
*PostgreSQL-14.7数据库
如果不指定PostgreSQL的版本,就会发生错误。
使用Homebrew安装PostgreSQL。
$ brew install postgresql
Warning: No available formula with the name "postgresql". Did you mean postgresql@13, postgresql@12, postgresql@11, postgresql@15, postgresql@10, postgresql@14, postgresql@9.5, postgresql@9.4, postgrest or qt-postgresql?
postgresql breaks existing databases on upgrade without human intervention.
See a more specific version to install with:
brew formulae | grep postgresql@
请指定版本,并注意警告。
解决方案
在本地使用Homebrew安装PostgreSQL
$ brew install postgresql@14
~~
==> Summary
? /opt/homebrew/Cellar/postgresql@14/14.7: 3,314 files, 45.2MB
~~
如果不指定版本,就会发生错误,所以要像@14那样指定版本。
$ psql --version
psql (PostgreSQL) 14.7 (Homebrew)
确认是否已安装
使用UTF-8对数据库进行初始化
$ initdb /usr/local/var/postgres -E utf8
The files belonging to this database system will be owned by user "sf213471118".
This user must also own the server process.
The database cluster will be initialized with locale "ja_JP.UTF-8".
initdb: could not find suitable text search configuration for locale "ja_JP.UTF-8"
The default text search configuration will be set to "simple".
Data page checksums are disabled.
initdb: directory "/usr/local/var/postgres" exists but is not empty
If you want to create a new database system, either remove or empty
the directory "/usr/local/var/postgres" or run initdb
with an argument other than "/usr/local/var/postgres".
启动/停止PostgreSQL
启动PostgreSQL
$ brew services start postgresql@14
==> Successfully started `postgresql@14` (label: homebrew.mxcl.postgresql@14)
如果不指定版本,运行这个命令也会出错。
停止PostgreSQL
$ brew services stop postgresql@14
Stopping `postgresql@14`... (might take a while)
==> Successfully stopped `postgresql@14` (label: homebrew.mxcl.postgresql@14)
也可以指定一个版本。
以下是可以参考的文章:
https://qiita.com/sf213471118/items/0e843af332ea0210c810