如果 libpq 已使用 LDAP 支持(configure 的选项 )进行编译,则可以从中央服务器通过 LDAP 检索连接选项,如 --with-ldaphost 或 dbname。优点在于,如果数据库的连接参数发生更改,则不必在所有客户端计算机上更新连接信息。
LDAP 连接参数查找使用连接服务文件 pg_service.conf(请参阅 第 34.17 节)。以 ldap:// 开头的 pg_service.conf 节中的行将被识别为 LDAP URL,并且将执行 LDAP 查询。结果必须是 keyword = value 对的列表,该列表将用于设置连接选项。URL 必须符合 RFC 1959,并采用以下形式
ldap://[hostname[:port]]/search_base?attribute?search_scope?filter
其中 hostname 默认为 localhost,port 默认为 389。
在成功进行 LDAP 查找后,将终止对 pg_service.conf 的处理,但如果无法联系到 LDAP 服务器,则将继续处理。这是为了提供后备,其中包含指向不同 LDAP 服务器的进一步 LDAP URL 行、经典的 keyword = value 对或默认连接选项。如果您希望在这种情况下收到错误消息,请在 LDAP URL 后添加语法不正确的行。
可以使用 LDIF 文件创建的示例 LDAP 项
version:1 dn:cn=mydatabase,dc=mycompany,dc=com changetype:add objectclass:top objectclass:device cn:mydatabase description:host=dbserver.mycompany.com description:port=5439 description:dbname=mydb description:user=mydb_user description:sslmode=require
可以使用以下 LDAP URL 进行查询
ldap://ldap.mycompany.com/dc=mycompany,dc=com?description?one?(cn=mydatabase)
您还可以将常规服务文件项与 LDAP 查找混合使用。在 pg_service.conf 中的节中,一个完整的示例如下
# only host and port are stored in LDAP, specify dbname and user explicitly [customerdb] dbname=customer user=appuser ldap://ldap.acme.com/cn=dbserver,cn=hosts?pgconnectinfo?base?(objectclass=*)
如果您在文档中看到任何不正确、与您对特定功能的体验不符或需要进一步澄清的内容,请使用 此表单 报告文档问题。