一个 conninfo 字符串是向 libpq 及其一些基于 libpq 的应用程序(例如 psql)提供 PostgreSQL 连接参数的一种方法。它要么由“keyword=value”格式的参数组成,这些参数由空格分隔,例如 "host=localhost dbname=testdb",要么是一个 URI 风格的字符串(由 RFC 3986 定义),例如 "postgresql:///testdb"。
libpq 函数
libpq 提供了以下函数来处理 conninfo 字符串:
PQconninfoParse()
变更历史
- PostgreSQL 10
- 添加了
passfile连接参数(提交 ba005f19) - 添加了
target_session_attrs连接参数(提交 721f7bd3)
- 添加了
示例
使用 conninfo 字符串连接到 PostgreSQL
$ psql "host=localhost dbname=testdb" psql (13.1) Type "help" for help. postgres=#
请注意,该字符串也可以通过 -d/--dbname 选项提供,例如:
$ psql -d "host=localhost dbname=testdb" psql (13.1) Type "help" for help. postgres=#
参考资料
- PostgreSQL 文档: 有效的 conninfo 关键字
有用链接
- conninfo - 提供用于操作 conninfo 字符串的函数的扩展
