Home > Software design >  Disable postgres from listening on IPv6
Disable postgres from listening on IPv6

Time:09-23

I created a postgres docker image on top of the official image to copy my own pg_hba.conf into it, because I need to disable listening on IPv6 :

FROM postgres:13
COPY pg_hba.conf /etc/

Afterwards I run the container using the following docker-compose.yaml:

postgres:
    image: custom-postgres
    command: postgres -c hba_file="/etc/pg_hba.conf"

But postgres still tries listening on the none existent IPv6 socket. What am I doing wrong? This is my 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
# Allow replication connections from localhost, by a user with the
# replication privilege.
local   replication     all                                     trust
host    replication     all             127.0.0.1/32            trust

But I get the feeling it is not beeing used as I can see that the default pg_hba.conf is still created in /var/lib/postgresql/data

CodePudding user response:

If you want to shape what interface(s) the Postgres server listens on you need to use the listen_addresses in postgresql.conf. To restrict to IPv4 then set to 0.0.0.0. See documentation link for more options. pg_hba.conf is used to control client access to a server. It does not control what interface the server listens on.

  • Related