PostgreSQLのインストール
この記事は、PostgreSQL 8.4.3 を用いています。
PostgreSQLの最新版を取得
# wget ftp://ftp2.jp.postgresql.org/pub/postgresql/source/v8.4.3/postgresql-8.4.3.tar.gz ~省略~ 11:38:28 (15.41 MB/s) - `postgresql-8.4.3.tar.gz' を保存しました [16853436]
TARボールを展開
# tar -zxvf postgresql-8.4.3.tar.gz
~省略~
グループとユーザーの作成
# groupadd postgres # useradd -g postgres -d /home/postgres -m postgres # passwd postgres New UNIX password: Retype new UNIX password: passwd: all authentication tokens updated successfully.
コンパイルの準備
ここでは、各国語のサポートを有効にします。また、SSLでの接続も有効にします。
# cd postgresql-8.4.3 # ./configure --enable-nls=ja --with-openssl ~省略~
コンパイルを実行
# make ~省略~ make[1]: Leaving directory `/usr/local/src/postgresql-8.4.3/config' All of PostgreSQL successfully made. Ready to install.
インストール
インストール先は、/usr/local/pgsql になります。
# make install
~省略~
所有者の変更
# chown -R postgres.postgres /usr/local/pgsql
環境変数の登録
# su - postgres $ vi ~/.bash_profile ~省略~ export PGSQL_HOME=/usr/local/pgsql PATH=$PATH:$PGSQL_HOME/bin ~省略~ $ source ~/.bash_profile $ echo %PGSQL_HOME /usr/local/pgsql
データーベースの初期を実施
$ initdb -D /home/postgres/data -E UTF8 --no-locale データベースシステム内のファイルの所有者は"postgres"ユーザでした。 このユーザがサーバプロセスを所有しなければなりません。 データベースクラスタはロケールCで初期化されます。 デフォルトのテキスト検索設定はenglishに設定されました。 ~省略~ 成功しました。以下を使用してデータベースサーバを起動することができます。 postgres -D /home/postgres/data または pg_ctl -D /home/postgres/data -l logfile start ネットワークから接続できるように設定 $ vi /home/postgres/data/postgresql.conf ~省略~ listen_addresses = 'localhost,192.168.0.100/180'
起動スクリプトの準備
# cp /usr/local/src/postgresql-8.4.3/contrib/start-scripts/linux /etc/rc.d/init.d/pgsql
サービスの登録
# chmod 755 /etc/rc.d/init.d/pgsql # chkconfig pgsql on # service pgsql start Starting PostgreSQL: ok データファイルをインストール先のディレクトリとは別のディレクトリに作成する場合は、PGDATAを編集します。 # vi /etc/rc.d/init.d/pgsql ~省略~ PGDATA="/home/postgres/data" ~省略~
パスワードの設定
$ psql postgres=# alter user postgres with password 'password'; postgres=# \q
ネットワークから接続できるように設定
# vi /home/postgres/data/pg_hba.conf # "local" is for Unix domain socket connections only #local all all trust local all postgres md5 # IPv4 local connections: #host all all 127.0.0.1/32 trust host all postgres 127.0.0.1/32 md5 # IPv6 local connections: #host all all ::1/128 trust host all postgres ::1/128 md5