LoginSignup
0
0

More than 5 years have passed since last update.

PostgreSQL9.x 外部ホストからの接続設定

Last updated at Posted at 2018-08-01

PostgreSQLは、デフォルトでは自ホスト内の接続しか許可されていません。
JDBC等で他のホストからアクセスする際の接続設定をまとめます。実行環境は次の通りです。

・CentOS 7.5
・PostgreSQL 9.2.23

postgresq.confファイルの修正

デフォルトで、localhostからの接続しかListenしていない為、下記を設定

# vi /var/lib/pgsql/data/postgresql.conf
listen_addresses = '*'   (#を外し、'localhost' から'*'に変更)
port = 5432        (#を外す)

※listen_addressesにアドレス範囲は指定出来ず、pg_hba.confファイルで指定する

Firewallの設定

# firewall-cmd --add-port=5432/tcp --zone=public --permanent
# systemctl restart firewalld

pg_hba.confファイルの修正

・pg_hba.conf:対象DBへの該当DBユーザの接続元と認証方式を指定

接続を許可するクライアントのアドレスと認証方式を追記する
例)クライアントは10.44.59.0/24でmd5(暗号化パスワード)認証

# vi /var/lib/pgsql/data/pg_hba.conf
host    all     all      10.44.59.0/24  md5

サービス再起動

# systemctl restart postgresql
0
0
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
0