FreeBSDにPostgreSQLをインストールする

前提

前回の続きです。
構成
OSFreeBSD 6.3 Release
apache 2.0.63
PHP5.2.6
PostreSQL8.3.3


とりあえずやってみます

You must use GNU make to build PostgreSQL.
*** Error code 1

Stop in /usr/home/~/app/postgresql-8.3.3.

GNUのmake(通称?gmake)じゃないとだめといっています

gmakeのインストール

# make install
# mv /usr/local/bin/make /usr/local/bin/gmake

一応今までのものは「make」。GNUのものを「gmake」と使い分けるようにしました。

PostgreSQL 再インストール

# make install

「gmake」がインストールされると「make」内でgmakeを勝手に探索してくれます!
とりあえずこれでインストールが完了しました。

使えるようにする

postgres userとgroupを作成する

PostgreSQLはrootとは別の管理者ユーザとグループを作成しなくてはなりません。


# adduser
Username: postgres
Full name: Admin user for PostgreSQL DB
Uid (Leave empty for default):
Login group [postgres]:
Login group is postgres. Invite postgres into other groups? []:
Login class [default]:
Shell (sh csh tcsh nologin) [sh]: tcsh
Home directory [/home/postgres]:
Use password-based authentication? [yes]:
Use an empty password? (yes/no) [no]:
Use a random password? (yes/no) [no]:
Enter password:***
Enter password again:***
Lock out the account after creation? [no]:
Username : postgres
Password : *****
Full Name : Admin user for PostgreSQL DB
Uid : 1003
Class :
Groups : postgres
Home : /home/postgres
Shell : /bin/tcsh
Locked : no
OK? (yes/no): y
adduser: INFO: Successfully added (postgres) to the user database.
Add another user? (yes/no): n
Goodbye!
sv01#


sv01# vi /home/postgres/.cshrc


setenv PATH /usr/local/pgsql/bin:$PATH
setenv POSTGRES_HOME /usr/local/pgsql
setenv PGLIB $POSTGRES_HOME/lib
setenv LD_LIBRARY_PATH $PGLIB
setenv MANPATH $POSTGRES_HOME/man
setenv PGDATA /usr/local/pgsql/data
を追記します。

データベース初期化

上記で設定したPGDATAディレクトリは現時点で存在しないので作成。
およびpostgresに権限を与えておく

sv01# mkdir /usr/local/pgsql/data
sv01# chown postgres:postgres /usr/local/pgsql/data

上記で作成した「postgres」ユーザでloginし


sv01# su postgres
% initdb
:
:
Success. You can now start the database server using:

postgres -D /usr/local/pgsql/data
or
pg_ctl -D /usr/local/pgsql/data -l logfile start

%

データベース起動

起動コマンド


%pg_ctl -w start
:
:
server started
%

起動確認


%psql -l
List of databases
Name | Owner | Encoding

                                                                  • -

postgres | postgres | SQL_ASCII
template0 | postgres | SQL_ASCII
template1 | postgres | SQL_ASCII
(3 rows)

%


自動起動設定

host再起動の再に自動的にプロセスがあがるようにします。

sv01# cp ~/app/postgresql-8.3.3/contrib/start-scripts/freebsd /usr/local/etc/rc.d/postgreSQL.sh
sv01# chmod 755 /usr/local/etc/rc.d/postgreSQL.sh


PHPに連携させる

WEB上でPostgreSQLを使用するために PostgreSQLPHP を連携させます。

PHPの再make

sv01# make install

確認

きちんと連動するかはここの方法で確認します。

[ wget http://ring.aist.go.jp/archives/misc/db/postgresql/source/v8.3.3/postgresql-8.3.3.tar.gz