PostgreSQL 8.2 の設定

PostgreSQL 管理ユーザーの環境設定を行い PostgreSQL プログラムを共有ライブラリへ登録します。
またデーターを実際に記録するための領域であるデーターベースクラスタを作成します。
最後に設定ファイルを使って PostgreSQL を起動するための最低限の設定を行います。

環境変数の設定

PostgreSQL 管理ユーザーである postgres ユーザーの環境変数を設定します。
厳密に言えばこの作業は必要ないのですが、PostgreSQL を使いやすくするために行います。
環境変数設定ファイル /home/postgres/.bash_profile を編集して以下の行を追加します。

# vi /home/postgres/.bash_profile
/home/postgres/.bash_profile
export PGDATA=/usr/local/pgsql/data
PATH=/usr/local/pgsql/bin:$PATH

共有ライブラリへの登録

複数のプログラムが PostgreSQL の機能を利用できるようにするために共有ライブラリへ登録します。
共有ライブラリへ登録するためには /etc/ld.so.conf を編集して以下の行を追加します。

# vi /etc/ld.so.conf
/etc/ld.so.conf
/usr/local/pgsql/lib

ldconfig コマンドを実行して共有ライブラリの読込先である /etc/ld.so.cache ファイルに変更内容を反映させます。

# /sbin/ldconfig

データーベースの初期化

データーの格納領域であるデーターベースクラスタを作成します。
この作業は initdb コマンドを使って行います。
この領域を事前に作成しておかないと PostgreSQL サーバーを起動することができません。
またこの作業は PostgreSQL をインストールした後に一度だけ行います。

# su - postgres
$ initdb -E UNICODE --no-locale

The files belonging to this database system will be owned by user “postgres”.
This user must also own the server process.

The database cluster will be initialized with locale C.

creating directory /usr/local/pgsql/data … ok
creating subdirectories … ok
selecting default max_connections … 100
selecting default shared_buffers/max_fsm_pages … 24MB/153600
creating configuration files … ok
creating template1 database in /usr/local/pgsql/data/base/1 … ok
initializing pg_authid … ok
initializing dependencies … ok
creating system views … ok
loading system objects’ descriptions … ok
creating conversions … ok
setting privileges on built-in objects … ok
creating information schema … ok
vacuuming database template1 … ok
copying template1 to template0 … ok
copying template1 to postgres … ok

WARNING: enabling “trust” authentication for local connections
You can change this by editing pg_hba.conf or using the -A option the
next time you run 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

$ exit

— initdb コマンドオプションの解説

  1. デフォルトのデーターベースの文字コードを指定します。
    • -E UNICODE
  2. データーベースで日本語を使用する場合は指定します。
    • –no-locale

PostgreSQL の設定

PostgreSQL の設定は postgresql.conf ファイルと pg_hba.conf ファイルを使って行います。
サーバーの実行時のリソースなどを設定するファイルである postgresql.conf ファイルを編集して以下の値を設定します。

# vi /usr/local/pgsql/data/postgresql.conf
/usr/local/pgsql/data/postgresql.conf
50 行目辺り

#—————————————————————————
# CONNECTIONS AND AUTHENTICATION
#—————————————————————————

# – Connection Settings –

listen_addresses = ‘*’TCP 接続(外部マシンからの接続)を許可

以下省略

クライアントからのアクセスコントロールを設定するファイルである pg_hba.conf ファイルを編集して以下の行を追加します。

# vi /usr/local/pgsql/data/pg_hba.conf
/usr/local/pgsql/data/pg_hba.conf
68 行目辺り
# TYPE  DATABASE    USER        CIDR-ADDRESS          METHOD

# “local” is for Unix domain socket connections only
local   all         all                               trust
# IPv4 local connections:
host    all         all         127.0.0.1/32          trust
# IPv6 local connections:
host    all         all         ::1/128               trust

host    all         all         192.168.0.0/24        md5ローカルネットワークからの md5 認証接続を許可

カテゴリー
Fedora のインストール
ネットワーク設定
OpenSSH で SSH サーバー構築
NTP で時刻情報サーバー構築
Apache HTTP Server で Web サーバー構築
MySQL でデーターベースサーバー構築
PostgreSQL でデーターベースサーバー構築
PHP で Web アプリケーションサーバー構築
qmail でメールサーバー構築
Samba でファイルサーバー構築
BIND でネームサーバー構築
Tomcat で Web アプリケーションサーバー構築
ProFTPD で FTP サーバー構築
システム設定
CMS でサイト構築
snort でネットワーク進入探知システム構築
ライブラリのインストール