What's the difference between “local” and “localhost” connection types in pg_hba.conf?

后端 未结 2 1977
不知归路
不知归路 2020-12-19 19:28

This is the relevant part of my pg_hba.conf:

# TYPE  DATABASE        USER            ADDRESS                 METHOD

# \"local\" is for Unix dom         


        
相关标签:
2条回答
  • 2020-12-19 19:46

    ident authentication means that your OS user matches DB user. It is support only for TCP/IP connections as relevant entry in docs states. If used with Unix socket, Peer authentication method will be used instead.

    Also, note, that default user is not postgres, but the one you're currently logged in with.

    0 讨论(0)
  • 2020-12-19 19:48

    local is a connection type used in pg_hba.conf, while localhost is the network address for local loopback and translates to the IPv4 address 127.0.0.1, or IPv6 ::1.
    I quote the manual about pg_hba.conf:

    local

    This record matches connection attempts using Unix-domain sockets. Without a record of this type, Unix-domain socket connections are disallowed.

    host

    This record matches connection attempts made using TCP/IP. host records match either SSL or non-SSL connection attempts.

    Note: Remote TCP/IP connections will not be possible unless the server is started with an appropriate value for the listen_addresses configuration parameter, since the default behavior is to listen for TCP/IP connections only on the local loopback address localhost.

    For the GUC* listen_addresses in postgresql.conf, localhost also serves as setting:
    * GUC: Grand Unified Configuration

    The default value is localhost, which allows only local TCP/IP "loopback" connections to be made.

    Bold emphasis mine.

    0 讨论(0)
提交回复
热议问题