简体   繁体   中英

postgres not using postgres.conf file?

I have a postgres setup on my ubuntu 18.04 server. I have changed the listen_addresses property to '*' but it doesn't seem like the postgres server is following this.

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?

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?

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

There are two changes you need to make to enable PostgreSQL to accept remote connections:

  • First is exactly what you've done, modify listen_addresses in /etc/postgresql/<VERSION>/main/postgresql.conf to listen on all interfaces:

     listen_addresses = '*'
  • Second, you need to modify /etc/postgresql/<VERSION>/main/pg_hba.conf to allow remote connections. If you look at a default pg_hba.conf you will have a line that looks like this:

     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:

     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.

If you're still having issues connecting to the database remotely I'd check firewalls like iptables, etc.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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