How to connect Postgres to DataGrip in PostgreSQL

Galaxy Glossary

How do I connect a PostgreSQL database to JetBrains DataGrip?

Create a new PostgreSQL data source in JetBrains DataGrip by entering host, port, database, user, and password, then test and save the connection.

Sign up for the latest in SQL knowledge from the Galaxy Team!
Welcome to the Galaxy, Guardian!
Oops! Something went wrong while submitting the form.

Description

Why use DataGrip to connect to PostgreSQL?

DataGrip offers code completion, schema navigation, and version control integration, making it a powerful PostgreSQL client for everyday development and analysis.

What prerequisites must be in place before connecting?

Install DataGrip, confirm PostgreSQL is running and reachable, and have credentials: host, port (default 5432), database, user, and password. Decide whether you need SSL or an SSH tunnel.

How do you add a new PostgreSQL data source in DataGrip?

Step-by-step connection procedure

1.Open DataGrip → Database tool-window → “+” → Data Source → PostgreSQL.
2. In the General tab, enter Host, Port, Database, User, and Password.
3. Click Download Drivers if prompted.

4. (Optional) In SSH/SSL, enable an SSH tunnel or SSL mode.
5. Press Test Connection. Green means success.
6. Click OK to save.

What connection parameters should you use?

Match these fields with your server settings:

Host: db.company.internal
Port: 5432
Database: ecommerce_prod
User: analytics_app
Password: ****

SSL and SSH options

Use require SSL mode for managed clouds like RDS.For on-prem servers behind firewalls, enable Use SSH tunnel and provide key or password.

How can you test and save the connection?

Click Test Connection; ensure Ping and Server version appear. If latency is high, switch the driver protocol to socket over JDBC.

Example: Connect to an ecommerce database

After saving, expand the new data source.Run this query in a console:

SELECT o.id,
c.name,
o.total_amount
FROM Orders o
JOIN Customers c ON c.id = o.customer_id
WHERE o.order_date = CURRENT_DATE;

Best practices for stable connections

Store passwords in DataGrip’s secure vault. Keep the JDBC driver updated. Use read-only roles for analysts. Limit fetch size to prevent memory spikes on large result sets.

Common mistakes and how to avoid them

Wrong port: Many managed services use 5432-5433; confirm in the dashboard.Forgetting SSL: RDS/Cloud SQL often mandates SSL; enable it in the SSL tab.

Troubleshooting FAQs

Timeouts: Increase Connection timeout to 30 s or open firewall ports. Driver mismatch: Redownload the PostgreSQL JDBC driver to match server version.

.

Why How to connect Postgres to DataGrip in PostgreSQL is important

How to connect Postgres to DataGrip in PostgreSQL Example Usage


-- Check high-value orders in the last 24 h
SELECT o.id,
       c.name         AS customer_name,
       p.name         AS product,
       oi.quantity,
       o.total_amount
FROM   Orders      o
JOIN   OrderItems  oi ON oi.order_id = o.id
JOIN   Products    p  ON p.id = oi.product_id
JOIN   Customers   c  ON c.id = o.customer_id
WHERE  o.order_date >= NOW() - INTERVAL '1 day'
  AND  o.total_amount > 500;

How to connect Postgres to DataGrip in PostgreSQL Syntax


DataGrip Connection Fields:

Host      – Server address (e.g., db.company.internal)
Port      – 5432 (default) or custom
Database  – Target database (e.g., ecommerce_prod)
User      – Login role (e.g., analytics_app)
Password  – Role password

Equivalent psql syntax for reference:
psql "host=db.company.internal port=5432 dbname=ecommerce_prod user=analytics_app password=secret sslmode=require"

JDBC URL auto-generated by DataGrip:
jdbc:postgresql://db.company.internal:5432/ecommerce_prod?sslmode=require

For SSH tunneling (DataGrip UI):
SSH Host        – bastion.company.internal
SSH Port        – 22
SSH User        – ubuntu
Authentication  – Key pair or password

Common Mistakes

Frequently Asked Questions (FAQs)

Do I need to install a PostgreSQL driver manually?

No. DataGrip prompts to download the correct JDBC driver automatically. Click “Download” when asked.

Can I save multiple connections with different roles?

Yes. Create separate data sources, each with its own user credentials, or use clones inside DataGrip for quick switching.

How do I share a DataGrip connection?

Right-click the data source → “Copy Settings” to clipboard or save it to a .idea project. Do not share passwords; teammates will be prompted for them.

Want to learn about other SQL terms?

Trusted by top engineers on high-velocity teams
Aryeo Logo
Assort Health
Curri
Rubie
BauHealth Logo
Truvideo Logo
Welcome to the Galaxy, Guardian!
Oops! Something went wrong while submitting the form.