Configure PostgreSQL on Ubuntu and Connect with DataGrip

Install PostgreSQL, create a database and user, open it up for remote GUI access, and connect from DataGrip (or any Postgres client) without the common auth errors.

By DevStudio Online Team · Published September 3, 2026

PostgreSQL's default install is locked down to local connections only — reasonable for security, but it means three specific things need to change before a GUI client like DataGrip can reach it from your own machine.

Install and create a database

sudo apt install postgresql postgresql-contrib
sudo -u postgres psql

Inside the psql prompt:

CREATE DATABASE mydatabase;
CREATE USER appuser WITH ENCRYPTED PASSWORD 'a-strong-password';
GRANT ALL PRIVILEGES ON DATABASE mydatabase TO appuser;

Allow remote connections (two config files, not one)

Unlike MySQL, PostgreSQL splits "who can connect" across two separate files, and missing either one produces a different error — worth knowing which is which.

1. Listen on more than just localhost — edit postgresql.conf (usually /etc/postgresql/16/main/postgresql.conf):

listen_addresses = '*'

2. Allow the specific client and auth method — edit pg_hba.conf in the same directory:

# TYPE  DATABASE   USER      ADDRESS          METHOD
host    mydatabase appuser   203.0.113.10/32  scram-sha-256

Scope the address to your actual IP (or subnet) rather than 0.0.0.0/0 — this file is PostgreSQL's real access-control list, and being specific here matters more than the firewall rule below.

Restart for both to take effect:

sudo systemctl restart postgresql

Open the firewall

sudo ufw allow from 203.0.113.10 to any port 5432

Connecting from DataGrip

  1. New Data Source → PostgreSQL
  2. Host: your server's IP, Port: 5432
  3. Database: mydatabase, User: appuser
  4. Test Connection — DataGrip will offer to download the Postgres JDBC driver on first use if it isn't already installed

Reading the two most common connection errors

  • "Connection refused" — the connection never reached PostgreSQL at all. Check listen_addresses and the firewall rule first; this is a networking problem, not an auth problem.
  • "no pg_hba.conf entry for host ..." — PostgreSQL received the connection but has no matching rule for your IP/database/user combination in pg_hba.conf. This is the config-file half, not the network half — re-check the exact IP and database name in that file line.

Knowing which of the two errors you're looking at tells you which of the two files to go back and fix, instead of guessing.

Related tool

PostgreSQL Connector — skip the desktop client entirely

More Server guides