ユーザ作ったりDB作ったり、基本的なことに派手に躓いたので。。。
インストール
パッケージ管理システム(=Homebrew)より導入しました。インストール時に、セットアップ情報が表示されるので、それに従います。*1
postgresql: stable 9.2.1 http://www.postgresql.org/ Depends on: readline, ossp-uuid /usr/local/Cellar/postgresql/9.2.1 (2814 files, 38M) * https://github.com/mxcl/homebrew/commits/master/Library/Formula/postgresql.rb ==> Options --without-ossp-uuid Build without OSSP uuid --no-perl Build without Perl support --32-bit Build 32-bit only --enable-dtrace Build with DTrace support --no-python Build without Python support ==> Caveats # 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.2/static/install-procedure.html # Create/Upgrade a Database If this is your first install, create a database with: initdb /usr/local/var/postgres -E utf8 To migrate existing data from a previous major version (pre-9.2) of PostgreSQL, see: http://www.postgresql.org/docs/9.2/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.2.1/homebrew.mxcl.postgresql.plist ~/Library/LaunchAgents/ launchctl load -w ~/Library/LaunchAgents/homebrew.mxcl.postgresql.plist If this is an upgrade and you already have the homebrew.mxcl.postgresql.plist loaded: launchctl unload -w ~/Library/LaunchAgents/homebrew.mxcl.postgresql.plist cp /usr/local/Cellar/postgresql/9.2.1/homebrew.mxcl.postgresql.plist ~/Library/LaunchAgents/ launchctl load -w ~/Library/LaunchAgents/homebrew.mxcl.postgresql.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 # Loading Extensions By default, Homebrew builds all available Contrib extensions. To see a list of all available extensions, from the psql command line, run: SELECT * FROM pg_available_extensions; To load any of the extension names, navigate to the desired database and run: CREATE EXTENSION [extension name]; For instance, to load the tablefunc extension in the current database, run: CREATE EXTENSION tablefunc; For more information on the CREATE EXTENSION command, see: http://www.postgresql.org/docs/9.2/static/sql-createextension.html For more information on extensions, see: http://www.postgresql.org/docs/9.2/static/contrib.html # Other Some machines may require provisioning of shared memory: http://www.postgresql.org/docs/9.2/static/kernel-resources.html#SYSVIPC To install postgresql (and ossp-uuid) in 32-bit mode: brew install postgresql --32-bit 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.
起動と終了
起動
$pg_ctl -l /usr/local/var/postgres/server.log start
終了
$pg_ctl -D /usr/local/var/postgres stop -s -m fast
※ シェル設定ファイルにエイリアスを作っておくと便利!(例: in ~/.zshrc)
# for PostgreSQL export PGDATA=/usr/local/var/postgres alias pgstart="pg_ctl -l /usr/local/var/postgres/server.log start" alias pgstop="pg_ctl -D /usr/local/var/postgres stop -s -m fast"
これでpgstartやpgstopで開始、終了ができる。
ユーザの追加
$createuser -P -a pg_admin;
(-P: パスワード入力のプロンプト表示、-a: 作成するユーザはスーパユーザになる。)
※他のブログとか見ていると、$createuser usernameで対話的に設定できるはずな気もするが出来なかった。
ちなみに、当方のversionは9.2.1でした。
ユーザの確認
$psql -q -c 'select * from pg_user' postgres
PostgreSQLにログイン
$psql -U username dbname
入ってしまえば、他のRDBMSとほとんど同じでしょう。きっと。
存在するDB一覧
$psql -l
後は適宜充実させて行く予定です。
*1:Ubuntuの場合、インストール後、DB管理用にpostgresユーザが作成されていた。