PostgreSQL インストール †メモ †
yum でインストールする †インストールする †試してないけど、これかな。 $ sudo yum install postgresql-devel ソースからインストールする †1) postgres ユーザが存在するか確認する †$ sudo cut -d: -f1 /etc/passwd ユーザが存在した場合、postgres ユーザのグループの確認 †$ id postgres ユーザが存在しなかった場合、作成する †$ sudo groupadd postgres $ sudo useradd -g postgres postgres 2) フォルダ作成 †$ sudo mkdir /usr/local/pgsql $ sudo chown postgres:postgres /usr/local/pgsql/ 3) インストールに必要なモジュールをインストールする †試してないけど、ここらへんかな。 $ sudo yum install readline-devel $ sudo yum install zlib-devel $ sudo yum install openssl 4) インストール †$ cd /usr/local/src $ wget ftp://ftp.sra.co.jp/pub/cmd/postgres/8.3.7/postgresql-8.3.7.tar.gz $ tar zvxf postgresql-8.3.7.tar.gz $ sudo chown -R postgres:postgres postgresql-8.3.7 $ su - postgres [postgres@hoge]$ cd /usr/local/src/postgresql-8.3.7 [postgres@hoge]$ ./configure --prefix=/usr/local/pgsql [postgres@hoge]$ make [postgres@hoge]$ make install 設定 †共有ライブラリに追加 †ファイルの修正 †pgsql.conf を新たに作成し「/usr/local/pgsql/lib」を記述する。 $ sudo vim /etc/ld.so.conf.d/pgsql.conf /usr/local/pgsql/lib ldconfig 更新 †$ sudo ldconfig 確認 †$ ldconfig -p | grep 'pgsql' 環境変数の設定(パスを通す) †ファイルを修正する †環境にあわせて適当に設定してください。 $ su - postgres [postgres@hoge]$ vim .bash_profile
設定を反映させる †[postgres@hoge]$ source .bash_profile PostgreSQL 設定 †1) データベースファイルを置く場所を作成 †/usr/local/pgsql/data にデータベースファイルを置く場合は、以下のようにフォルダを作成する。 [postgres@hoge]$ cd /usr/local/pgsql/ [postgres@hoge]$ mkdir data 今回は、/home/postgres/data に置くので、以下のようにフォルダを作成する。 [postgres@hoge]$ cd /home/postgres/ [postgres@hoge]$ mkdir data 2) データベースの初期化 †新しいPostgreSQL データベースクラスタ(またはデータベースシステム)を作成する。 [postgres@hoge]$ initdb --encoding=UTF8 --no-locale -D /home/postgres/data パスが通ってない場合 [postgres@hoge]$ /usr/local/pgsql/bin/initdb --encoding=UTF8 --no-locale -D /home/postgres/data 3) 設定ファイル(postgresql.conf)修正 †postmaster はデフォルトでは UNIX ドメインソケット接続しか受け付けない。 [postgres@hoge]$ vim /home/postgres/data/postgresql.conf listen_addresses = '*' port = 5432 4) 設定ファイル(pg_hba.conf)の修正 †デフォルトでは自ホストからの接続のみ許可になっているので、 PostgreSQL へのクライアントの接続許可の設定を行う。 [postgres@hoge]$ vim /home/postgres/data/pg_hba.conf 変更前 # IPv4 local connections: host all all 127.0.0.1/32 trust ↓ 変更後 # IPv4 local connections: host all all 127.0.0.1/32 trust host all all 192.168.0.0/24 trust ログの設定 †syslog に出力するようにする。 設定ファイル(postgresql.conf)の修正 †[postgres@hoge]$ vim /home/postgres/data/postgresql.conf 変更前 #log_destination = 'stderr' ↓ 変更後 log_destination = 'syslog' 変更前 #syslog_facility = 'LOCAL0' #syslog_ident = 'postgres' ↓ 変更後 syslog_facility = 'LOCAL0' syslog_ident = 'postgres' 変更前 #log_statement = 'none' ↓ 変更後 log_statement = 'all' 設定ファイル(syslog.conf)の修正 †以下の行を追記する。 $ sudo /etc/syslog.conf local0.* /var/log/postgresql.log /var/log/message に postgres のログを出力しないように、以下も修正する。 $ sudo /etc/syslog.conf 変更前 .info;mail.none;authpriv.none;cron.none /var/log/messages ↓ 変更後 .info;mail.none;authpriv.none;cron.none;local0.none /var/log/messages 再起動 †syslog 再起動 †$ sudo /etc/rc.d/init.d/syslog restart PostgreSQL 再起動 †PostgreSQL が起動している場合は、PostgreSQL も再起動する。 [postgres@hoge]$ pg_ctl restart もしくわ $ sudo /etc/rc.d/init.d/postgresql restart パスワード設定 †postgres ユーザのパスワード設定 †$ sudo passwd postgres 自動起動 †PostgreSQL 起動のためファイルコピー †$ sudo cp /usr/local/src/postgresql-8.3.7/contrib/start-scripts/linux /etc/init.d/postgresql $ sudo chmod 755 /etc/init.d/postgresql データベースファイルを置く場所を、/home/postgres/data にしたので、PGDATA を修正する。 $ sudo vim /etc/init.d/postgresql 変更前 PGDATA="/usr/local/pgsql/data" ↓ 変更後 PGDATA="/home/postgres/data" PostgreSQL 自動起動設定に postgresql を追加 †$ sudo chkconfig --add postgresql PostgreSQL 自動起動設定 †$ sudo chkconfig postgresql on PostgreSQL 自動起動設定の確認 †ランレベル 2, 3, 4, 5 になっていればよい。 $ chkconfig --list postgresql PostgreSQL 起動 †自動起動スクリプトを使って起動する †私はこっちで起動する。 起動 †$ sudo /etc/rc.d/init.d/postgresql start 起動確認 †$ su - postgres [postgres@hoge]$ psql -l 停止 †$ sudo /etc/rc.d/init.d/postgresql stop pg_ctl で起動する †起動 †[postgres@hoge]$ pg_ctl start 環境変数$PGDATA が設定されていない場合は、こっち↓。 [postgres@hoge]$ pg_ctl start -D /home/postgres/data 起動確認 †[postgres@hoge]$ psql -l 停止 †[postgres@hoge]$ pg_ctl stop 環境変数$PGDATA が設定されていない場合は、こっち↓。 [postgres@hoge]$ pg_ctl stop -D /home/postgres/data Comment †
Counter: 9773,
today: 3,
yesterday: 0
|