Mac OS X 10.7でPostgreSQLを入れてみた&動かしてみた
前回の記事でRails(ホントはHeroku)のためにPostgreSQLを入れると書いたので、入れてみた。
インストール
$ brew install postgresql
インストールしたらこんなの出てきた。今後のインストールとか設定のために載せる。
# Build Notes If builds of PostgreSQL 9 are failing and you have version 8.x installed, you may need to remove the previous version first. See: https://github.com/mxcl/homebrew/issues/issue/2510 To build plpython against a specific Python, set PYTHON prior to brewing: PYTHON=/usr/local/bin/python brew install postgresql See: http://www.postgresql.org/docs/9.1/static/install-procedure.html # Create/Upgrade a Database If this is your first install, create a database with: initdb /usr/local/var/postgres To migrate existing data from a previous major version (pre-9.1) of PostgreSQL, see: http://www.postgresql.org/docs/9.1/static/upgrading.html # Start/Stop PostgreSQL If this is your first install, automatically load on login with: mkdir -p ~/Library/LaunchAgents cp /usr/local/Cellar/postgresql/9.1.2/org.postgresql.postgres.plist ~/Library/LaunchAgents/ launchctl load -w ~/Library/LaunchAgents/org.postgresql.postgres.plist If this is an upgrade and you already have the org.postgresql.postgres.plist loaded: launchctl unload -w ~/Library/LaunchAgents/org.postgresql.postgres.plist cp /usr/local/Cellar/postgresql/9.1.2/org.postgresql.postgres.plist ~/Library/LaunchAgents/ launchctl load -w ~/Library/LaunchAgents/org.postgresql.postgres.plist Or start manually with: pg_ctl -D /usr/local/var/postgres -l /usr/local/var/postgres/server.log start And stop with: pg_ctl -D /usr/local/var/postgres stop -s -m fast # Other Some machines may require provisioning of shared memory: http://www.postgresql.org/docs/current/static/kernel-resources.html#SYSVIPC If you want to install the postgres gem, including ARCHFLAGS is recommended: env ARCHFLAGS="-arch x86_64" gem install pg To install gems without sudo, see the Homebrew wiki.
DBを作る
$ initdb /usr/local/var/postgres
DBを動かす
ログイン時に自動的に動かすのと手動で動かすのがあるけど、ここでは手動で行う方を示す。
Railで動かすためのテストなので自動は必要ないと思う。
DBを手動でフォアグラウンドで動かす
$ postgres -D /usr/local/var/postgres
止めるには^Cを入力する。
DBを手動でバッググラウンドで動かす
$ pg_ctl -D /usr/local/var/postgres -l /usr/local/var/postgres/server.log start
バッググラウンドで動かしているDBを手動で止める
$ pg_ctl -D /usr/local/var/postgres stop -s -m fast