kopug memo

名古屋で働くとあるWebエンジニアの覚書。

PostgreSQLの基本設定

[1] PGDATA の変更
PGDATAを変更する必要がなければデフォルトのままでもOK

# mkdir -p /var/data/pgsql/project_name
# chown -R postgres.postgres /var/data/pgsql
# chmod -R 700 /var/data/pgsql
# echo 'PGDATA=/var/data/pgsql/project_name' > /etc/sysconfig/pgsql/postgresql

[2] PostgreSQL自動起動設定

# chkconfig postgresql on
# chkconfig --list postgresql
postgresql 0:off 1:off 2:on 3:on 4:on 5:on 6:off

[3] PostgreSQLの起動

# service postgresql start

[4] 外部ネットワークからの接続設定 (SSH Port-Forward 使用予定)

vi $PGDATA/pg_hba.conf
local all all md5
host all all 127.0.0.1/32 md5
host all all xxx.xxx.xxx.xxx 255.255.255.255 md5
vi /var/data/pgsql/project_name/postgresql.conf
listen_addresses = 'localhost,xxx.xxx.xxx.xxx'

[5] postgresql パスワード変更

# su - postgres
$ psql template1
# alter user postgres with password 'postgres password';

[6] 一般ユーザの作成

$ createuser foo
Shall the new role be a superuser? (y/n) n
Shall the new role be allowed to create databases? (y/n) y
Shall the new role be allowed to create more new roles? (y/n) n

$ psql template1
# alter user foo with password 'foo password';

[7] PostgreSQL再起動

# service postgresql restart