PostgreSQLのインストール&詳細設定

(1)postgresqlのインストール

# yum install postgresql-server

rootから、postgresにスイッチユーザーする。

# su – postgres

エンコードをUTF8に設定し、データベースを初期化。

$ initdb –encoding=UTF8 –no-locale -D /var/lib/pgsql/data

自動起動設定

postgresユーザ→rootにスイッチユーザ。

# chkconfig postgresql on

サービス起動。

# service postgresql start

接続確認。

postgresユーザにスイッチ

# su – postgres

$ psql

「Welcome to psql x.x.x, the PostgreSQL interactive terminal.」と表示されればOK.

(2)wwwサーバとDBサーバの接続設定

僕はwwwサーバとDBサーバを各一台ずつ構築しているので、

PHPやperlのDB接続は全てDBサーバへ接続する。

まず、pg_hba.confの設定から。

# vi /var/lib/pgsql/data/pg_hba.conf

host    all    all     127.0.0.1/32  255.255.255.0 trust

host    all    all     196.168.100.51  255.255.255.0    trust  wwwサーバのIPアドレスを入力

# vi /var/lib/pgsql/data/postgresql.conf

listen_addresses = ‘192.168.100.250,localhost‘  DBサーバのIPを入力

サービス再起動

# service postgresql restart

で、OK.

著者:bouya Imamura