Fedora8にpostgresqlをセットアップしたログ

yumでインストール

[root]# yum -y install postgresql postgresql-server

サーバだけならpostgresqlだけで良いと思うのですが、
一応クライアントもインストールしました。


データベースクラスタ初期化

postgresqlのスーパーユーザであるpostgresになって、
データベースクラスタを初期化します。

[root]# su - postgres
[postgres]$ initdb -E UTF8

符号化方式にはUTF-8を指定しました。
[http://www.postgresql.jp/document/current/html/app-initdb.html:title=http://:title]

データベースサーバの起動

データベースサーバを起動します。

[root]# /etc/rc.d/init.d/postgresql start

管理ユーザpostgresのパスワード設定

システム上のパスワードとpostgresql上のパスワードを設定します。

[root]# passwd postgres
Changing password for user postgres.
新しいUNIX パスワード:
新しいUNIX パスワードを再入力してください:
passwd: all authentication tokens updated successfully.
[root]# su - postgres
[postgres]$ psql
Welcome to psql 8.2.11, the PostgreSQL interactive terminal.

Type:  \copyright for distribution terms
       \h for help with SQL commands
       \? for help with psql commands
       \g or terminate with semicolon to execute query
       \q to quit

postgres=# alter user postgres with password 'pass.pass';

ユーザの追加とパスワードの設定

[root]# su - postgres
[postgres]$ createuser -AdPE mailgw
Enter password for new role: 
Enter it again: 
Shall the new role be allowed to create more new roles? (y/n) n
CREATE ROLE

createuserコマンドでユーザの追加とパスワードの設定をします。
指定しているオプションは以下の通りです。
http://www.postgresql.jp/document/pg721doc/reference/app-createuser.html

-A 新しいユーザが他のユーザを作成することの禁止
-d 新しいユーザがデータベースを作成することを許可
-P 新しいユーザのパスワードのプロンプトを発行
-E データベースに保存するユーザのパスワードを暗号化

外部からアクセスできるようにする

[root]# su - postgres
[postgres]$ vi /var/lib/pgsql/data/postgresql.conf
#listen_addresses = 'localhost'
listen_addresses = '*'

アクセスできるホストを制限する

20.1. pg_hba.confファイル

[root]# vi /var/lib/pgsql/data/pg_hba.conf

以下の記述を追加する。

host    hoge         hoge         192.168.1.0/24        md5