PostgreSQL Connection String

Once the installation is done, we need a way to connect the database to perform various operations and execute SQL statements. Once we are able to identify the various parameters involved in the credentials for connecting, we can construct something called Connection String.

Several libraries parse a user specified string to get the connection parameter. There are two formats which are widely used.

  • plain keyword/value strings
  • Connection URIs.

Example of keyword value:

host=localhost port=5432 dbname=mydb connect_timeout=10

Example of connection string:

postgresql://username:[email protected]:port/dbname[?paramspec]

Let us try to create a connection URI to the database we had set up in the previous step:

postgresql://postgres:[email protected].docker.internal:5432/postgres

Here the following parameters are used:

  • POSTGRES_USER = postgres
  • POSTGRES_PASSWORD = postgrespassword
  • POSTGRES_HOST = host.docker.internal
  • POSTGRES_PORT = 5432
  • POSTGRES_DATABASE = postgres

In case you are using Linux, the host would be localhost and in case you are using Mac, the host would be host.docker.internal.

Connection String from Heroku Postgres

In case you installed Postgres via Heroku in the earlier step, you can click on View Database Credentials button on their app dashboard for the Postgres add-on.

View Database Credentials

We will make use of the Connection URI in the next step using psql.

Close

Get Started with GraphQL Now

Hasura Cloud gives you a fully managed, production ready GraphQL API as a service to help you build modern apps faster.
Ready to get started?
Start for free on Hasura Cloud or you could contact our sales team for a detailed walk-through on how Hasura may benefit your business.
Stay in the know
Sign up for full access to our community highlights, new features, and occasional baby animal gifs! Oh, and we have a strict no-spam rule. โœŒ๏ธ