postgresqlリモートログインとローカルログインを設定する方法

postgresqlリモートログインとローカルログインを設定する方法

別のコンピュータから私のpostgresqlデータベースに接続するには、postgresql.con次のようにfファイルを設定する必要があります。

#------------------------------------------------------------------------------
# CONNECTIONS AND AUTHENTICATION
#------------------------------------------------------------------------------

# - Connection Settings -

listen_addresses = '10.14.4.4'                # what IP address(es) to listen on;
                                        # comma-separated list of addresses;
                                        # defaults to 'localhost'; use '*' for all
                                        # (change requires restart)
port = 5432                             # (change requires restart)

私は127.0.0.1を試してみましたが、成功しませんでした。 「localhost」も同様です。これを行うことができる唯一の方法は、サーバーの物理IPアドレスを使用することです。私の "hosts"ファイルにlocalhostが定義されていることを確認しました。

とにかく、次のようにして他のサーバーから接続できるようになりました。

psql -U test test -h 10.14.4.4

しかし、今はログインできないようです。地元の次の構文を使用します。

psql -U test test -h 127.0.0.1

ローカルでログインする唯一の方法は次のとおりです。

psql -U test test

"*"を使用するようにpostgresql.confファイルを変更してみました。これによりリモートでログインできましたが、ローカルではまだ127.0.0.1または「localhost」を使用して接続できません。

リモートログインとローカルログインの両方が機能するようにどのように設定しますか?

ベストアンサー1

pg_hba.confファイルを編集する必要がありました:

# TYPE  DATABASE        USER            ADDRESS                 METHOD

# "local" is for Unix domain socket connections only
local   all             all                                     trust
# IPv4 local connections:
host    all             all             127.0.0.1/32            md5
# IPv6 local connections:
host    all             all             ::1/128                 trust
# Allow replication connections from localhost, by a user with the
# replication privilege.
#local   replication     postgres                                trust
#host    replication     postgres        127.0.0.1/32            trust
#host    replication     postgres        ::1/128                 trust
host    all             all             10.14.4.0/24             md5
host    replication     postgres        10.14.0.0/16              trust

メソッドを「trust」から「md5」に変更し、問題が解決しました。

おすすめ記事