简体   繁体   English

postgres 不使用 postgres.conf 文件?

[英]postgres not using postgres.conf file?

I have a postgres setup on my ubuntu 18.04 server.我的 ubuntu 18.04 服务器上有一个 postgres 设置。 I have changed the listen_addresses property to '*' but it doesn't seem like the postgres server is following this.我已将listen_addresses属性更改为'*'但似乎 postgres 服务器并未遵循此操作。

currently the first part of the file:当前文件的第一部分:

# - Connection Settings -

listen_addresses = '*'      # 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)
max_connections = 100           # (change requires restart)
#superuser_reserved_connections = 3 # (change requires restart)
unix_socket_directories = '/var/run/postgresql' # comma-separated list of directories
                # (change requires restart)
#unix_socket_group = ''         # (change requires restart)
#unix_socket_permissions = 0777     # begin with 0 to use octal notation
                # (change requires restart)
#bonjour = off              # advertise server via Bonjour
                # (change requires restart)
#bonjour_name = ''          # defaults to the computer name
                # (change requires restart)

As a test, I changed the port setting to a different port and restarted the postgres server and psql stopped being able to connect to the running server so it seems like the psql command is following the config file but the server itself isnt?作为测试,我将port设置更改为不同的端口并重新启动 postgres 服务器,并且 psql 无法连接到正在运行的服务器,因此psql命令似乎遵循配置文件,但服务器本身不是?

How can I debug this issue?我该如何调试这个问题?

I have tried to use psql -U postgres -c 'SHOW config_file' but it just shows the config file that I have edited?我曾尝试使用psql -U postgres -c 'SHOW config_file'但它只显示我编辑过的配置文件?

at the end of the file is:文件末尾是:

include_dir = 'conf.d'          # include files ending in '.conf' from
                # a directory, e.g., 'conf.d'

but this conf.d folder is empty但是这个 conf.d 文件夹是空的

There are two changes you need to make to enable PostgreSQL to accept remote connections:您需要进行两项更改才能使 PostgreSQL 接受远程连接:

  • First is exactly what you've done, modify listen_addresses in /etc/postgresql/<VERSION>/main/postgresql.conf to listen on all interfaces:首先就是您所做的,修改/etc/postgresql/<VERSION>/main/postgresql.conf listen_addresses以侦听所有接口:

     listen_addresses = '*'
  • Second, you need to modify /etc/postgresql/<VERSION>/main/pg_hba.conf to allow remote connections.其次,您需要修改/etc/postgresql/<VERSION>/main/pg_hba.conf以允许远程连接。 If you look at a default pg_hba.conf you will have a line that looks like this:如果您查看默认的pg_hba.conf您将看到如下所示的一行:

     host all all 127.0.0.1/32 md5

    That 127.0.0.1/32 is keeping PostgreSQL from accepting remote connections, so let's change it: 127.0.0.1/32阻止 PostgreSQL 接受远程连接,所以让我们改变它:

     host all all 0.0.0.0/0 md5

Restart the PostgreSQL database after making these two changes and you should be able to connect to it from a remote computer.进行这两项更改后重新启动 PostgreSQL 数据库,您应该能够从远程计算机连接到它。

If you're still having issues connecting to the database remotely I'd check firewalls like iptables, etc.如果您仍然无法远程连接到数据库,我会检查防火墙,如 iptables 等。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM