Connection Strings

There are various ways to connect to your database, depending on the configuration of your Postgres instance and the tool which you are connecting with.

postgres://postgres:postgres@localhost:5432/postgres
# or
postgresql://postgres:postgres@localhost:5432/postgres

Notes

  • Official Documentation.
  • Avoid using special characters usernames and passwords. If you use special characters in a connection URL, you'll need to URL encode any special characters.

Examples

Basic connection string

If you're using a default setup, your postgres connection string will likely be in the format:

postgres://{user}:{password}@{host}:{port}/{database_name}

postgres://postgres:postgres@localhost:5432/postgres
# or
postgresql://postgres:postgres@localhost:5432/postgres

JDBC

See full documentation.

jdbc:postgresql://{host}:{port}/{database_name}

ADO.NET

See full documentation.

Server=host;Port=5432;User Id=username;Password=secret;Database=database_name;

PHP

See full documentation.

host=hostname port=5432 dbname=databasename user=username password=secret