sudo passwd postgres

[vagrant@localhost ~]$ sudo find / -name pg_hba.conf
/var/lib/pgsql/9.6/data/pg_hba.conf
[vagrant@localhost ~]$ sudo cat /var/lib/pgsql/9.6/data/pg_hba.conf
local all all peer
# IPv4 local connections:
host all all 127.0.0.1/32 ident
# IPv6 local connections:
host all all ::1/128 ident
# Allow replication connections from localhost, by a user with the
# replication privilege.
#local replication postgres peer
#host replication postgres 127.0.0.1/32 ident
#host replication postgres ::1/128 ident

[vagrant@localhost ~]$ sudo passwd postgres
ユーザー postgres のパスワードを変更。
新しいパスワード:
よくないパスワード: 辞書の単語に基づいています
新しいパスワードを再入力してください:
passwd: 全ての認証トークンが正しく更新できました。
[vagrant@localhost ~]$ su – postgres
パスワード:
-bash-4.1$ psql
psql (9.6.15)
“help” でヘルプを表示します.

postgres=# \q
-bash-4.1$ exit
logout

来た!事前準備にどれだけ時間かかってるんじゃ、という感じ。

postgresをインストールする

sudo yum install https://download.postgresql.org/pub/repos/yum/9.6/redhat/rhel-6-x86_64/pgdg-centos96-9.6-3.noarch.rpm
sudo yum update
sudo yum install postgresql96 postgresql96-server postgresql96-libs
[vagrant@localhost ~]$ rpm -qa | grep postgres
postgresql96-server-9.6.15-1PGDG.rhel6.x86_64
postgresql96-9.6.15-1PGDG.rhel6.x86_64
postgresql96-libs-9.6.15-1PGDG.rhel6.x86_64

[vagrant@localhost ~]$ service postgresql-9.6 initdb
データベースを初期化中: mkdir: ディレクトリ `/var/lib/pgsql’ を作成できません: 許可がありません
[vagrant@localhost ~]$ sudo service postgresql-9.6 initdb
データベースを初期化中: [ OK ]

[vagrant@localhost ~]$ sudo service postgresql-9.6 start
postgresql-9.6 サービスを開始中: [ OK ]
[vagrant@localhost ~]$ service postgresql-9.6 status
postgresql-9.6 (pid 20665) を実行中…
[vagrant@localhost ~]$ chkconfig postgresql-9.6 –list
postgresql-9.6 0:off 1:off 2:off 3:off 4:off 5:off 6:off
[vagrant@localhost ~]$ chkconfig postgresql-9.6 on
この操作を実行するためには権限が十分ではありません。
[vagrant@localhost ~]$ sudo chkconfig postgresql-9.6 on
[vagrant@localhost ~]$ chkconfig postgresql-9.6 –list
postgresql-9.6 0:off 1:off 2:on 3:on 4:on 5:on 6:off

[vagrant@localhost ~]$ su – postgres
パスワード:
su: パスワードが違います
なにいいいいいいいいいいいい