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


当前回答

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;

其他回答

DATABASE_URL=postgres://{user}:{password}@{hostname}:{port}/{database-name}
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

下面的方法对我很有效

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

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;