在 postgresql.conf 中设置什么值以启用“localhost”和“127.0.0.1”以及 IP 地址?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/20080633/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-21 01:12:02  来源:igfitidea点击:

what value to set in postgresql.conf to enable use of "localhost" and "127.0.0.1" and ip address?

postgresql

提问by dot

In order to be able to connect to my postgresql database from another machine, I had to configure my postgresql.conf file like so:

为了能够从另一台机器连接到我的 postgresql 数据库,我必须像这样配置我的 postgresql.conf 文件:

#------------------------------------------------------------------------------
# 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)

I tried using 127.0.0.1 but that didn't work. Neither did "localhost". The only way I was able to do make this work is to use the actual IP address of the server. I checked to make sure in my "hosts" file, localhost was defined....

我尝试使用 127.0.0.1 但这没有用。“本地主机”也没有。我能够完成这项工作的唯一方法是使用服务器的实际 IP 地址。我检查以确保在我的“主机”文件中定义了 localhost....

In any case, I am now able to connect from a different server by doing the following:

无论如何,我现在可以通过执行以下操作从不同的服务器进行连接:

psql -U test test -h 10.14.4.4

But now I'm noticing that I cannot log on locallyusing the following syntax:

但现在我注意到我无法使用以下语法在本地登录:

psql -U test test -h 127.0.0.1

The only way to log in locally is

本地登录的唯一方法是

psql -U test test

I tried to change my postgresql.conf file to use "*"... and that let's me log in remotely, but locally, i still cannot use 127.0.0.1 or "localhost" to connect.

我试图将我的 postgresql.conf 文件更改为使用“*”...让我远程登录,但在本地,我仍然无法使用 127.0.0.1 或“localhost”进行连接。

How can I set this up so that both my remote log ins and my local log ins work?

我如何设置它以便我的远程登录和本地登录都可以工作?

Thanks.

谢谢。

EDIT 1

编辑 1

Here's what my pg_hba.conf file looks like:

这是我的 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            trust
# 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 trust
host    replication     postgres        10.14.0.0/16              trust

回答by dot

I had to edit the pg_hba.conf file to use MD5, not trust. This is what the final file looks like:

我必须编辑 pg_hba.conf 文件才能使用 MD5,而不是信任。这是最终文件的样子:

# 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

Now I can log on remotely specifying IP address, and log on locally using IP address too.

现在我可以远程指定IP地址登录,也可以使用IP地址在本地登录。

回答by Noam Rathaus

You need to modify the pg_hba.conf file, see: http://www.postgresql.org/docs/8.2/static/auth-pg-hba-conf.html

需要修改pg_hba.conf文件,见:http: //www.postgresql.org/docs/8.2/static/auth-pg-hba-conf.html