How to allow external connections to PostgreSQL

Jun 4, 2020 | - views

0. Allow CONNECT

Grant privilege CONNECT

# GRANT CONNECT ON DATABASE dbname TO username;

And add privilege on the schema (in this example public):

# GRANT USAGE ON SCHEMA public TO username;

1. Edit your postgresql.conf

You can find this file in /etc/postgresql/12/main/postgresql.conf (for postgres version 12). After that edit listen_addresses

listen_addresses = 'localhost'
listen_addresses = '*'

2. Edit your pg_hba.conf

You can find this file in /etc/postgresql/12/main/pg_hba.conf (for postgres version 12). After that add this lines:

host    all             all              0.0.0.0/0                       md5
host    all             all              ::/0                            md5

3. Restart your server

If you are started postgres as a cluster:

pg_ctlcluster 12 main restart

Related articles: