What is a PostgreSQL connection string?

A PostgreSQL connection string is a formatted piece of text that bundles all the information needed to connect to a database — hostname, port, credentials, database name, and SSL settings — into a single value. Applications, ORMs, and command-line tools use connection strings to establish database sessions without requiring each parameter to be configured separately. There are two common formats: the URI format (postgresql://user:password@host:port/dbname) and the libpq key=value format (host=localhost port=5432 dbname=mydb). Both formats are supported across virtually all PostgreSQL client libraries.

Tool description

This tool generates valid PostgreSQL connection strings from individual parameters. Fill in the host, port, credentials, database name, and SSL mode, and it instantly produces three ready-to-use outputs: a connection URL, a psql command, and a libpq key=value string.

Examples

Input:

Field Value
Host db.example.com
Port 5432
Username alice
Password s3cr3t
Database production
SSL Mode require

Connection URL:

postgresql://alice:s3cr3t@db.example.com/production?sslmode=require

psql command:

psql "postgresql://alice:s3cr3t@db.example.com/production?sslmode=require"

libpq key=value string:

host=db.example.com port=5432 dbname=production user=alice password=s3cr3t sslmode=require

Features

  • Three output formats: Generates a connection URL, psql shell command, and libpq key=value string simultaneously
  • SSL mode selector: Supports all six PostgreSQL SSL modes — disable, allow, prefer, require, verify-ca, and verify-full
  • Smart defaults: Omits default values (port 5432, sslmode=prefer) to keep output clean and minimal
  • URL encoding: Automatically percent-encodes usernames, passwords, and database names containing special characters
  • Port validation: Validates that the port is a number between 1 and 65535

Use cases

  • Application configuration: Generate a DATABASE_URL environment variable for frameworks like Django, Rails, or any app using a connection string
  • Quick CLI access: Produce a ready-to-run psql command to connect to a remote database without memorizing URI syntax
  • Connection debugging: Build a libpq string to test connections with low-level drivers or tools that don't accept URI format

SSL modes explained

Mode Description
disable No SSL. Connection is unencrypted.
allow Uses SSL if the server requires it; otherwise connects without SSL.
prefer Tries SSL first; falls back to unencrypted (default).
require Requires SSL but does not verify the server certificate.
verify-ca Requires SSL and verifies that the server certificate is signed by a trusted CA.
verify-full Requires SSL, verifies the CA, and also checks that the hostname matches the certificate.