PostgreSQL のインストール
Conoha に CentOS 7.1 サーバーを立てて PostgreSQL 9.4.5 をインストールしたので手順をメモしておきます。
基本的には以下のページの内容を参考にしています。
https://wiki.postgresql.org/wiki/YUM_Installation
yum リポジトリの設定
BASE リポジトリから PostgreSQL を引っ張ってこないように修正します。
vim /etc/yum.repos.d/CentOS-Base.repo
[base] セクションと [update] セクションに以下の記述をします。
exclude=postgresql*
PostgreSQL のインストール
yum localinstall http://yum.postgresql.org/9.4/redhat/rhel-7-x86_64/pgdg-centos94-9.4-2.noarch.rpm yum install postgresql94-server
データベースの初期化
今回はロケールなしで作成します。
デフォルトのままインストールすると日本語ロケールになりますが、この場合いくつか考慮すべき点が発生するので、ロケールなしにしています。
export PGSETUP_INITDB_OPTIONS="--encoding=UTF-8 --no-locale" /usr/pgsql-9.4/bin/postgresql94-setup initdb
「/usr/pgsql-9.4/bin/postgresql94-setup help
」でヘルプを参照すると、initdb コマンドの引数を渡すには環境変数「PGSETUP_INITDB_OPTIONS
」に値を設定するように書いてあるので、上記のようにして C ロケールを設定しています。
データベースの起動
systemctl enable postgresql-9.4.service systemctl start postgresql-9.4.service
ログインして確認
su - postgres psql \l
Collate と Ctype が C になっていればうまく initdb できています。
List of databases Name | Owner | Encoding | Collate | Ctype | Access privileges -----------+----------+----------+---------+-------+----------------------- postgres | postgres | UTF8 | C | C | template0 | postgres | UTF8 | C | C | =c/postgres + | | | | | postgres=CTc/postgres template1 | postgres | UTF8 | C | C | =c/postgres + | | | | | postgres=CTc/postgres (3 rows)