postgresql connection string

Generate PostgreSQL connection strings for apps, drivers, and psql

Fill the connection fields once and get PostgreSQL URI, JDBC, libpq, SQLAlchemy, and psql command formats instantly.

Useful when you need the same database credentials in multiple tools or frameworks.

Quick presets

Connection details

Output options

Generated formats

Copy the format that matches your stack.

PostgreSQL URI

Common format for app config and DATABASE_URL style variables.

postgresql://postgres:secret@127.0.0.1:5432/app_db?sslmode=prefer

JDBC

Used in Java and Spring environments.

jdbc:postgresql://127.0.0.1:5432/app_db?user=postgres&password=secret&sslmode=prefer

libpq keyword/value

Useful with PostgreSQL-native clients and environment-based tooling.

host=127.0.0.1 port=5432 dbname=app_db user=postgres password=secret sslmode=prefer

SQLAlchemy

Typical format for Python apps using SQLAlchemy and psycopg.

postgresql+psycopg://postgres:secret@127.0.0.1:5432/app_db?sslmode=prefer

psql CLI

Paste into Terminal to test access with psql.

psql "host=127.0.0.1 port=5432 dbname=app_db user=postgres sslmode=prefer"

Keep database access close to the rest of your remote workflow

After you generate the connection string, DartShell can help you keep SSH, file transfer, and database access in one Mac workspace.

What this PostgreSQL connection string generator helps with

Reuse the same credentials across tools

Generate the exact format required by your app, driver, or command-line workflow without hand-converting the same values.

Work with managed PostgreSQL services

Set SSL mode and schema-friendly parameters for hosted databases where secure connections are expected.

Test quickly with psql

Use the generated psql command before wiring the connection into your codebase.

Common examples

App config

postgresql://app_user:secret@db.example.com:5432/app_db?sslmode=require

JDBC

jdbc:postgresql://db.example.com:5432/app_db?user=app_user&password=secret&sslmode=require

psql

psql "host=db.example.com port=5432 dbname=app_db user=app_user sslmode=require"

SQLAlchemy

postgresql+psycopg://app_user:secret@db.example.com:5432/app_db?sslmode=require

libpq keyword/value

host=db.example.com port=5432 dbname=app_db user=app_user password=secret sslmode=require connect_timeout=10

Other names for the same connection

Documentation and config files rarely agree on one name. These three phrases all describe the same set of host, port, database, user, and SSL values — here is what each one looks like in practice.

psql connection string: the command-line form

psql accepts a conninfo string, a URI, or separate flags. Fill in the fields above and the generator gives you the first two; the flag form is handy for a one-off test from Terminal.

psql "host=db.internal.example.net port=5432 dbname=orders user=reporting sslmode=require"
psql postgresql://reporting:secret@db.internal.example.net:5432/orders?sslmode=require -c "select version();"
psql -h db.internal.example.net -p 5432 -U reporting -d orders -c "select 1;"

Passwords stay out of the command so they do not land in shell history; psql prompts for them instead.

Postgres DSN: the libpq keyword/value form

When someone says Postgres DSN they usually mean the libpq conninfo string. It is a space-separated list of key=value pairs, and it also works as the value of PGDATABASE-style environment variables.

host=db.internal.example.net port=5432 dbname=orders user=reporting password=secret sslmode=require connect_timeout=10

PGHOST=db.internal.example.net PGPORT=5432 PGDATABASE=orders PGUSER=reporting psql -c "select 1;"

Quote values that contain spaces, and percent-encode @ : / # in a URI form of the same DSN.

PostgreSQL DSN: what drivers expect in app config

Java, Python, and .NET drivers spell the full product name differently and wrap the same values in their own DSN syntax. These are the three formats most often pasted into a config file.

jdbc:postgresql://db.internal.example.net:5432/orders?user=reporting&password=secret&sslmode=require
postgresql+psycopg://reporting:secret@db.internal.example.net:5432/orders?sslmode=require
Host=db.internal.example.net;Port=5432;Database=orders;Username=reporting;Password=secret;SSL Mode=Require

The JDBC, SQLAlchemy, and URI outputs above produce the same three values from one form.

Common PostgreSQL connection errors

Most failures fall into four groups: the network path, the account, the database name, and SSL settings. Find the message you see in the first column.

Error messageWhat it meansWhat to change
psql: command not foundThe psql client is missing, or its bin directory is not on your PATH.Install only the client with brew install libpq and add $(brew --prefix libpq)/bin to PATH; Postgres.app ships its own bin directory.
could not connect to server: Connection refusedNothing is listening on that address and port, or a firewall and cloud security group are blocking it.Run nc -vz db.example.com 5432 from your Mac, then check listen_addresses, the port in postgresql.conf, and the cloud security group.
password authentication failed for user "app_user"The account or password is wrong, pg_hba.conf rejects this host, or a special character in the password broke the URI.Verify with psql -h db.example.com -U app_user -d app_db, then percent-encode @ : / # and other reserved characters in the URI.
FATAL: database "app_db" does not existThe database name is misspelled, or the connection string points at a default database instead.List databases with psql -l and correct the name after the final slash in the URI.
server does not support SSL, but SSL was requiredsslmode=require does not match the server's TLS configuration.Use sslmode=disable or prefer on a trusted local network; managed PostgreSQL services normally require require plus a valid certificate.
relation "orders" does not existThe table exists but is outside the current search_path.Add options=-csearch_path%3Dmyschema to the URI, or qualify the table as myschema.orders.

Related tools

MySQL connection string generator

Generate JDBC, CLI, and SQLAlchemy formats for MySQL from the same connection fields.

Redis connection string generator

Build redis:// and rediss:// URLs when the app also needs a cache or queue.

SSH port forwarding generator

Reach a database that only listens on a private network through an SSH tunnel.