PostgreSQL の初期設定
2010-04-22-1: [PostgreSQL][CentOS]
1. CentOS 付属の PostgreSQL は、8.1.11 のため 8.4.x をインストールする
下記サイトより、pgdg-centos-8.4-x.noarch をダウンロードし、yum による管理を行う。
- pgdg-centos - PostgreSQL 9.0.X PGDG RPMs for CentOS - Yum Repository Configuration
http://yum.pgsqlrpms.org/reporpms/repoview/pgdg-centos.html
$ sudo rpm -ivh pgdg-centos-8.4-x.noarch.rpm
$ sudo yum check-update
$ sudo yum install postgresql-server
次に、/etc/rc.d/init.d/postgresql の initdb のオプションを追加する。
-E UTF8 --no-locale
--- /etc/rc.d/init.d/postgresql 2010-03-17 15:09:56.000000000 +0900
+++ /etc/rc.d/init.d/postgresql 2010-04-22 11:06:43.000000000 +0900
@@ -243,7 +243,7 @@
fi
# Initialize the database
- $SU -l postgres -c "$PGENGINE/initdb --pgdata='$PGDATA' --auth='ident'" >> "$PGLOG" 2>&1 < /dev/null
+ $SU -l postgres -c "$PGENGINE/initdb -E UTF8 --no-locale --pgdata='$PGDATA' --auth='ident'" >> "$PGLOG" 2>&1 < /dev/null
# Create directory for postmaster log
mkdir "$PGDATA/pg_log"
2. DB の初期化、PostgreSQL の起動を行う
$ sudo service postgresql initdb
$ sudo chkconfig postgresql on
$ sudo service postgresql start
3. ユーザの追加
username というユーザを追加する場合
$ sudo -u postgres createuser -P username
Enter password for new role: <パスワード>
Enter it again: <パスワード>
Shall the new role be a superuser? (y/n) n
Shall the new role be allowed to create databases? (y/n) n
Shall the new role be allowed to create more new roles? (y/n) n
4. DB の作成
dbname という DB を、username オーナーで作る場合。
$ sudo -u postgres createdb -E UTF-8 -O username dbname
5. 他のサーバからの接続を許可する
$ sudo vi /var/lib/pgsql/data/postgresql.conf
他のサーバ全てからの接続を許可する場合
listen_addresses = '*'
いくつかのサーバを指定する場合(「,」でつなぐ)
listen_addresses = 'localhost,192.0.2.1'
$ sudo vi /var/lib/pgsql/data/pg_hba.conf
下記を追加し、パスワード認証で接続を許可する。
host all all 192.0.2.1/32 md5
