CentOS7にPostgreSQLインストール&初期設定&DB作成&認証方式設定
© The PostgreSQL Global Development Group
環境
- OS : CentOS 7.3
- PostgreSQL 9.2.8
PostgreSQL(9.2.8)インストール
yum install postgresql-server
- パッケージ
- 完了
インストール確認(バージョン確認)
psql --version
初期設定
初期セットアップコマンド実行
postgresql-setup initdb
起動時の有効化 & 起動
systemctl enable postgresql systemctl start postgresql
管理者パスワードを変更
su - postgres psql -c "alter user postgres with password '*******'"
DB作成
DB[webhippodb] 作成
psql -c "create database webhippodb WITH template template0 encoding 'utf8' lc_collate 'ja_JP.UTF-8' lc_ctype 'ja_JP.UTF-8'";
ユーザ(ロール)[webhippo] 作成
psql -c "CREATE ROLE webhippo WITH LOGIN PASSWORD 'webhippo'";
所有者を webhippo に変更
psql -c "ALTER DATABASE webhippodb OWNER TO webhippo";
認証方式設定
/var/lib/pgsql/data/pg_hba.conf
- パスワード認証方式(md5) に変更
#local all all peer ← 変更前 local all all md5
- PostgreSQL再起動
systemctl restart postgresql
ログイン
psql -U webhippo webhippodb -W