PostgreSQL连接URL

JII*_*JII 189 postgresql database-connection

当主机是除localhost之外的其他计算机时,PostgreSQL连接URL是如何形成的?

我允许PostgreSQL接受来自外部的请求.

And*_*rey 329

如果对各自的语言使用Libpq绑定,则根据其文档 URI形成如下:

postgresql://[user[:password]@][netloc][:port][/dbname][?param1=value1&...]
Run Code Online (Sandbox Code Playgroud)

以下是同一文档中的示例

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
Run Code Online (Sandbox Code Playgroud)

  • 这为我工作了postgres:// user:secret @ localhost:5432/mydatabasename (17认同)
  • 要添加到 @Edenshaw 关于特殊字符的注释,密码需要进行 url 编码,我只是偶然发现了这个问题,密码包含“@”字符(用 %40 替换它解决了它) (3认同)
  • `postgresql://localhost/mydb?user=other&password=secret` 成功了 (2认同)

Hem*_*ari 42

以下对我有用

const conString = "postgres://YourUserName:YourPassword@YourHost:5432/YourDatabase";
Run Code Online (Sandbox Code Playgroud)

  • @RyuS。`URI 方案指示符可以是 postgresql:// 或 postgres://` 从这里:https://www.postgresql.org/docs/current/libpq-connect.html#LIBPQ-CONNSTRING (7认同)
  • 'postgres://' 和 'postgresql://' 可以互换吗? (2认同)

nos*_*nos 15

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

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

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

如果你正在使用别的东西,你必须告诉我们.

  • 谢谢。ADO.NET 格式也是您需要传递给 Entity Framework Core 的 `UseNpgsql()` 的格式。我有点困惑是否应该是那个或 postgres:// URL(我也将其视为“postgresql://”) (2认同)

gil*_*niy 8

DATABASE_URL=postgres://{user}:{password}@{hostname}:{port}/{database-name}
Run Code Online (Sandbox Code Playgroud)


DIN*_*LIT 7

  • 数据库url的一般格式
DATABASE_URL=postgresql://username:password@host:port/dtabase_name
Run Code Online (Sandbox Code Playgroud)
  • 如果您将 postgresql sql 与 asyncpg 一起使用,则数据库 url 将是
DATABASE_URL=postgresql+asyncpg://username:password@host:port/dtabase_name
Run Code Online (Sandbox Code Playgroud)
  • 请记住永远不要推送您的数据库密码,因此您应该使用您的DATABASE_URL文件.env
  • port如果您使用默认值,则该选项是可选的
  • 像这样,您可以连接本地和远程数据库,想象一下,一旦您想要检查远程部署版本中发生的问题

  • localhost DATABASE_URL 的 ex 是

DATABASE_URL=postgresql+asyncpg://postgres:dina@localhost/mysens
Run Code Online (Sandbox Code Playgroud)
  • 如果您在 Heroku 上部署了数据库并且想要将其与本地应用程序连接,请转至 Heroku Postgres 安装的附加组件,转至设置,然后单击数据库凭据中的查看凭据,然后使用 连接uri到您的数据库
DATABASE_URL=postgresql+asyncpg://sqnalxxxxxxxxx:160xxxx2bdd2942b26c93c392xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx@ec2-35-173-91-114.compute-1.amazonaws.com:5432/del6o4cjoqfsov
Run Code Online (Sandbox Code Playgroud)

在此输入图像描述


小智 6

postgres 语法的连接 URL:

"Server=host ipaddress;Port=5432;Database=dbname;User Id=userid;Password=password;
Run Code Online (Sandbox Code Playgroud)

例子:

"Server=192.168.1.163;Port=5432;Database=postgres;User Id=postgres;Password=root;
Run Code Online (Sandbox Code Playgroud)


Mac*_*ski 5

还可以通过编程方式从工作的数据库连接器中检索连接字符串。

例如,我有时从 SQLAlchemy 中提取连接字符串engine,如下所示:

> db_engine.url
postgres://{user}:{password}@{host}:{port}/{db_name}?sslmode=require
Run Code Online (Sandbox Code Playgroud)