LoginSignup
0
1

More than 3 years have passed since last update.

Centos8にPostgreSQL12をインストール

Last updated at Posted at 2020-10-15

はじめに

Mysqlしか触ったことなかったので、検証用にPostgresqlを公式サイトのインストール方法でインストールした。
今回はローカルからpostgresユーザーで認証なしの接続を想定する。

環境

  • CentOS8
  • Postgresql12

インストール

dnf install -y https://download.postgresql.org/pub/repos/yum/reporpms/EL-8-x86_64/pgdg-redhat-repo-latest.noarch.rpm
dnf -qy module disable postgresql
dnf install -y postgresql12-server
/usr/pgsql-12/bin/postgresql-12-setup initdb
systemctl enable postgresql-12
systemctl start postgresql-12

以下の公式サイトでインストールしたいものを選択してインストールする。
https://www.postgresql.org/download/linux/redhat/

設定変更

事前準備

ユーザー変更

インストール後、postgresユーザーが追加されているため、ユーザーを変更する。
基本的にpostgresユーザーで操作を行う。

su - postgres

ディレクトリ遷移

設定ファイルあるディレクトリに移動する。

cd /var/lib/pgsql/12/data

PATHの追加

pg_ctlを相対PATHで使えるようにする。
.bash_profileに追記しても良い。

export PATH=$PATH:/usr/pgsql-12/bin/

postgresql.conf

基本的な設定をするファイル。適宜設定を変更する。
今回は検証なのでデフォルトのまま。

pg_hba.conf

接続するネットワークを設定するファイル。
identからtrustに変更することで、ローカルホストに認証なしで接続できるようにする。
postgresql.confがデフォルトだとipv6で繋ぎに行く場合もあるので、ipv6も変更する。

  • 変更前
  • # IPv4 local connections:
    host    all             all             127.0.0.1/32            ident
    # IPv6 local connections:
    host    all             all             ::1/128                 ident
    
  • 変更後

  • # IPv4 local connections:
    host    all             all             127.0.0.1/32            trust
    # IPv6 local connections:
    host    all             all             ::1/128                 trust
    

設定の反映

以下のコマンドで設定を反映する。

pg_ctl reload

確認

ログイン確認

以下のコマンドでログインできることを確認する。

psql -h localhost

パスワード変更(任意)

接続後、postgresユーザーのパスワードを変更する。

alter role postgres with password 'パスワード';

まとめ

公式サイトにのっとてインストールしてみた。
ipv6の設定変更を忘れたり、postgresユーザーの初期パスワードがわからなかったり、意外と引っかかった。
そして、postgresユーザーの初期パスワードは今でもわかっていない。

参考文献

0
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
1