What is the format for the PostgreSQL connection string / URL?

PostgresqlDatabase Connection

Postgresql Problem Overview


What is the format for the PostgreSQL connection string (URL postgres://...) when the host is not the localhost?

Postgresql Solutions


Solution 1 - Postgresql

If you use Libpq binding for respective language, according to its documentation URI is formed as follows:

postgresql://[user[:password]@][netloc][:port][/dbname][?param1=value1&...]

Here are examples from same document

postgresql://
postgresql://localhost
postgresql://localhost:5432
postgresql://localhost/mydb
postgresql://user@localhost
postgresql://user:secret@localhost
postgresql://other@localhost/otherdb?connect_timeout=10&application_name=myapp
postgresql://localhost/mydb?user=other&password=secret

Solution 2 - Postgresql

The following worked for me

const conString = "postgres://YourUserName:YourPassword@YourHostname:5432/YourDatabaseName";

Solution 3 - Postgresql

DATABASE_URL=postgres://{user}:{password}@{hostname}:{port}/{database-name}

Solution 4 - Postgresql

Here is the documentation for JDBC, the general URL is "jdbc:postgresql://host:port/database"

Chapter 3 here documents the ADO.NET connection string, the general connection string is Server=host;Port=5432;User Id=username;Password=secret;Database=databasename;

PHP documentation us here, the general connection string is host=hostname port=5432 dbname=databasename user=username password=secret

If you're using something else, you'll have to tell us.

Solution 5 - Postgresql

the connection url for postgres syntax:

"Server=host ipaddress;Port=5432;Database=dbname;User Id=userid;Password=password;

example:

"Server=192.168.1.163;Port=5432;Database=postgres;User Id=postgres;Password=root;

Solution 6 - Postgresql

server.address=10.20.20.10
server.port=8080
database.user=username
database.password=password
spring.datasource.url=jdbc:postgresql://${server.address}/${server.port}?user=${database.user}&password=${database.password}

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionJIIView Question on Stackoverflow
Solution 1 - PostgresqlAndreyView Answer on Stackoverflow
Solution 2 - PostgresqlHemadri DasariView Answer on Stackoverflow
Solution 3 - PostgresqlgildniyView Answer on Stackoverflow
Solution 4 - PostgresqlnosView Answer on Stackoverflow
Solution 5 - PostgresqlVinoth ShankarView Answer on Stackoverflow
Solution 6 - PostgresqlAlanView Answer on Stackoverflow