[英]Postgres in docker-compose can't find/mount /etc/postgresql/postgres.conf
[英]postgres not using postgres.conf file?
我的 ubuntu 18.04 服务器上有一个 postgres 设置。 我已将listen_addresses
属性更改为'*'
但似乎 postgres 服务器并未遵循此操作。
当前文件的第一部分:
# - 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)
作为测试,我将port
设置更改为不同的端口并重新启动 postgres 服务器,并且 psql 无法连接到正在运行的服务器,因此psql
命令似乎遵循配置文件,但服务器本身不是?
我该如何调试这个问题?
我曾尝试使用psql -U postgres -c 'SHOW config_file'
但它只显示我编辑过的配置文件?
文件末尾是:
include_dir = 'conf.d' # include files ending in '.conf' from
# a directory, e.g., 'conf.d'
但是这个 conf.d 文件夹是空的
您需要进行两项更改才能使 PostgreSQL 接受远程连接:
首先就是您所做的,修改/etc/postgresql/<VERSION>/main/postgresql.conf
listen_addresses
以侦听所有接口:
listen_addresses = '*'
其次,您需要修改/etc/postgresql/<VERSION>/main/pg_hba.conf
以允许远程连接。 如果您查看默认的pg_hba.conf
您将看到如下所示的一行:
host all all 127.0.0.1/32 md5
127.0.0.1/32
阻止 PostgreSQL 接受远程连接,所以让我们改变它:
host all all 0.0.0.0/0 md5
进行这两项更改后重新启动 PostgreSQL 数据库,您应该能够从远程计算机连接到它。
如果您仍然无法远程连接到数据库,我会检查防火墙,如 iptables 等。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.