macへのpostgres install
いろいろと忘れたのでメモ。
install確認
$ brew search postgres
==> Searching local taps...
postgresql ✔ postgres-xc postgresql@9.5 postgrest
check_postgres postgresql@9.4 postgresql@9.6
installしていない場合は
$ brew install postgresql
brew link
link
$ brew link postgresql
Linking /usr/local/Cellar/postgresql/10.0... 666 symlinks created
initdb確認
$ which initdb | xargs readlink
../Cellar/postgresql/10.0/bin/initdb
ちなみにunlinkは
$ brew unlink postgresql
version
$ postgres --version
postgres (PostgreSQL) 10.0
$ psql --version
psql (PostgreSQL) 10.0
データベース初期化
$ initdb /usr/local/var/postgres -E utf8
The files belonging to this database system will be owned by user <USERNAME>.
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.
creating directory /usr/local/var/postgres ... ok
creating subdirectories ... ok
selecting default max_connections ... 100
selecting default shared_buffers ... 128MB
selecting dynamic shared memory implementation ... posix
creating configuration files ... ok
running bootstrap script ... ok
performing post-bootstrap initialization ... ok
syncing data to disk ... ok
起動
$ pg_ctl -D /usr/local/var/postgres -l logfile start
または
$ postgres -D /usr/local/var/postgres
停止
$ pg_ctl stop -D /usr/local/var/postgres
services起動
確認
$ brew services list
Name Status User Plist
postgresql stopped
起動
$ brew services start postgresql
==> Successfully started `postgresql` (label: homebrew.mxcl.postgresql)
停止
$ brew services stop postgresql
Stopping `postgresql`... (might take a while)
==> Successfully stopped `postgresql` (label: homebrew.mxcl.postgresql)
再起動
$ brew services restart postgresql
Stopping `postgresql`... (might take a while)
==> Successfully stopped `postgresql` (label: homebrew.mxcl.postgresql)
==> Successfully started `postgresql` (label: homebrew.mxcl.postgresql)
バージョン切り替え
$ pg_ctl stop -D /usr/local/var/postgres
$ brew switch postgres 9.6.3
$ initdb /usr/local/var/postgres96 -E utf8
$ brew services restart postgresql
$ pg_ctl -D /usr/local/var/postgres96 -l logfile start