支援的版本:目前 (17) / 16 / 15 / 14 / 13
開發版本:devel
不支援的版本:12 / 11 / 10 / 9.6 / 9.5 / 9.4 / 9.3 / 9.2 / 9.1 / 9.0 / 8.4 / 8.3 / 8.2

32.18. LDAP 查詢連線參數 #

如果 libpq 已編譯支援 LDAP (使用 configure--with-ldap 選項),則可以透過 LDAP 從中央伺服器檢索連線選項,例如 hostdbname。 這樣的好處是,如果資料庫的連線參數發生變更,則無需在所有用戶端機器上更新連線資訊。

LDAP 連線參數查詢使用連線服務檔案 pg_service.conf(請參閱第 32.17 節)。 以 ldap:// 開頭的 pg_service.conf 節中的一行將被識別為 LDAP URL,並執行 LDAP 查詢。 結果必須是 keyword = value 鍵值對的列表,這些鍵值對將用於設定連線選項。 URL 必須符合 RFC 1959,並且格式如下

ldap://[hostname[:port]]/search_base?attribute?search_scope?filter

其中 hostname 預設為 localhostport 預設為 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 中 stanza 的完整範例為

# 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=*)

提交更正

如果您在文件中發現任何不正確、與您使用特定功能的經驗不符或需要進一步澄清的地方,請使用此表單回報文件問題。