ChatGPT解决这个技术问题 Extra ChatGPT

PostgreSQL 连接字符串/URL 的格式是什么?

当主机不是本地主机时,PostgreSQL 连接字符串(URL postgres://...)的格式是什么?

此链接提供有关连接字符串、驱动程序类和驱动程序库的信息。 docs.oracle.com/cd/E19509-01/820-3497/agqka/index.html 要下载最近的 jar 文件,请使用此链接:jdbc.postgresql.org/download.html
例如postgres://postgres:123456@127.0.0.1:5432/dummy
关于 pgAdmin 的相关问题:stackoverflow.com/questions/61479570/…

M
Mike 'Pomax' Kamermans

如果你对各自的语言使用 Libpq 绑定,根据它的 documentation URI 形成如下:

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

以下是来自同一文档的示例

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

这对我有用 postgres://user:secret@localhost:5432/mydatabasename
postgresql://localhost/mydb?user=other&password=secret 成功了
如果您仍然有问题,请检查密码中的特殊字符,暂时将其更改为仅数字并测试 URL(只是为了验证您的连接是否按预期工作)
我的问题是简单地从 DataGrip 中复制“jdbc:postgres:// ...”字符串。不幸的是,错误消息没有帮助。谢谢!
要添加到@Edenshaw 关于特殊字符的注释,密码需要进行 url 编码,我只是偶然发现了这个问题,密码包含“@”字符(将其替换为 %40 即可解决)
H
Hemadri Dasari

以下对我有用

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

如何在 ruby 中使用这个连接字符串?
'postgres://' 和 'postgresql://' 可以互换吗?
@RyuS。 The URI scheme designator can be either postgresql:// or postgres:// 从这里:postgresql.org/docs/current/libpq-connect.html#LIBPQ-CONNSTRING
如果您的主机名是 url,您可以使用 ping hostname 获取 IP 地址。
a
adiga
DATABASE_URL=postgres://{user}:{password}@{hostname}:{port}/{database-name}

n
nos

Here 是 JDBC 的文档,一般 URL 是“jdbc:postgresql://host:port/database”

第 3 章 here 记录了 ADO.NET 连接字符串,一般的连接字符串是 Server=host;Port=5432;User Id=username;Password=secret;Database=databasename;

我们的 PHP 文档 here,一般连接字符串是 host=hostname port=5432 dbname=databasename user=username password=secret

如果您使用其他东西,您必须告诉我们。


谢谢。对于 Entity Framework Core,您还需要将 ADO.NET 格式传递给 UseNpgsql()。我有点困惑是应该是那个还是 postgres:// URL(我也将其视为“postgresql://”)
libpq(官方 postgresql 客户端库)理解 URL 形式和名称=值对形式。如果您最终不是通过 libpq 进行连接,请查阅您的框架的文档。
V
Vinoth Shankar

postgres 语法的连接 url:

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

例子:

"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}

定义连接 URI 的方法无效