# cd /usr/local/src # tar xvzf postgresql-7.4.2.tar.gz # cd postgresql-7.4.2 # ./configure --with-includes=/sw/include/ --with-libraries=/sw/lib checking build system type... powerpc-apple-darwin7.3.0 . . config.status: linking ./src/makefiles/Makefile.darwin to src/Makefile.port # make make -C doc all . . All of PostgreSQL successfully made. Ready to install. # make install make -C doc install . . PostgreSQL installation complete. |
Linux の場合、大抵は configure のオプションは不要なのですが、Mac OS X の場合、 Fink でインストールしたインクルードファイルやライブラリファイルの位置が特殊な場所にあるため、--with-includes や --with-libraries の指定が必要です。
次に postgres アカウントを作成します。Linux の場合は、useradd コマンドで作成するのが一般的ですが、Mac OS X では、それに該当するコマンドが見当たらないため、 [システム環境設定] - [アカウント] で postgres アカウントを作成します。
続いて、PostgreSQL のデータディレクトリを作成し、データベースを初期化します。
# cd /usr/local/pgsql # mkdir data # chown postgres data $ su - postgres $ /usr/local/pgsql/bin/initdb -D /usr/local/pgsql/data |
PostgreSQL の起動前に、環境変数を設定しておくと便利です。postgres アカウントのままで、~/.bash_profile に次の1行を加えます。
PATH=/usr/local/pgsql/bin:$PATH |
source コマンドで、~/.bash_profile の変更内容を有効後に、PostgreSQL を起動し、sample データベースを作成します。
$ source ~/.bash_profile $ pg_ctl -D /usr/local/pgsql/data -l logfile start . . $ createdb sample CREATE DATABASE |
psql コマンドで sample データベースにログインできることを確かめます。
$ psql sample Welcome to psql 7.4.2, the PostgreSQL interactive terminal. Type: \copyright for distribution terms \h for help with SQL commands \? for help on internal slash commands \g or terminate with semicolon to execute query \q to quit sample=# |
psql を終了するには、\q と入力します。ここまでで、PostgreSQL のインストールから起動、データベースの作成の確認が行えたことになります。
PostgreSQL を pg_ctl で毎回手動起動するのは面倒なので、以下に Mac OS X の起動と同時に PostgreSQL を自動起動する手順を記載します。この作業は、スーパーユーザで行います。
まず、/etc/hostconfig ファイルに次の行を加えます。
POSTGRESQLSERVER=-YES- |
続いて、/Library/StartupItems/PostgreSQL/ ディレクトリを作成し、/usr/local/src/postgresql-7.4.2/contrib/start-scripts/ 内の2ファイルをコピーします。
# mkdir /Library/StartupItems/PostgreSQL # cd /usr/local/src/postgresql-7.4.2/contrib/start-scripts # cp StartupParameters.plist.darwin /Library/StartupItems/PostgreSQL/StartupParameters.plist # cp PostgreSQL.darwin /Library/StartupItems/PostgreSQL/PostgreSQL |
Mac OS X を再起動すると、PostgreSQL が自動起動されます。