10月 23

PostgreSQL インストール

By ststyle Database, PostgreSQL コメントは受け付けていません。

postgreSQL インストール (postgreSQL8.3.4)

事前準備

readlineをインストール

# cd /usr/local/src
# wget ftp://ftp.gnu.org/gnu/readline/readline-5.1.tar.gz
# tar zxvf readline-5.1.tar.gz
# cd readline-5.1
# ./configure
# make
# make install

readline-develをインストール


yum install readline-devel

zlibをインストール


tar zxvf zlib-1.1.4.tar.gz
cd zlib-1.1.4
make
make install

zlib-develをインストール


yum install zlib-devel

postgreSQLユーザの準備&展開

$ su -
# useradd postgres
# mkdir /usr/local/pgsql
# chown postgres:postgres /usr/local/pgsql/

# cd /usr/local/src/

# mkdir postgresql-8.3.4/
# chown postgres:postgres postgresql-8.3.4

# su postgres
# tar zxvf postgresql-8.3.4.tar.gz
<h3>PostgreSQlのコンパイル&amp;インストール</h3>




cd postgresql-8.3.4

--8系--

./configure \
--prefix=/usr/local/pgsql \
--with-readline \
--with-zlib

$ make all
$ make install
PostgreSQL installation complete.

インストール後、環境変数の設定

usr/local下にpgsqlディレクトリが存在する事を確認する。

vi /home/postgres/.bashrcに太字部分 (PATH~5行)下記を追加する。
vi /home/XXXX/.bashrcに太字部分 (PATH~5行)下記を追加する。

postgresユーザーにスイッチ


su postgres

# .bashrc

# User specific aliases and functions

# Source global definitions
if [ -f /etc/bashrc ]; then
. /etc/bashrc
fi
export EMACS_IM="canna"

if [ "$LANG" = "ja" -o "$LANG" = "ja_JP.eucJP" ]; then
export JLESSCHARSET=japanese
fi

PATH="$PATH":/usr/local/pgsql/bin
PG=/usr/local/pgsql
export PGLIB=$PG/lib
export LD_LIBRARY_PATH=$PGLIB
export PGDATA=$PG/data

環境変数の反映


source ~/.bashrc

データベースの初期化


initdb --encoding=EUC_JP --no-locale

postgresの自動起動スクリプトの準備


su root
cp /usr/local/src/postgresql-8.3.4/contrib/start-scripts/linux /etc/rc.d/init.d/pgsql
chmod 700 /etc/rc.d/init.d/pgsql
cd /etc/rc.d/rc3.d
ln -sf ../init.d.pgsql S83pgsql

/etc/rc.d/init.d/pgsql start

chkconfig --add pgsql
ntsysvでチェック

DB実体場所の変更

( ここではvarをデータ領域としている為)
☆DB実体場所の変更 var/pgsql下に実体を持たせ
/usr/local/pgsql/data/へシンボリックリンクする


su
mkdir /var/pgsql
chown postgres:root /var/pgsql/
su postgres
pg_ctl stop
mv /usr/local/pgsql/data /var/pgsql/
ln -s /var/pgsql/data /usr/local/pgsql/data

cd /usr/local/pgsql/
ls -F にて@になればOK

アクセス権限


vi /usr/local/pgsql/data/pg_hba.conf

host all all XXX.XXX.XXX.0/24 trust

postgresql.confの基本設定


vi /var/pgsql/data/postgresql.conf

#IPアクセスの許可
#listen_addresses = 'localhost'         # what IP address(es) to listen on;
↓
#listen_addresses = '*'         # what IP address(es) to listen on;

#PORT番号
#port = 5432                            # (change requires restart)
↓
port = 5432                            # (change requires restart)

※PGPOOL入れる場合は5431にする(PGPOOLを5432とする)

(まぁ、PORT番号はその環境に合わせて..)
#バージョン差異?(7系からの移行時にこの設定でうまくいったっけ)
#escape_string_warning = on
↓
escape_string_warning = off

postgresql.logの作成及びローテーション


vi /var/pgsql/data/postgresql.conf

#------------------------------------------------------------------------------
# ERROR REPORTING AND LOGGING
#------------------------------------------------------------------------------

# - Where to Log -

#エラーをコンソールからlogにする

○#log_destination = 'stderr'             # Valid values are combinations of
○log_destination = 'syslog'              # Valid values are combinations of
# stderr, csvlog, syslog and eventlog,
# depending on platform.  csvlog
# requires logging_collector to be on.

# This is used when logging to stderr:
#logging_collector = off                # Enable capturing of stderr and csvlog
# into log files. Required to be on for
# csvlogs.
# (change requires restart)

# These are only used if logging_collector is on:
#log_directory = 'pg_log'               # directory where log files are written,
# can be absolute or relative to PGDATA
#log_filename = 'postgresql-%Y-%m-%d_%H%M%S.log'        # log file name pattern,
# can include strftime() escapes
#log_truncate_on_rotation = off         # If on, an existing log file of the
# same name as the new log file will be
# truncated rather than appended to.
# But such truncation only occurs on
# time-driven rotation, not on restarts
# or size-driven rotation.  Default is
# off, meaning append to existing files
# in all cases.
#log_rotation_age = 1d                  # Automatic rotation of logfiles will
# happen after that time.  0 to disable.
#log_rotation_size = 10MB               # Automatic rotation of logfiles will
# happen after that much log output.
# 0 to disable.

# These are relevant when logging to syslog:
○syslog_facility = 'LOCAL0'
○syslog_ident = 'postgres'

/etc/logrotate.d/syslogの編集

ログは、放っておくと膨大な量になります。
そこでログをローテーションして、古いログを消去します。

/etc/logrotate.d/syslogに追記をします。


su
vi /etc/logrotate.d/syslog

以下を追記

/var/log/postgres.log {
postrotate
/bin/kill -HUP `cat /var/run/syslogd.pid 2&gt; /dev/null` 2&gt; /dev/null || true
endscript
}

syslogの編集

vi /etc/syslog.conf

以下を追記

#postgres
local0.*                                                /var/log/postgres.log

syslogdとpgsqlの再起動


service syslog restart
service pgsql start
Tagged with:
preload preload preload