ChatGPT解决这个技术问题 Extra ChatGPT

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

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

This link provides information about connection string, driver class, and driver library. docs.oracle.com/cd/E19509-01/820-3497/agqka/index.html Also to download the recent jar files, use this link: jdbc.postgresql.org/download.html
e.g postgres://postgres:123456@127.0.0.1:5432/dummy
Related question about pgAdmin: stackoverflow.com/questions/61479570/…

M
Mike 'Pomax' Kamermans

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

This workded for me postgres://user:secret@localhost:5432/mydatabasename
postgresql://localhost/mydb?user=other&password=secret did the trick
If you still have problems, check the special characters in your password, change it temporarily for only numbers and test the URL (just to validate that your connection is working as expected)
My issue was to simply copying the "jdbc:postgres:// ..." string out of DataGrip. Unfortunately the error message did not help. Thank you!
To add to @Edenshaw's note on special characters, the password needs to be url encoded, I just stumbled upon this problem with a password containing the '@' character (replacing it with %40 solved it)
H
Hemadri Dasari

The following worked for me

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

How to use this connection string in ruby?
is 'postgres://' and 'postgresql://' interchangeable ?
@RyuS. The URI scheme designator can be either postgresql:// or postgres:// From here: postgresql.org/docs/current/libpq-connect.html#LIBPQ-CONNSTRING
In case your hostname is a url, you can use ping hostname to get IP address.
a
adiga
DATABASE_URL=postgres://{user}:{password}@{hostname}:{port}/{database-name}

n
nos

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.


Thanks. The ADO.NET format is also what you need to pass to UseNpgsql() for Entity Framework Core. I was a little confused whether it should be that or the postgres:// URL (which I've also seen as "postgresql://")
libpq (offical postgresql client lib) understands both URL form and name=value pairs form. if you connection is not ultimately through libpq then consult the documentation for your framework.
V
Vinoth Shankar

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;

A
Alan
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}

Not valid way to define connection URI