#####***** [01] PostgreSQL専用ユーザを作成 *****#####
## Postgres
## postgresは専用ユーザで動作させるので、ユーザを作成します。
groupadd postgres
useradd -g postgres postgres
su - postgres
## ~~/.bash_profileの既存のPATH記述行下に以下の行を追記~
mv ~/.bash_profile ~/.bash_profile_org
cat ~/.bash_profile_org | sed –e ‘s/PATH=$PATH:$HOME\/bin/PATH=$PATH:$HOME\/bin\nPATH=$PATH:\/usr\/local\/pgsql\/bin/’> ~/.bash_profile
chmod 644 ~/.bash_profile
chmod 000 ~/.bash_profile_org
exit
#####***** [02] PostgreSQLのインストール *****#####
## readlineのライブラリを要求されるのでインストールしておきます。
yum -y install readline-devel
## ソースファイルを取得します。
## ソースファイルを展開します。
## コンパイル・インストール作業は postgresユーザ権限で行います。
## その為、先にインストール先ディレクトリを作成しておきます。
## シンボリックリンクを作成します。
## コンパイル、インストールの作業は postgresユーザで行います。
mkdir -p /usr/local/src/postgres
cd /usr/local/src/postgres
wget ftp://ftp.sra.co.jp/pub/cmd/postgres/8.4.3/postgresql-8.4.3.tar.gz
cd /usr/local/src/postgres
tar zxf postgresql-8.4.3.tar.gz
mv postgresql-8.4.3 postgresql-8.4.3-1
chown -R postgres.postgres postgresql-8.4.3-1
mkdir /usr/local/pgsql-8.4.3-1
chown postgres.postgres /usr/local/pgsql-8.4.3-1
ln -fs /usr/local/pgsql-8.4.3-1 /usr/local/pgsql
## postgresユーザになります。
su - postgres
cd /usr/local/src/postgres/postgresql-8.4.3-1
./configure --prefix=/usr/local/pgsql-8.4.3-1 \
--enable-multibite=EUC_JP \
--with-perl \
--enable-syslog
gmake check
gmake install
exit
#####***** [03] PostgreSQLインストール後の設定 *****#####
## exitデータベース格納先のディレクトリを作成して、初期化します。
## データベース初期化は postgresユーザで行います。
## このinitdbは、文字コードがEUC-JPのデータベースを作成するためのコマンドです。
## UTF-8のデータベースを作成したい場合は、オプションを変えてください。
mkdir -p /db/pgsql-8.4.3-1
chown postgres.postgres /db/pgsql-8.4.3-1
su - postgres -c "/usr/local/pgsql/bin/initdb -D /db/pgsql-8.4.3-1 --encoding=EUC_JP --no-locale"
## postmaster を起動します。これも postgresユーザ権限で行います。
su - postgres -c "/usr/local/pgsql/bin/pg_ctl -D /db/pgsql-8.4.3-1 -l logfile start"
## 再起動時に自動起動するように /etc/rc.local に記述します。
printf \
‘##############
# postgres #
##############
su - postgres -c "/usr/local/pgsql/bin/pg_ctl -D /db/pgsql-8.4.3-1 -l logfile start"
\n’>> /etc/rc.local