How to configure PostgreSQL to accept all incoming connections

Postgresql

Postgresql Problem Overview


I've got a PostgreSQL data base that I'd like to configure to accept all incoming connections regardless of the source IP address. How can this be configured in the pg_hba.conf file? I'm using postgreSQL version 8.4.

Postgresql Solutions


Solution 1 - Postgresql

Just use 0.0.0.0/0.

host    all             all             0.0.0.0/0            md5

Make sure the listen_addresses in postgresql.conf (or ALTER SYSTEM SET) allows incoming connections on all available IP interfaces.

listen_addresses = '*'

After the changes you have to reload the configuration. One way to do this is execute this SELECT as a superuser.

SELECT pg_reload_conf();

Note: to change listen_addresses, a reload is not enough, and you have to restart the server.

Solution 2 - Postgresql

0.0.0.0/0 for all IPv4 addresses

::0/0 for all IPv6 addresses

all to match any IP address

samehost to match any of the server's own IP addresses

samenet to match any address in any subnet that the server is directly connected to.

e.g.

host    all             all             0.0.0.0/0            md5

Solution 3 - Postgresql

Addition to above great answers, if you want some range of IPs to be authorized, you could edit /var/lib/pgsql/{VERSION}/data file and put something like

host all all 172.0.0.0/8 trust

It will accept incoming connections from any host of the above range. Source: http://www.linuxtopia.org/online_books/database_guides/Practical_PostgreSQL_database/c15679_002.htm

Solution 4 - Postgresql

Configuration all files with postgres 12 on centos:

step 1: search and edit file

> sudo vi /var/lib/pgsql/12/data/pg_hba.conf

press "i" and at line IPv4 change

host    all             all             0.0.0.0/0            md5

step 2: search and edit file postgresql.conf

> sudo vi /var/lib/pgsql/12/data/postgresql.conf

add last line: listen_addresses = '*' :wq! (save file)

  • step 3: restart

    systemctl restart postgresql-12.service

Solution 5 - Postgresql

Add this line to pg_hba.conf of postgres folder

host    all    all    all    trust

"trust" allows all users to connect without any password.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionFergalView Question on Stackoverflow
Solution 1 - PostgresqlFrank HeikensView Answer on Stackoverflow
Solution 2 - PostgresqlOwen PaulingView Answer on Stackoverflow
Solution 3 - Postgresqlvvs14View Answer on Stackoverflow
Solution 4 - PostgresqlgshoanganhView Answer on Stackoverflow
Solution 5 - PostgresqlGuestView Answer on Stackoverflow