当主机不是本地主机时,PostgreSQL连接字符串(URL postgres://…)是什么格式?
这里是JDBC的文档,一般的URL是" JDBC:postgresql://host:port/database"
这里的第3章记录了ADO。NET连接字符串, 一般连接字符串是Server=host;Port=5432;User Id=username;Password=secret;
PHP文档我们这里,一般的连接字符串是 Host =hostname port=5432 dbname=databasename user=username password=secret
如果你用了别的药,你得告诉我们。
如果对各自的语言使用Libpq绑定,根据其文档,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的连接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;
下面的方法对我很有效
const conString = "postgres://YourUserName:YourPassword@YourHostname:5432/YourDatabaseName";
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}
还可以通过编程方式从工作的DB连接器检索连接字符串。
例如,我有时从SQLAlchemy的引擎中提取连接字符串,如下所示:
> db_engine.url
postgres://{user}:{password}@{host}:{port}/{db_name}?sslmode=require
有些人似乎误读了数据库名作为服务器名和主机作为postgresql服务器?主机上有一个postgresql服务器,该服务器上有一个数据库。还是我遗漏了什么?
postgresql: / / my_host及服务器= my_postgresql_server ?用户= my_user&port = my_port&password = my_password&database = my_database
例子:
My_host:可以是“localhost”(但这不在问题中)或主机的IP地址。
postgresql: / / my_host / &server = postgres ?用户= postgres&port 5432&password = postgres&database = test_db
为我工作在Python sqlalchemy和postgresql localhost运行。需要sqlalchemy、postgresql和psycopg2才能使其工作。
PS:这个问题是关于postgres的://…URL,但这在这里不起作用。相反,你需要postgresql,在Python中最后运行的是方言+驱动程序(参见数据库url) = postgresql+psycopg2,而不必像这样编写。
推荐文章
- 查询JSON类型内的数组元素
- 获得PostgreSQL数据库中当前连接数的正确查询
- 纬度和经度的数据类型是什么?
- 如何在PostgreSQL中临时禁用触发器?
- 输入文件似乎是一个文本格式转储。请使用psql
- 使用LIMIT/OFFSET运行查询,还可以获得总行数
- 当恢复sql时,psql无效命令\N
- 货币应该使用哪种数据类型?
- 如何添加列,如果不存在PostgreSQL?
- 如何在Postgres中获得两个字段的MIN() ?
- 截断Postgres数据库中的所有表
- 如何连接列在Postgres选择?
- 将varchar字段的类型更改为整数:"不能自动转换为整数类型"
- PostgreSQL可以索引数组列吗?
- 什么是数据库池?