在安装PostgreSQL到Mac上时遇到了困难
我想要在Homebrew中安装PostgreSQL,但在权限等方面遇到了问题,所以将其作为备忘录留下来。
我也附上了我在安装PostgreSQL时参考的URL,希望您能一并确认。
使用Homebrew安装PostgreSQL。
$ brew install postgresql
==> Downloading https://homebrew.bintray.com/bottles/postgresql-11.1.mojave.bottle.tar.gz
Already downloaded: /Users/suzuki_naoto/Library/Caches/Homebrew/downloads/0c14020ff4817a892c73344b81dbd6f31e0d6e83ca0778de6fe3b4d4ecba7a59--postgresql-11.1.mojave.bottle.tar.gz
==> Pouring postgresql-11.1.mojave.bottle.tar.gz
Error: The `brew link` step did not complete successfully
The formula built, but is not symlinked into /usr/local
Could not symlink include/ecpg_config.h
/usr/local/include is not writable.
You can try again using:
brew link postgresql
==> /usr/local/Cellar/postgresql/11.1/bin/initdb /usr/local/var/postgres
Last 15 lines from /Users/suzuki_naoto/Library/Logs/Homebrew/postgresql/post_install.01.initdb:
2019-01-03 15:55:57 +0900
/usr/local/Cellar/postgresql/11.1/bin/initdb
/usr/local/var/postgres
The files belonging to this database system will be owned by user "suzuki_naoto".
This user must also own the server process.
initdb: file "/usr/local/share/postgresql/postgres.bki" does not exist
This might mean you have a corrupted installation or identified
the wrong directory with the invocation option -L.
Warning: The post-install step did not complete successfully
You can try again using `brew postinstall postgresql`
==> Caveats
To migrate existing data from a previous major version of PostgreSQL run:
brew postgresql-upgrade-database
To have launchd start postgresql now and restart at login:
brew services start postgresql
Or, if you don't want/need a background service you can just run:
pg_ctl -D /usr/local/var/postgres start
==> Summary
? /usr/local/Cellar/postgresql/11.1: 3,548 files, 40.3MB
错误:brew link 步骤未能成功完成
该公式已构建,但未链接到/usr/local目录
无法链接 include/ecpg_config.h
/usr/local/include 不可写
您可以尝试再次使用以下命令:
brew link postgresql
这个错误是指无法创建符号链接。
※符号链接是操作系统文件系统的一种功能,可以创建一个指向特定文件或目录的另一个文件,通过它可以引用到原始文件。
执行错误中提到的命令
$ brew link postgresql
Linking /usr/local/Cellar/postgresql/11.1...
Error: Could not symlink include/ecpg_config.h
/usr/local/include is not writable.
根据我的调查,我发现在尝试安装Ansible时,在macOS High Sierra中失败了。进一步研究发现,/usr/local/include目录没有写入权限。请执行以下操作:
$ sudo mkdir /usr/local/include
$ sudo chown -R $(whoami) $(brew --prefix)/*
再次安装postgresql
$ brew install postgresql
Warning: postgresql 11.1 is already installed, it's just not linked
You can use `brew link postgresql` to link this version.
执行警告命令
$ brew link postgresql
Linking /usr/local/Cellar/postgresql/11.1... 392 symlinks created
执行首次brew install postgresql时出现的警告命令。
brew postinstall postgresql
==> Postinstalling postgresql
==> /usr/local/Cellar/postgresql/11.1/bin/initdb /usr/local/var/postgres
查询PostgreSQL版本
$ postgres --version
postgres (PostgreSQL) 11.1
将DB进行初始化,并指定locale为ja_JP.UTF-8。
$ initdb /usr/local/var/postgres --encoding=UTF-8 --locale=ja_JP.UTF-8
The files belonging to this database system will be owned by user "suzuki_naoto".
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".
DB的启动和验证
$ postgres -D /usr/local/var/postgres`
$ psql -l
List of databases
Name | Owner | Encoding | Collate | Ctype | Access privileges
-----------+--------------+----------+-------------+-------------+-------------------------------
postgres | suzuki_naoto | UTF8 | ja_JP.UTF-8 | ja_JP.UTF-8 |
template0 | suzuki_naoto | UTF8 | ja_JP.UTF-8 | ja_JP.UTF-8 | =c/suzuki_naoto +
| | | | | suzuki_naoto=CTc/suzuki_naoto
template1 | suzuki_naoto | UTF8 | ja_JP.UTF-8 | ja_JP.UTF-8 | =c/suzuki_naoto +
| | | | | suzuki_naoto=CTc/suzuki_naoto
请提供一个参考网址。
在 Mac 上安装 PostgreSQL
在 macOS High Sierra 上尝试安装 Ansible 失败。
本地化(locale)
PostgreSQL 命令的备忘录