Environment:
- CentOS based 7.4
- PostgreSQL 9.6
$ cat /etc/redhat-release
CentOS Linux release 7.4.1708 (Core)
# pgdg96リポジトリを追加する
$ sudo yum install -y https://yum.postgresql.org/9.6/redhat/rhel-7-x86_64/pgdg-redhat96-9.6-3.noarch.rpm
# PostgreSQLサーバーをインストールする
$ sudo yum install -y postgresql96-server postgresql96-contrib
# version check
$ psql --version
psql (PostgreSQL) 9.6.8
Initializae database
sudo /usr/pgsql-9.6/bin/postgresql96-setup initdb
Start postgresql
sudo systemctl start postgresql-9.6.service
Configure postgresql to auto-start in OS loading
sudo systemctl enable postgresql-9.6.service
Create user
$ psql -l
psql: FATAL: role "azureuser" does not exist ###ログインユーザーがazureuser�だから
# DBの初期化時に postgres というユーザーが作成されるので、パスワードを設定してログインし、先ほどまでログインしていたユーザーと同名のロールを作成します。
# `postgres` ユーザーにパスワードを設定する
$ sudo passwd postgres # ”postgres�”に設定
# `postgres` ユーザーでログインする
$ su - postgres
# `postgres` へ接続する
$ psql
psql (9.6.3)
"help" でヘルプを表示します.
# ロールを作成する
# postgres=# create role {ユーザー名} login createdb password '{パスワード}';
postgres=# create role azureuser login createdb password 'P@ssw0rd';
ロールを作成したら、作成したユーザーでDBを操作できるようになったか確認
$ psql -U azureuser --password postgres
ticketmonsterという名前のデータベースを作成する
psql> create database ticketmonster
psql> \q
Rmoete access Configuration - postgresql.conf
sudo vi /var/lib/pgsql/9.6/data/postgresql.conf
# Open postgresql.conf file and replace line
# listen_addresses = 'localhost'
# with
# listen_addresses = '*'
listen_addresses = '*'
Rmoete access Configuration - pg_hpa.conf
sudo vi /var/lib/pgsql/9.6/data/pg_hba.conf
host all all 0.0.0.0/0 md5
host all all ::/0 md5
Restart postgreSQL server! Then you can check if you are able to access from remote
psql -h <dbhost> -U azureuser --password ticketmonster
Access via psql command
psql -h <dbhost> -U azureuser --password ticketmonster
Stop & Start postgresQL
sudo systemctl stop postgresql-9.6.service
sudo systemctl start postgresql-9.6.service
Configuration
sudo vi /var/lib/pgsql/9.6/data/postgresql.conf