0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

postgresqlを外部から接続する

Last updated at Posted at 2025-08-10

はじめに

Postgresqlを外部PCから接続する際、デフォルト設定だと接続できないため
設定を実施する必要があります、今回備忘録として設定手順を残します。
※Windows環境で接続設定を実施しています
※ファイヤーウォール設定(Postgresqlデフォルトポート5432解放など)は別途実施する必要があります

外部接続設定方法

リモート接続受付可能を設定

リモート接続を受け付けるには、postgresql.conf の listen_addresses が正しく設定されている必要があります。

PostgreSQLフォルダ配下にある「postgresql.conf」にリモート接続の受付設定を実施します

postgresql.conf
listen_addresses = '*'

特定のIPだけ許可するなら listen_addresses = '192.168.11.xx' のように指定できます。(xxは任意のIP)

接続可能とする対象を設定

PostgreSQLフォルダ配下にある「pg_hba.conf」ファイルに対し設定をします
host → TCP/IP 接続を許可
postgres(DB名)→ ここではデータベース名 postgres を指定
postgres(ユーザー名)→ 接続ユーザー
192.168.11.37/32 → 許可するクライアント IP(単一IPの場合は /32)
md5 → パスワード認証方式(PostgreSQL 15 以降は scram-sha-256 が推奨)
もし 192.168.11.x の全範囲を許可したい場合は /24 にします。

pg_hba.conf
host    postgres    postgres    192.168.11.0/24    md5

上記を実施後にPostgresqlサービスを再起動を実施します

[補足]PostgreSQLフォルダの設定ファイルの場所について

インストール先のフォルダ指定によりますが、下記のフォルダに配置されていることが多いです
C:\Program Files\PostgreSQL\XX\data ※「XX」はバージョン番号

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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?